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"
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
$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
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
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
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
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
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
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
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
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
EOF
cat <<EOF >code.c
/* code.c */
-int test() {}
+int test() { return 0; }
EOF
backdate test1.h test2.h test3.h
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
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
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
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
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
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
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
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.
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
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
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
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.
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
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
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
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 '{}' \;
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
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
clang_pch_suite() {
##################################################################
- # Tests for creating a .gch.
+ # Tests for creating a .gch without opt-in.
backdate pch.h
$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
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
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
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
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
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
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
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
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
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
*Darwin*)
HOST_OS_APPLE=1
;;
+ *Linux*)
+ HOST_OS_LINUX=1
+ ;;
esac
TESTDIR=testdir.$$