aboutsummaryrefslogtreecommitdiff
path: root/testcases/commands
diff options
context:
space:
mode:
authorJeffrey Bastian <jbastian@redhat.com>2014-11-05 12:37:06 -0600
committerCyril Hrubis <chrubis@suse.cz>2014-12-02 15:31:38 +0100
commit17585ccf010432d8e8f4e82a737918237a4a752e (patch)
tree59dee33c84cda28adf750282c5926b52558e866d /testcases/commands
parent0a45153c159d7182a681db67a04cb948748611e1 (diff)
file_test: fix testcase for ppc64le
The file_test.sh test assumes all PPC systems are big-endian (MSB), but this assumption is incorrect on the new ppc64le little-endian (LSB) systems and file06 and file10 report false failures: file06 0 TINFO : TEST #6: file command recognizes ELF executables file06 6 TFAIL : ltpapicmd.c:156: file: Failed to Recognize ELF binary executable. Reason: /tmp//cprog: ELF 64-bit LSB executable, version 1 (SYSV), dynamically linked (uses shared libs), ... ... file10 0 TINFO : TEST #10: file command recognizes vmlinu file file10 10 TFAIL : ltpapicmd.c:156: file: Failed to Recognize vmlinu correctly. Reason: /boot/vmlinuz: ELF 64-bit LSB shared object, version 1 (SYSV), statically linked, ... This patch adds more robust testing for the endianness of a CPU. Signed-off-by: Jeffrey Bastian <jbastian@redhat.com> Acked-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
Diffstat (limited to 'testcases/commands')
-rwxr-xr-xtestcases/commands/ade/file/file_test.sh43
1 files changed, 22 insertions, 21 deletions
diff --git a/testcases/commands/ade/file/file_test.sh b/testcases/commands/ade/file/file_test.sh
index 101a8cca8..f28b0ad67 100755
--- a/testcases/commands/ade/file/file_test.sh
+++ b/testcases/commands/ade/file/file_test.sh
@@ -75,20 +75,17 @@
# -------
# Similar test(as Test02) is performed with C program text
#
-# Test06: Test if file command can recognize ELF binay executables
+# Test06: Test if file command can recognize ELF binary executables
# -------
-# 1) Grep for 'm68k' or 'sparc' or 'mips' or 'mipseb' or 'sh.eb'
-# or 'powerpc' or 'ppc' or 's390' from the output of the command
-# 'uname -m'
-# 2) If the above step is successful, assign string 'MSB' to variable
-# TARGET_ARCH else assign string 'LSB'
-# 3) Write small C program to a known '.c' file
-# 4) Compile it using "cc"
+# 1) Use readelf to determine if the host is big- or little-endian
+# and assign TEST_ARCH the string "MSB" or "LSB" respectively
+# 2) Write small C program to a known '.c' file
+# 3) Compile it using "cc"
# Ex: cc xyz xyz.c
-# 5) Use file command to get the type of the object file
-# 6) Grep for the string "ELF .*-bit $TEST_ARCH executable, .*"
+# 4) Use file command to get the type of the object file
+# 5) Grep for the string "ELF .*-bit $TEST_ARCH executable, .*"
# in the output of the 'file' command
-# 7) If the above command is successful, declare test as PASS
+# 6) If the above command is successful, declare test as PASS
# else declare test as FAIL
#
# Test07: Test if file command can recognize tar files
@@ -332,16 +329,7 @@ fi
# TEST #6
-# Test if file command can recognize ELF binay executables
-
-# Check ppc architecture
- TEST_ARCH=LSB # Assume the architecture is Intel
-
- if uname -m |
- grep -qe '\(m68k\)\|\(sparc\)\|\(mips\b\)\|\(mipseb\)\|\(sh.eb\)' \
- -e '\(powerpc\)\|\(ppc\)\|\(s390\)\|\(parisc\)'; then
- TEST_ARCH=MSB
- fi
+# Test if file command can recognize ELF binary executables
export TCID=file06
export TST_COUNT=6
@@ -349,6 +337,19 @@ export TST_COUNT=6
$LTPBIN/tst_resm TINFO \
"TEST #6: file command recognizes ELF executables"
+# check for CPU endianness
+case $(readelf -h /bin/sh) in
+ *Data:*"big endian"*)
+ TEST_ARCH=MSB
+ ;;
+ *Data:*"little endian"*)
+ TEST_ARCH=LSB
+ ;;
+ *)
+ TEST_ARCH=NULL
+ $LTPBIN/tst_resm TFAIL "file: Could not determine CPU endianness"
+ ;;
+esac
cat > $LTPTMP/cprog.c <<EOF
#include <stdio.h>