1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
From: Michael Tokarev <mjt@tls.msk.ru>
Date: Sun, 6 Oct 2024 14:06:00 +0300
Subject: [PATCH v2] fix od and hexdump tests on big-endian hosts
Forwarded: yes
Newly added in 1.37.0 tests (od -B, hexdump -e /2 %d) are
endian-dependent, and fails on big-endian machines due to
mismatched output.
Expect different output depending on the host architecture.
Extend od.tests a little to provide a helper function,
testing2endian, which expects another version of the
"expected result" argument - first being for little endian,
second for big endian. And use this function for the
failing `od -B` test, providing the big-endian expected
result.
Do the same for hexdump.
Note: od.tests is using host `od` tool to determine if the
endian is big or little, which might not be the right thing
to do considering possible cross-compilation. It is probably
a better idea to use busybox version of od in this case
(and a busybox version of hexdump in hexdump.tests).
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
v2: use testing2endian helper function;
fix a bug (missing ";")
testsuite/hexdump.tests | 24 +++++++++++++++++++++++-
testsuite/od.tests | 16 +++++++++++++++-
2 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/testsuite/hexdump.tests b/testsuite/hexdump.tests
index be0379cfc..dbe13a365 100755
--- a/testsuite/hexdump.tests
+++ b/testsuite/hexdump.tests
@@ -6,6 +6,21 @@
. ./testing.sh
# testing "description" "command" "result" "infile" "stdin"
+
+little_endian=false
+{ printf '\0\1' | od -s | grep -q 256; } && little_endian=true
+readonly little_endian
+
+# two versions of "expected result" arg:
+# first for little-, second for big-endian
+testing2endian() {
+ if $little_endian; then
+ testing "$1 (little-endian)" "$2" "$3" "$5" "$6"
+ else
+ testing "$1 (big-endian)" "$2" "$4" "$5" "$6"
+ fi
+}
+
testing 'hexdump -C with four NULs' \
'hexdump -C' \
"\
@@ -66,7 +81,7 @@ testing "hexdump -e /1 %d" \
"\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"\
"\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"\
-testing "hexdump -e /2 %d" \
+testing2endian "hexdump -e /2 %d" \
"hexdump -e '8/2 \" %6d\" \"\n\"'" \
"\
256 770 1284 1798 2312 2826 3340 3854
@@ -74,6 +89,13 @@ testing "hexdump -e /2 %d" \
29040 29554 30068 30582 31096 31610 32124 32638
-32384 -31870 -31356 -30842 -30328 -29814 -29300 -28786
-3600 -3086 -2572 -2058 -1544 -1030 -516 -2
+" \
+ "\
+ 1 515 1029 1543 2057 2571 3085 3599
+ 4113 4627 5141 5655 6169 6683 7197 7711
+ 28785 29299 29813 30327 30841 31355 31869 32383
+ -32639 -32125 -31611 -31097 -30583 -30069 -29555 -29041
+ -3855 -3341 -2827 -2313 -1799 -1285 -771 -257
" \
"" \
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"\
diff --git a/testsuite/od.tests b/testsuite/od.tests
index 4f245a7e8..c739a8506 100755
--- a/testsuite/od.tests
+++ b/testsuite/od.tests
@@ -12,6 +12,16 @@ little_endian=false
{ printf '\0\1' | od -s | grep -q 256; } && little_endian=true
readonly little_endian
+# two versions of "expected result" arg:
+# first for little-, second for big-endian
+testing2endian() {
+ if $little_endian; then
+ testing "$1 (little-endian)" "$2" "$3" "$5" "$6"
+ else
+ testing "$1 (big-endian)" "$2" "$4" "$5" "$6"
+ fi
+}
+
$little_endian || SKIP=1
testing "od (little-endian)" \
"od" \
@@ -61,11 +71,15 @@ testing "od -a (DESKTOP)" \
"\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"
SKIP=
-testing "od -B" \
+testing2endian "od -B" \
"od -B" \
"\
0000000 001001 005003 041101 177103
0000010
+" \
+"\
+0000000 000402 001412 040502 041776
+0000010
" \
"" "$input"
SKIP=
--
2.39.5
|