qemu-trivial
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] iotests: Fix nonportable use of od --endian


From: Eric Blake
Subject: [PATCH] iotests: Fix nonportable use of od --endian
Date: Wed, 19 Feb 2020 08:41:03 -0600

Tests 261 and 272 fail on RHEL 7 with coreutils 8.22, since od
--endian was not added until coreutils 8.23.  Fix this by manually
constructing the final value one byte at a time.

Fixes: fc8ba423
Reported-by: Andrey Shinkevich <address@hidden>
Signed-off-by: Eric Blake <address@hidden>
---
 tests/qemu-iotests/common.rc | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc
index 8a6366c09daf..b77ef3d22cd1 100644
--- a/tests/qemu-iotests/common.rc
+++ b/tests/qemu-iotests/common.rc
@@ -56,6 +56,12 @@ poke_file()
 # peek_file_le 'test.img' 512 2 => 65534
 peek_file_le()
 {
-    # Wrap in echo $() to strip spaces
-    echo $(od -j"$2" -N"$3" --endian=little -An -vtu"$3" "$1")
+    local val=0 shift=0 i
+
+    # coreutils' od --endian is not portable, so manually assemble bytes.
+    for i in $(od -j"$2" -N"$3" -An -v -tu1 "$1"); do
+        val=$(( val | (i << shift) ))
+        shift=$((shift + 8))
+    done
+    echo $val
 }

 # peek_file_be 'test.img' 512 2 => 65279
 peek_file_be()
 {
-    # Wrap in echo $() to strip spaces
-    echo $(od -j"$2" -N"$3" --endian=big -An -vtu"$3" "$1")
+    local val=0 i
+
+    # coreutils' od --endian is not portable, so manually assemble bytes.
+    for i in $(od -j"$2" -N"$3" -An -v -tu1 "$1"); do
+        val=$(( (val << 8) | i ))
+    done
+    echo $val
 }

-# peek_file_raw 'test.img' 512 2 => '\xff\xfe'
+# peek_file_raw 'test.img' 512 2 => '\xff\xfe'. Do not use if the raw data
+# is likely to contain \0 or trailing \n.
 peek_file_raw()
 {
     dd if="$1" bs=1 skip="$2" count="$3" status=none
-- 
2.24.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]