On Tue, Nov 04, 2014 at 09:14:15PM -0500, Mike Frysinger wrote:
> interesting idea.  there's a few issues with this code, but rather
> than get into that, why don't ew just rely on readelf and be done ?  i
> don't think we want to maintain two code paths here.

I was just trying to give the test the best chance of finding the
endianness (just-in-case there's a rare system that does not have
readelf installed).  I suppose it would be simpler, though, to start
with just the readelf test and then add the backup check later if there
are any bug reports about a missing readelf command.

If a missing readelf command becomes a problem, there are a number of
other ways to check:
  1. echo -n I | od -to2
  2. lscpu | grep "Byte Order"
  3. python -c "import sys;print sys.byteorder;"
  4. perl -MConfig -e 'print $Config{byteorder};'
  5. a small C helper program since we know at least the compiler
     is installed

The patch below uses just the readelf command, and it uses your
simplified code path, and it also updates the comments at the top of the
test (I forgot that in my earlier patches).

           ==================================================

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 <jbast...@redhat.com>
---
 testcases/commands/ade/file/file_test.sh | 44 +++++++++++++++++---------------
 1 file changed, 23 insertions(+), 21 deletions(-)

diff --git a/testcases/commands/ade/file/file_test.sh 
b/testcases/commands/ade/file/file_test.sh
index 101a8cca8bc9..59ec85e45b31 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,20 @@ export TST_COUNT=6
 $LTPBIN/tst_resm TINFO \
         "TEST #6: file command recognizes ELF executables"
 
+# check for CPU endianness
+READELF=$(which readelf 2>/dev/null)
+case $(${READELF} -h ${READELF}) 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>

Attachment: pgplg2WQtsqnO.pgp
Description: PGP signature

------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to