From 396df7efdf26a60084d2dbc2082be5dbdd7370d0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Anders=20Bj=C3=B6rklund?= Date: Mon, 1 Feb 2016 22:48:05 +0100 Subject: [PATCH] Fix clang test suite when running on linux (elf) Need to use eu-elfcmp (from elfutils) instead of cmp, to compare objects. Also need to cater for color coding (not to /dev/null). And it seems like the pch test suite hadn't been kept up to date plus some minor annoyances (i.e. a warning) in the coverage test. --- .travis.yml | 6 +-- test.sh | 146 ++++++++++++++++++++++++++++++++++------------------ 2 files changed, 98 insertions(+), 54 deletions(-) diff --git a/.travis.yml b/.travis.yml index 339726292..ed62987e3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ addons: apt: packages: - zlib1g-dev + - elfutils os: - linux @@ -26,7 +27,4 @@ script: - ./autogen.sh - ./configure - make - - make quicktest - - if [ "$CC" = "gcc" ]; then - ./test.sh; - fi + - make test diff --git a/test.sh b/test.sh index c2ae3cc5b..fea8c022d 100755 --- a/test.sh +++ b/test.sh @@ -96,6 +96,17 @@ compare_file() { fi } +compare_object() { + if [ $HOST_OS_LINUX -eq 1 ] && [ $COMPILER_TYPE_CLANG -eq 1 ]; then + eu-elfcmp -q "$1" "$2" + else + cmp -s "$1" "$2" + fi + if [ $? -ne 0 ]; then + test_failed "Objects differ: $1 != $2" + fi +} + checkfile() { if [ ! -f $1 ]; then test_failed "$1 not found" @@ -163,14 +174,14 @@ base_tests() { checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 checkstat 'files in cache' 1 - compare_file reference_test1.o test1.o + compare_object reference_test1.o test1.o testname="BASIC2" $CCACHE_COMPILE -c test1.c checkstat 'cache hit (preprocessed)' 1 checkstat 'cache miss' 1 checkstat 'files in cache' 1 - compare_file reference_test1.o test1.o + compare_object reference_test1.o test1.o testname="debug" $CCACHE_COMPILE -c test1.c -g @@ -187,7 +198,7 @@ base_tests() { $CCACHE_COMPILE -c test1.c -o foo.o checkstat 'cache hit (preprocessed)' 3 checkstat 'cache miss' 2 - compare_file reference_test1.o foo.o + compare_object reference_test1.o foo.o testname="link" $CCACHE_COMPILE test1.c -o test 2> /dev/null @@ -255,12 +266,12 @@ base_tests() { checkstat 'cache hit (preprocessed)' 4 checkstat 'cache miss' 3 CCACHE_DISABLE=1 $COMPILER -c test1.c -o reference_test1.o -O -O - compare_file reference_test1.o test1.o + compare_object reference_test1.o test1.o CCACHE_CPP2=1 $CCACHE_COMPILE -c test1.c -O -O checkstat 'cache hit (preprocessed)' 5 checkstat 'cache miss' 3 - compare_file reference_test1.o test1.o + compare_object reference_test1.o test1.o testname="CCACHE_NOSTATS" CCACHE_NOSTATS=1 $CCACHE_COMPILE -c test1.c -O -O @@ -271,7 +282,7 @@ base_tests() { CCACHE_RECACHE=1 $CCACHE_COMPILE -c test1.c -O -O checkstat 'cache hit (preprocessed)' 5 checkstat 'cache miss' 4 - compare_file reference_test1.o test1.o + compare_object reference_test1.o test1.o # strictly speaking should be 4 - RECACHE causes a double counting! checkstat 'files in cache' 4 @@ -282,13 +293,13 @@ base_tests() { CCACHE_HASHDIR=1 $CCACHE_COMPILE -c test1.c -O -O checkstat 'cache hit (preprocessed)' 5 checkstat 'cache miss' 5 - compare_file reference_test1.o test1.o + compare_object reference_test1.o test1.o CCACHE_HASHDIR=1 $CCACHE_COMPILE -c test1.c -O -O checkstat 'cache hit (preprocessed)' 6 checkstat 'cache miss' 5 checkstat 'files in cache' 5 - compare_file reference_test1.o test1.o + compare_object reference_test1.o test1.o testname="comments" echo '/* a silly comment */' > test1-comment.c @@ -310,7 +321,7 @@ base_tests() { checkstat 'cache hit (preprocessed)' 7 checkstat 'cache miss' 7 CCACHE_DISABLE=1 $COMPILER -c test1.c -o reference_test1.o - compare_file reference_test1.o test1.o + compare_object reference_test1.o test1.o testname="cache-size" for f in *.c; do @@ -365,7 +376,7 @@ base_tests() { checkstat 'unsupported source language' 2 testname="-D not hashed" - $CCACHE_COMPILE -DNOT_AFFECTING=1 -c test1.c 2>/dev/null + $CCACHE_COMPILE -DNOT_AFFECTING=1 -c test1.c checkstat 'cache hit (preprocessed)' 14 checkstat 'cache miss' 39 @@ -531,6 +542,8 @@ EOF cat <<'EOF' >prefix-remove.sh #!/bin/sh "$@" +[ x$2 = x-fcolor-diagnostics ] && shift +[ x$2 = x-fdiagnostics-color ] && shift [ x$3 = x-o ] && rm $4 EOF chmod +x prefix-remove.sh @@ -544,6 +557,8 @@ EOF cat <<'EOF' >prefix-empty.sh #!/bin/sh "$@" +[ x$2 = x-fcolor-diagnostics ] && shift +[ x$2 = x-fdiagnostics-color ] && shift [ x$3 = x-o ] && cp /dev/null $4 EOF chmod +x prefix-empty.sh @@ -586,9 +601,14 @@ EOF if [ $HOST_OS_APPLE -eq 1 ] && [ $COMPILER_USES_LLVM -eq 1 ]; then darwin_llvm=1 fi + # ditto clang on linux + linux_clang=0 + if [ $HOST_OS_LINUX -eq 1 ] && [ $COMPILER_TYPE_CLANG -eq 1 ]; then + linux_clang=1 + fi $COMPILER -c -fprofile-generate test1.c 2>/dev/null - if [ $? -eq 0 ] && [ $darwin_llvm -eq 0 ]; then + if [ $? -eq 0 ] && [ $darwin_llvm -eq 0 ] && [ $linux_clang -eq 0 ]; then testname="profile-generate" $CCACHE -Cz > /dev/null $CCACHE_COMPILE -c -fprofile-generate test1.c @@ -766,7 +786,7 @@ int test3; EOF cat <code.c /* code.c */ -int test() {} +int test() { return 0; } EOF backdate test1.h test2.h test3.h @@ -893,7 +913,7 @@ EOF checkstat 'cache miss' 1 checkfile other.d "$expected_d_content" CCACHE_DISABLE=1 $COMPILER -c -Wp,-MD,other.d test.c -o reference_test.o - compare_file reference_test.o test.o + compare_object reference_test.o test.o rm -f other.d @@ -902,7 +922,7 @@ EOF checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 checkfile other.d "$expected_d_content" - compare_file reference_test.o test.o + compare_object reference_test.o test.o rm -f other.d @@ -911,7 +931,7 @@ EOF checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 checkfile different_name.d "$expected_d_content" - compare_file reference_test.o test.o + compare_object reference_test.o test.o rm -f different_name.d @@ -926,7 +946,7 @@ EOF checkstat 'cache miss' 1 checkfile other.d "$expected_mmd_d_content" CCACHE_DISABLE=1 $COMPILER -c -Wp,-MMD,other.d test.c -o reference_test.o - compare_file reference_test.o test.o + compare_object reference_test.o test.o rm -f other.d @@ -935,7 +955,7 @@ EOF checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 checkfile other.d "$expected_mmd_d_content" - compare_file reference_test.o test.o + compare_object reference_test.o test.o rm -f other.d @@ -944,7 +964,7 @@ EOF checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 checkfile different_name.d "$expected_mmd_d_content" - compare_file reference_test.o test.o + compare_object reference_test.o test.o rm -f different_name.d @@ -972,7 +992,7 @@ EOF checkstat 'cache miss' 1 checkfile test.d "$expected_d_content" CCACHE_DISABLE=1 $COMPILER -c -MD test.c -o reference_test.o - compare_file reference_test.o test.o + compare_object reference_test.o test.o rm -f test.d @@ -981,7 +1001,7 @@ EOF checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 checkfile test.d "$expected_d_content" - compare_file reference_test.o test.o + compare_object reference_test.o test.o ################################################################## # Check that coverage works. @@ -1024,7 +1044,7 @@ EOF checkstat 'cache miss' 1 checkfile test.d "$expected_d_content" CCACHE_DISABLE=1 $COMPILER -c -MD test.c -o reference_test.o - compare_file reference_test.o test.o + compare_object reference_test.o test.o rm -f test.d @@ -1033,7 +1053,7 @@ EOF checkstat 'cache hit (preprocessed)' 1 checkstat 'cache miss' 1 checkfile test.d "$expected_d_content" - compare_file reference_test.o test.o + compare_object reference_test.o test.o rm -f test.d @@ -1042,7 +1062,7 @@ EOF checkstat 'cache hit (preprocessed)' 2 checkstat 'cache miss' 1 checkfile test.d "$expected_d_content" - compare_file reference_test.o test.o + compare_object reference_test.o test.o rm -f test.d @@ -1051,7 +1071,7 @@ EOF checkstat 'cache hit (preprocessed)' 2 checkstat 'cache miss' 1 checkfile test.d "$expected_d_content" - compare_file reference_test.o test.o + compare_object reference_test.o test.o ################################################################## # Check that -MF works. @@ -1064,7 +1084,7 @@ EOF checkstat 'cache miss' 1 checkfile other.d "$expected_d_content" CCACHE_DISABLE=1 $COMPILER -c -MD -MF other.d test.c -o reference_test.o - compare_file reference_test.o test.o + compare_object reference_test.o test.o rm -f other.d @@ -1073,14 +1093,14 @@ EOF checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 checkfile other.d "$expected_d_content" - compare_file reference_test.o test.o + compare_object reference_test.o test.o $CCACHE $COMPILER -c -MD -MF different_name.d test.c checkstat 'cache hit (direct)' 2 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 checkfile different_name.d "$expected_d_content" - compare_file reference_test.o test.o + compare_object reference_test.o test.o rm -f different_name.d @@ -1089,7 +1109,7 @@ EOF checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 checkfile third_name.d "$expected_d_content" - compare_file reference_test.o test.o + compare_object reference_test.o test.o rm -f third_name.d @@ -1105,14 +1125,14 @@ EOF checkstat 'cache miss' 1 checkfile other.d "$expected_d_content" CCACHE_DISABLE=1 $COMPILER -c -MD test.c -o reference_test.o - compare_file reference_test.o test.o + compare_object reference_test.o test.o $CCACHE $COMPILER -c -MD test.c checkstat 'cache hit (direct)' 1 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 checkfile other.d "$expected_d_content" - compare_file reference_test.o test.o + compare_object reference_test.o test.o find $CCACHE_DIR -name '*.d' -exec rm -f '{}' \; @@ -1121,7 +1141,7 @@ EOF checkstat 'cache hit (preprocessed)' 1 checkstat 'cache miss' 1 checkfile other.d "$expected_d_content" - compare_file reference_test.o test.o + compare_object reference_test.o test.o ################################################################## # Check that stderr from both the preprocessor and the compiler is emitted @@ -1691,7 +1711,7 @@ readonly_suite() { echo "int test2;" >test2.c # Cache a compilation. - $CCACHE $COMPILER -c test.c -o test.o + $CCACHE $COMPILER -c test.c -o test.o 2>/dev/null checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 @@ -2224,7 +2244,7 @@ gcc_pch_suite() { clang_pch_suite() { ################################################################## - # Tests for creating a .gch. + # Tests for creating a .gch without opt-in. backdate pch.h @@ -2233,9 +2253,30 @@ clang_pch_suite() { $CCACHE $COMPILER $SYSROOT -c pch.h checkstat 'cache hit (direct)' 0 checkstat 'cache hit (preprocessed)' 0 + checkstat 'cache miss' 0 + checkstat "can't use precompiled header" 1 + + testname="create .gch, no -c, -o, without opt-in" + $CCACHE -Cz >/dev/null + $CCACHE $COMPILER pch.h -o pch.gch + checkstat 'cache hit (direct)' 0 + checkstat 'cache hit (preprocessed)' 0 + checkstat 'cache miss' 0 + checkstat "can't use precompiled header" 1 + + ################################################################## + # Tests for creating a .gch with opt-in. + + backdate pch.h + + testname="create .gch, -c, no -o, with opt-in" + $CCACHE -zC >/dev/null + CCACHE_SLOPPINESS=pch_defines,time_macros $CCACHE $COMPILER $SYSROOT -c pch.h + checkstat 'cache hit (direct)' 0 + checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 rm -f pch.h.gch - $CCACHE $COMPILER $SYSROOT -c pch.h + CCACHE_SLOPPINESS=pch_defines,time_macros $CCACHE $COMPILER $SYSROOT -c pch.h checkstat 'cache hit (direct)' 1 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 @@ -2243,13 +2284,13 @@ clang_pch_suite() { test_failed "pch.h.gch missing" fi - testname="create .gch, no -c, -o" + testname="create .gch, no -c, -o, with opt-in" $CCACHE -Cz >/dev/null - $CCACHE $COMPILER $SYSROOT pch.h -o pch.gch + CCACHE_SLOPPINESS=pch_defines,time_macros $CCACHE $COMPILER $SYSROOT pch.h -o pch.gch checkstat 'cache hit (direct)' 0 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 - $CCACHE $COMPILER $SYSROOT pch.h -o pch.gch + CCACHE_SLOPPINESS=pch_defines,time_macros $CCACHE $COMPILER $SYSROOT pch.h -o pch.gch checkstat 'cache hit (direct)' 1 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 @@ -2274,11 +2315,11 @@ clang_pch_suite() { testname="gch, no -fpch-preprocess, -include, sloppy time macros" $CCACHE -Cz >/dev/null - CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER $SYSROOT -c -include pch.h pch2.c 2>/dev/null + CCACHE_SLOPPINESS="$default_sloppiness pch_defines time_macros" $CCACHE $COMPILER $SYSROOT -c -include pch.h pch2.c 2>/dev/null checkstat 'cache hit (direct)' 0 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 - CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER $SYSROOT -c -include pch.h pch2.c 2>/dev/null + CCACHE_SLOPPINESS="$default_sloppiness pch_defines time_macros" $CCACHE $COMPILER $SYSROOT -c -include pch.h pch2.c 2>/dev/null checkstat 'cache hit (direct)' 1 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 @@ -2293,11 +2334,11 @@ clang_pch_suite() { testname="gch, preprocessor mode" $CCACHE -Cz >/dev/null - CCACHE_NODIRECT=1 CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER $SYSROOT -c -include pch.h -fpch-preprocess pch.c + CCACHE_NODIRECT=1 CCACHE_SLOPPINESS="$default_sloppiness pch_defines time_macros" $CCACHE $COMPILER $SYSROOT -c -include pch.h -fpch-preprocess pch.c checkstat 'cache hit (direct)' 0 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 - CCACHE_NODIRECT=1 CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER $SYSROOT -c -include pch.h -fpch-preprocess pch.c + CCACHE_NODIRECT=1 CCACHE_SLOPPINESS="$default_sloppiness pch_defines time_macros" $CCACHE $COMPILER $SYSROOT -c -include pch.h -fpch-preprocess pch.c checkstat 'cache hit (direct)' 0 checkstat 'cache hit (preprocessed)' 1 checkstat 'cache miss' 1 @@ -2305,11 +2346,11 @@ clang_pch_suite() { testname="gch, preprocessor mode, file changed" echo "updated" >>pch.h.gch # clang seems to cope with this... backdate pch.h.gch - CCACHE_NODIRECT=1 CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER $SYSROOT -c -include pch.h -fpch-preprocess pch.c + CCACHE_NODIRECT=1 CCACHE_SLOPPINESS="$default_sloppiness pch_defines time_macros" $CCACHE $COMPILER $SYSROOT -c -include pch.h -fpch-preprocess pch.c checkstat 'cache hit (direct)' 0 checkstat 'cache hit (preprocessed)' 1 checkstat 'cache miss' 2 - CCACHE_NODIRECT=1 CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER $SYSROOT -c -include pch.h -fpch-preprocess pch.c + CCACHE_NODIRECT=1 CCACHE_SLOPPINESS="$default_sloppiness pch_defines time_macros" $CCACHE $COMPILER $SYSROOT -c -include pch.h -fpch-preprocess pch.c checkstat 'cache hit (direct)' 0 checkstat 'cache hit (preprocessed)' 2 checkstat 'cache miss' 2 @@ -2323,12 +2364,12 @@ clang_pch_suite() { testname="create .pth, -c, -o" $CCACHE -zC >/dev/null - $CCACHE $COMPILER $SYSROOT -c pch.h -o pch.h.pth + CCACHE_SLOPPINESS=pch_defines,time_macros $CCACHE $COMPILER $SYSROOT -c pch.h -o pch.h.pth checkstat 'cache hit (direct)' 0 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 rm -f pch.h.pth - $CCACHE $COMPILER $SYSROOT -c pch.h -o pch.h.pth + CCACHE_SLOPPINESS=pch_defines,time_macros $CCACHE $COMPILER $SYSROOT -c pch.h -o pch.h.pth checkstat 'cache hit (direct)' 1 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 @@ -2352,11 +2393,11 @@ clang_pch_suite() { testname="pth, no -fpch-preprocess, -include, sloppy time macros" $CCACHE -Cz >/dev/null - CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER $SYSROOT -c -include pch.h pch2.c 2>/dev/null + CCACHE_SLOPPINESS="$default_sloppiness pch_defines time_macros" $CCACHE $COMPILER $SYSROOT -c -include pch.h pch2.c 2>/dev/null checkstat 'cache hit (direct)' 0 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 - CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER $SYSROOT -c -include pch.h pch2.c 2>/dev/null + CCACHE_SLOPPINESS="$default_sloppiness pch_defines time_macros" $CCACHE $COMPILER $SYSROOT -c -include pch.h pch2.c 2>/dev/null checkstat 'cache hit (direct)' 1 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 @@ -2364,7 +2405,7 @@ clang_pch_suite() { testname="pth, -fpch-preprocess, -include, file changed" echo "updated" >>pch.h.pth # clang seems to cope with this... backdate pch.h.pth - CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER $SYSROOT -c -include pch.h -fpch-preprocess pch.c + CCACHE_SLOPPINESS="$default_sloppiness pch_defines time_macros" $CCACHE $COMPILER $SYSROOT -c -include pch.h -fpch-preprocess pch.c checkstat 'cache hit (direct)' 1 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 2 @@ -2383,11 +2424,11 @@ clang_pch_suite() { testname="pth, preprocessor mode, file changed" echo "updated" >>pch.h.pth # clang seems to cope with this... backdate pch.h.pth - CCACHE_NODIRECT=1 CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER $SYSROOT -c -include pch.h -fpch-preprocess pch.c + CCACHE_NODIRECT=1 CCACHE_SLOPPINESS="$default_sloppiness pch_defines time_macros" $CCACHE $COMPILER $SYSROOT -c -include pch.h -fpch-preprocess pch.c checkstat 'cache hit (direct)' 0 checkstat 'cache hit (preprocessed)' 1 checkstat 'cache miss' 2 - CCACHE_NODIRECT=1 CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER $SYSROOT -c -include pch.h -fpch-preprocess pch.c + CCACHE_NODIRECT=1 CCACHE_SLOPPINESS="$default_sloppiness pch_defines time_macros" $CCACHE $COMPILER $SYSROOT -c -include pch.h -fpch-preprocess pch.c checkstat 'cache hit (direct)' 0 checkstat 'cache hit (preprocessed)' 2 checkstat 'cache miss' 2 @@ -2470,7 +2511,9 @@ COMPILER_TYPE_CLANG=0 COMPILER_TYPE_GCC=0 COMPILER_USES_LLVM=0 + HOST_OS_APPLE=0 +HOST_OS_LINUX=0 compiler_version="`$COMPILER --version 2>&1 | head -1`" case $compiler_version in @@ -2497,6 +2540,9 @@ case $host_os in *Darwin*) HOST_OS_APPLE=1 ;; + *Linux*) + HOST_OS_LINUX=1 + ;; esac TESTDIR=testdir.$$ -- 2.47.2