[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 07/19] iotests: Fix nonportable use of od --endian
From: |
Max Reitz |
Subject: |
[PULL 07/19] iotests: Fix nonportable use of od --endian |
Date: |
Wed, 11 Mar 2020 14:52:01 +0100 |
From: Eric Blake <address@hidden>
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>
Reviewed-by: Max Reitz <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Max Reitz <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 8a6366c09d..4c246c0450 100644
--- a/tests/qemu-iotests/common.rc
+++ b/tests/qemu-iotests/common.rc
@@ -56,18 +56,30 @@ 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 byte
+
+ # coreutils' od --endian is not portable, so manually assemble bytes.
+ for byte in $(od -j"$2" -N"$3" -An -v -tu1 "$1"); do
+ val=$(( val | (byte << shift) ))
+ shift=$((shift + 8))
+ done
+ printf %llu $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 byte
+
+ # coreutils' od --endian is not portable, so manually assemble bytes.
+ for byte in $(od -j"$2" -N"$3" -An -v -tu1 "$1"); do
+ val=$(( (val << 8) | byte ))
+ done
+ printf %llu $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
- [PULL 00/19] Block patches, Max Reitz, 2020/03/11
- [PULL 01/19] luks: extract qcrypto_block_calculate_payload_offset(), Max Reitz, 2020/03/11
- [PULL 02/19] luks: implement .bdrv_measure(), Max Reitz, 2020/03/11
- [PULL 05/19] block/curl: HTTP header fields allow whitespace around values, Max Reitz, 2020/03/11
- [PULL 04/19] iotests: add 288 luks qemu-img measure test, Max Reitz, 2020/03/11
- [PULL 06/19] block/curl: HTTP header field names are case insensitive, Max Reitz, 2020/03/11
- [PULL 09/19] qemu-img: free memory before re-assign, Max Reitz, 2020/03/11
- [PULL 08/19] block/qcow2: do free crypto_opts in qcow2_close(), Max Reitz, 2020/03/11
- [PULL 03/19] qemu-img: allow qemu-img measure --object without a filename, Max Reitz, 2020/03/11
- [PULL 10/19] block/qcow2-threads: fix qcow2_decompress, Max Reitz, 2020/03/11
- [PULL 07/19] iotests: Fix nonportable use of od --endian,
Max Reitz <=
- [PULL 11/19] job: refactor progress to separate object, Max Reitz, 2020/03/11
- [PULL 12/19] block/block-copy: fix progress calculation, Max Reitz, 2020/03/11
- [PULL 13/19] block/block-copy: specialcase first copy_range request, Max Reitz, 2020/03/11
- [PULL 14/19] block/block-copy: use block_status, Max Reitz, 2020/03/11
- [PULL 15/19] block/block-copy: factor out find_conflicting_inflight_req, Max Reitz, 2020/03/11
- [PULL 16/19] block/block-copy: refactor interfaces to use bytes instead of end, Max Reitz, 2020/03/11
- [PULL 17/19] block/block-copy: rename start to offset in interfaces, Max Reitz, 2020/03/11
- [PULL 18/19] block/block-copy: reduce intersecting request lock, Max Reitz, 2020/03/11
- [PULL 19/19] block/block-copy: hide structure definitions, Max Reitz, 2020/03/11
- Re: [PULL 00/19] Block patches, Peter Maydell, 2020/03/12