492
578
$CCACHE -C > /dev/null
493
579
checkstat 'files in cache' 0
581
# the profile options do not seem to work correctly with clang or gcc-llvm
584
if [ $HOST_OS_APPLE -eq 1 ] && [ $COMPILER_USES_LLVM -eq 1 ]; then
588
$COMPILER -c -fprofile-generate test1.c 2>/dev/null
589
if [ $? -eq 0 ] && [ $darwin_llvm -eq 0 ]; then
590
testname="profile-generate"
591
$CCACHE -Cz > /dev/null
592
$CCACHE_COMPILE -c -fprofile-generate test1.c
593
checkstat 'cache hit (preprocessed)' 0
594
checkstat 'cache miss' 1
595
checkstat 'files in cache' 1
596
$CCACHE_COMPILE -c -fprofile-generate test1.c
597
checkstat 'cache hit (preprocessed)' 1
598
checkstat 'cache miss' 1
599
checkstat 'files in cache' 1
601
testname="profile-arcs"
602
$CCACHE_COMPILE -c -fprofile-arcs test1.c
603
checkstat 'cache hit (preprocessed)' 1
604
checkstat 'cache miss' 2
605
checkstat 'files in cache' 2
606
$CCACHE_COMPILE -c -fprofile-arcs test1.c
607
checkstat 'cache hit (preprocessed)' 2
608
checkstat 'cache miss' 2
609
checkstat 'files in cache' 2
611
testname="profile-use"
612
$CCACHE_COMPILE -c -fprofile-use test1.c 2>/dev/null
613
checkstat 'cache hit (preprocessed)' 2
614
checkstat 'cache miss' 3
615
$CCACHE_COMPILE -c -fprofile-use test1.c 2>/dev/null
616
checkstat 'cache hit (preprocessed)' 3
617
checkstat 'cache miss' 3
620
##################################################################
621
# Check that -Wp,-P disables ccache. (-P removes preprocessor information
622
# in such a way that the object file from compiling the preprocessed file
623
# will not be equal to the object file produced when compiling without
626
$CCACHE -Cz >/dev/null
627
$CCACHE_COMPILE -c -Wp,-P test1.c
628
checkstat 'cache hit (direct)' 0
629
checkstat 'cache hit (preprocessed)' 0
630
checkstat 'cache miss' 0
631
checkstat 'unsupported compiler option' 1
632
$CCACHE_COMPILE -c -Wp,-P test1.c
633
checkstat 'cache hit (direct)' 0
634
checkstat 'cache hit (preprocessed)' 0
635
checkstat 'cache miss' 0
636
checkstat 'unsupported compiler option' 2
637
$CCACHE_COMPILE -c -Wp,-DFOO,-P,-DGOO test1.c
638
checkstat 'cache hit (direct)' 0
639
checkstat 'cache hit (preprocessed)' 0
640
checkstat 'cache miss' 0
641
checkstat 'unsupported compiler option' 3
642
$CCACHE_COMPILE -c -Wp,-DFOO,-P,-DGOO test1.c
643
checkstat 'cache hit (direct)' 0
644
checkstat 'cache hit (preprocessed)' 0
645
checkstat 'cache miss' 0
646
checkstat 'unsupported compiler option' 4
648
##################################################################
650
if [ $COMPILER_TYPE_CLANG -eq 1 ]; then
651
testname="serialize-diagnostics"
652
$CCACHE -Cz > /dev/null
653
$COMPILER -c --serialize-diagnostics expected.dia test1.c 2> /dev/null
654
# Run with CCACHE_CPP2 to ensure the same diagnostics output as above
655
CCACHE_CPP2=1 $CCACHE_COMPILE -c --serialize-diagnostics test.dia test1.c 2> /dev/null
656
checkstat 'cache hit (preprocessed)' 0
657
checkstat 'cache miss' 1
658
checkstat 'files in cache' 2
659
compare_file expected.dia test.dia
661
CCACHE_CPP2=1 $CCACHE_COMPILE -c --serialize-diagnostics test.dia test1.c 2> /dev/null
662
checkstat 'cache hit (preprocessed)' 1
663
checkstat 'cache miss' 1
664
checkstat 'files in cache' 2
665
compare_file expected.dia test.dia
670
testname="serialize-diagnostics-compile-failed"
671
$CCACHE -Cz > /dev/null
672
echo "bad source" >error.c
673
$COMPILER -c --serialize-diagnostics expected.dia error.c 2> /dev/null
674
if [ $? -eq 0 ]; then
675
test_failed "expected an error compiling error.c"
677
CCACHE_CPP2=1 $CCACHE_COMPILE -c --serialize-diagnostics test.dia error.c 2> /dev/null
678
checkstat 'compile failed' 1
679
checkstat 'cache hit (preprocessed)' 0
680
checkstat 'cache miss' 0
681
checkstat 'files in cache' 0
682
compare_file expected.dia test.dia
684
CCACHE_CPP2=1 $CCACHE_COMPILE -c --serialize-diagnostics test.dia error.c 2> /dev/null
685
checkstat 'compile failed' 2
686
checkstat 'cache hit (preprocessed)' 0
687
checkstat 'cache miss' 0
688
checkstat 'files in cache' 0
689
compare_file expected.dia test.dia
692
##################################################################
718
933
checkstat 'cache hit (preprocessed)' 0
719
934
checkstat 'cache miss' 1
720
935
checkfile other.d "$expected_mmd_d_content"
936
compare_file reference_test.o test.o
724
##################################################################
725
# Check that -Wp,-MD,file.d,-P disables direct mode.
726
testname="-Wp,-MD,file.d,-P"
727
$CCACHE -z >/dev/null
728
$CCACHE $COMPILER -c -Wp,-MD,$DEVNULL,-P test.c
729
checkstat 'cache hit (direct)' 0
730
checkstat 'cache hit (preprocessed)' 0
731
checkstat 'cache miss' 1
733
$CCACHE $COMPILER -c -Wp,-MD,$DEVNULL,-P test.c
734
checkstat 'cache hit (direct)' 0
735
checkstat 'cache hit (preprocessed)' 1
736
checkstat 'cache miss' 1
738
##################################################################
739
# Check that -Wp,-MMD,file.d,-P disables direct mode.
740
testname="-Wp,-MDD,file.d,-P"
741
$CCACHE -z >/dev/null
742
$CCACHE $COMPILER -c -Wp,-MMD,$DEVNULL,-P test.c
743
checkstat 'cache hit (direct)' 0
744
checkstat 'cache hit (preprocessed)' 0
745
checkstat 'cache miss' 1
747
$CCACHE $COMPILER -c -Wp,-MMD,$DEVNULL,-P test.c
748
checkstat 'cache hit (direct)' 0
749
checkstat 'cache hit (preprocessed)' 1
750
checkstat 'cache miss' 1
940
$CCACHE $COMPILER -c -Wp,-MMD,different_name.d test.c
941
checkstat 'cache hit (direct)' 2
942
checkstat 'cache hit (preprocessed)' 0
943
checkstat 'cache miss' 1
944
checkfile different_name.d "$expected_mmd_d_content"
945
compare_file reference_test.o test.o
947
rm -f different_name.d
752
949
##################################################################
753
950
# Test some header modifications to get multiple objects in the manifest.
1203
1423
checkstat 'cache hit (direct)' 2
1204
1424
checkstat 'cache hit (preprocessed)' 0
1205
1425
checkstat 'cache miss' 2
1427
testname="comment in strings"
1428
$CCACHE -Cz >/dev/null
1429
echo 'char *comment = " /* \\\\u" "foo" " */";' >comment.c
1430
$CCACHE $COMPILER -c comment.c
1431
checkstat 'cache hit (direct)' 0
1432
checkstat 'cache hit (preprocessed)' 0
1433
checkstat 'cache miss' 1
1434
$CCACHE $COMPILER -c comment.c
1435
checkstat 'cache hit (direct)' 1
1436
checkstat 'cache hit (preprocessed)' 0
1437
checkstat 'cache miss' 1
1438
echo 'char *comment = " /* \\\\u" "goo" " */";' >comment.c
1439
$CCACHE $COMPILER -c comment.c
1440
checkstat 'cache hit (direct)' 1
1441
checkstat 'cache hit (preprocessed)' 0
1442
checkstat 'cache miss' 2
1444
#################################################################
1445
# Check that strange "#line" directives are handled.
1446
testname="#line directives with troublesome files"
1447
$CCACHE -Cz >/dev/null
1448
cat <<EOF >strange.c
1451
for x in stdout tty sda hda; do
1452
if [ -b /dev/$x ] || [ -c /dev/$x ]; then
1453
echo "#line 1 \"/dev/$x\"" >> strange.c
1456
CCACHE_SLOPPINESS="$default_sloppiness include_file_mtime" $CCACHE $COMPILER -c strange.c
1457
manifest=`find $CCACHE_DIR -name '*.manifest'`
1458
if [ -n "$manifest" ]; then
1459
data="`$CCACHE --dump-manifest $manifest | egrep '/dev/(stdout|tty|sda|hda'`"
1460
if [ -n "$data" ]; then
1461
test_failed "$manifest contained troublesome file(s): $data"
1465
##################################################################
1466
# Test --dump-manifest output.
1467
testname="--dump-manifest"
1468
$CCACHE -Cz >/dev/null
1469
$CCACHE $COMPILER test.c -c -o test.o
1470
manifest=`find $CCACHE_DIR -name '*.manifest'`
1471
$CCACHE --dump-manifest $manifest >manifest.dump
1473
if grep 'Hash: e6b009695d072974f2c4d1dd7e7ed4fc' manifest.dump >/dev/null 2>&1 && \
1474
grep 'Hash: e94ceb9f1b196c387d098a5f1f4fe862' manifest.dump >/dev/null 2>&1 && \
1475
grep 'Hash: c2f5392dbc7e8ff6138d01608445240a' manifest.dump >/dev/null 2>&1; then
1478
test_failed "unexpected output of --dump-manifest"
1208
1482
basedir_suite() {
1843
2187
testname="preprocessor mode, file changed"
1844
2188
echo "updated" >>pch.h.gch # GCC seems to cope with this...
1845
2189
backdate pch.h.gch
1846
CCACHE_NODIRECT=1 CCACHE_SLOPPINESS=pch_defines,time_macros $CCACHE $COMPILER -c -fpch-preprocess pch.c
1847
checkstat 'cache hit (direct)' 0
1848
checkstat 'cache hit (preprocessed)' 1
1849
checkstat 'cache miss' 2
1850
CCACHE_NODIRECT=1 CCACHE_SLOPPINESS=pch_defines,time_macros $CCACHE $COMPILER -c -fpch-preprocess pch.c
1851
checkstat 'cache hit (direct)' 0
1852
checkstat 'cache hit (preprocessed)' 2
1853
checkstat 'cache miss' 2
2190
CCACHE_NODIRECT=1 CCACHE_SLOPPINESS="$default_sloppiness pch_defines time_macros" $CCACHE $COMPILER $SYSROOT -c -fpch-preprocess pch.c
2191
checkstat 'cache hit (direct)' 0
2192
checkstat 'cache hit (preprocessed)' 1
2193
checkstat 'cache miss' 2
2194
CCACHE_NODIRECT=1 CCACHE_SLOPPINESS="$default_sloppiness pch_defines time_macros" $CCACHE $COMPILER $SYSROOT -c -fpch-preprocess pch.c
2195
checkstat 'cache hit (direct)' 0
2196
checkstat 'cache hit (preprocessed)' 2
2197
checkstat 'cache miss' 2
2201
##################################################################
2202
# Tests for creating a .gch.
2206
testname="create .gch, -c, no -o"
2207
$CCACHE -zC >/dev/null
2208
$CCACHE $COMPILER $SYSROOT -c pch.h
2209
checkstat 'cache hit (direct)' 0
2210
checkstat 'cache hit (preprocessed)' 0
2211
checkstat 'cache miss' 1
2213
$CCACHE $COMPILER $SYSROOT -c pch.h
2214
checkstat 'cache hit (direct)' 1
2215
checkstat 'cache hit (preprocessed)' 0
2216
checkstat 'cache miss' 1
2217
if [ ! -f pch.h.gch ]; then
2218
test_failed "pch.h.gch missing"
2221
testname="create .gch, no -c, -o"
2222
$CCACHE -Cz >/dev/null
2223
$CCACHE $COMPILER $SYSROOT pch.h -o pch.gch
2224
checkstat 'cache hit (direct)' 0
2225
checkstat 'cache hit (preprocessed)' 0
2226
checkstat 'cache miss' 1
2227
$CCACHE $COMPILER $SYSROOT pch.h -o pch.gch
2228
checkstat 'cache hit (direct)' 1
2229
checkstat 'cache hit (preprocessed)' 0
2230
checkstat 'cache miss' 1
2231
if [ ! -f pch.gch ]; then
2232
test_failed "pch.gch missing"
2236
##################################################################
2237
# Tests for using a .gch.
2241
testname="gch, no -fpch-preprocess, -include, no sloppy time macros"
2242
$CCACHE -Cz >/dev/null
2243
$CCACHE $COMPILER $SYSROOT -c -include pch.h pch2.c 2>/dev/null
2244
checkstat 'cache hit (direct)' 0
2245
checkstat 'cache hit (preprocessed)' 0
2246
checkstat 'cache miss' 0
2247
# Must enable sloppy time macros:
2248
checkstat "can't use precompiled header" 1
2250
testname="gch, no -fpch-preprocess, -include, sloppy time macros"
2251
$CCACHE -Cz >/dev/null
2252
CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER $SYSROOT -c -include pch.h pch2.c 2>/dev/null
2253
checkstat 'cache hit (direct)' 0
2254
checkstat 'cache hit (preprocessed)' 0
2255
checkstat 'cache miss' 1
2256
CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER $SYSROOT -c -include pch.h pch2.c 2>/dev/null
2257
checkstat 'cache hit (direct)' 1
2258
checkstat 'cache hit (preprocessed)' 0
2259
checkstat 'cache miss' 1
2261
testname="gch, -fpch-preprocess, -include, file changed"
2262
echo "updated" >>pch.h.gch # clang seems to cope with this...
2264
CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER $SYSROOT -c -include pch.h -fpch-preprocess pch.c
2265
checkstat 'cache hit (direct)' 1
2266
checkstat 'cache hit (preprocessed)' 0
2267
checkstat 'cache miss' 2
2269
testname="gch, preprocessor mode"
2270
$CCACHE -Cz >/dev/null
2271
CCACHE_NODIRECT=1 CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER $SYSROOT -c -include pch.h -fpch-preprocess pch.c
2272
checkstat 'cache hit (direct)' 0
2273
checkstat 'cache hit (preprocessed)' 0
2274
checkstat 'cache miss' 1
2275
CCACHE_NODIRECT=1 CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER $SYSROOT -c -include pch.h -fpch-preprocess pch.c
2276
checkstat 'cache hit (direct)' 0
2277
checkstat 'cache hit (preprocessed)' 1
2278
checkstat 'cache miss' 1
2280
testname="gch, preprocessor mode, file changed"
2281
echo "updated" >>pch.h.gch # clang seems to cope with this...
2283
CCACHE_NODIRECT=1 CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER $SYSROOT -c -include pch.h -fpch-preprocess pch.c
2284
checkstat 'cache hit (direct)' 0
2285
checkstat 'cache hit (preprocessed)' 1
2286
checkstat 'cache miss' 2
2287
CCACHE_NODIRECT=1 CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER $SYSROOT -c -include pch.h -fpch-preprocess pch.c
2288
checkstat 'cache hit (direct)' 0
2289
checkstat 'cache hit (preprocessed)' 2
2290
checkstat 'cache miss' 2
2294
##################################################################
2295
# Tests for creating a .pth.
2299
testname="create .pth, -c, -o"
2300
$CCACHE -zC >/dev/null
2301
$CCACHE $COMPILER $SYSROOT -c pch.h -o pch.h.pth
2302
checkstat 'cache hit (direct)' 0
2303
checkstat 'cache hit (preprocessed)' 0
2304
checkstat 'cache miss' 1
2306
$CCACHE $COMPILER $SYSROOT -c pch.h -o pch.h.pth
2307
checkstat 'cache hit (direct)' 1
2308
checkstat 'cache hit (preprocessed)' 0
2309
checkstat 'cache miss' 1
2310
if [ ! -f pch.h.pth ]; then
2311
test_failed "pch.h.pth missing"
2314
##################################################################
2315
# Tests for using a .pth.
2319
testname="pth, no -fpch-preprocess, -include, no sloppy time macros"
2320
$CCACHE -Cz >/dev/null
2321
$CCACHE $COMPILER $SYSROOT -c -include pch.h pch2.c
2322
checkstat 'cache hit (direct)' 0
2323
checkstat 'cache hit (preprocessed)' 0
2324
checkstat 'cache miss' 0
2325
# Must enable sloppy time macros:
2326
checkstat "can't use precompiled header" 1
2328
testname="pth, no -fpch-preprocess, -include, sloppy time macros"
2329
$CCACHE -Cz >/dev/null
2330
CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER $SYSROOT -c -include pch.h pch2.c 2>/dev/null
2331
checkstat 'cache hit (direct)' 0
2332
checkstat 'cache hit (preprocessed)' 0
2333
checkstat 'cache miss' 1
2334
CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER $SYSROOT -c -include pch.h pch2.c 2>/dev/null
2335
checkstat 'cache hit (direct)' 1
2336
checkstat 'cache hit (preprocessed)' 0
2337
checkstat 'cache miss' 1
2339
testname="pth, -fpch-preprocess, -include, file changed"
2340
echo "updated" >>pch.h.pth # clang seems to cope with this...
2342
CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER $SYSROOT -c -include pch.h -fpch-preprocess pch.c
2343
checkstat 'cache hit (direct)' 1
2344
checkstat 'cache hit (preprocessed)' 0
2345
checkstat 'cache miss' 2
2347
testname="pth, preprocessor mode"
2348
$CCACHE -Cz >/dev/null
2349
CCACHE_NODIRECT=1 CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER $SYSROOT -c -include pch.h -fpch-preprocess pch.c
2350
checkstat 'cache hit (direct)' 0
2351
checkstat 'cache hit (preprocessed)' 0
2352
checkstat 'cache miss' 1
2353
CCACHE_NODIRECT=1 CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER $SYSROOT -c -include pch.h -fpch-preprocess pch.c
2354
checkstat 'cache hit (direct)' 0
2355
checkstat 'cache hit (preprocessed)' 1
2356
checkstat 'cache miss' 1
2358
testname="pth, preprocessor mode, file changed"
2359
echo "updated" >>pch.h.pth # clang seems to cope with this...
2361
CCACHE_NODIRECT=1 CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER $SYSROOT -c -include pch.h -fpch-preprocess pch.c
2362
checkstat 'cache hit (direct)' 0
2363
checkstat 'cache hit (preprocessed)' 1
2364
checkstat 'cache miss' 2
2365
CCACHE_NODIRECT=1 CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER $SYSROOT -c -include pch.h -fpch-preprocess pch.c
2366
checkstat 'cache hit (direct)' 0
2367
checkstat 'cache hit (preprocessed)' 2
2368
checkstat 'cache miss' 2
2374
testname="keep maxfiles and maxsize settings"
2375
rm -rf $CCACHE_DIR $CCACHE_CONFIGPATH
2376
mkdir -p $CCACHE_DIR/0
2377
echo "0 0 0 0 0 0 0 0 0 0 0 0 0 2000 131072" >$CCACHE_DIR/0/stats
2378
checkstat 'max files' 32000
2379
checkstat 'max cache size' '2.1 GB'
2384
$CCACHE -Cz >/dev/null
2386
cat <<'EOF' >prefix-a
2388
echo a >>prefix.result
2391
cat <<'EOF' >prefix-b
2393
echo b >>prefix.result
2396
chmod +x prefix-a prefix-b
2400
PATH=.:$PATH CCACHE_PREFIX="prefix-a prefix-b" $CCACHE $COMPILER -c file.c
2401
checkstat 'cache hit (direct)' 0
2402
checkstat 'cache hit (preprocessed)' 0
2403
checkstat 'cache miss' 1
2404
checkfile prefix.result "a
2406
PATH=.:$PATH CCACHE_PREFIX="prefix-a prefix-b" $CCACHE $COMPILER -c file.c
2407
checkstat 'cache hit (direct)' 0
2408
checkstat 'cache hit (preprocessed)' 1
2409
checkstat 'cache miss' 1
2410
checkfile prefix.result "a
1856
2414
######################################################################
2417
if pwd | grep '[^A-Za-z0-9/.,=_%+-]' >/dev/null 2>&1; then
2419
Error: The test suite doesn't work in directories with whitespace or other
2420
funny characters in the name. Sorry.
1860
2426
if [ -n "$CC" ]; then