3 # A simple test suite for ccache.
5 # Copyright (C) 2002-2007 Andrew Tridgell
6 # Copyright (C) 2009-2011 Joel Rosdahl
8 # This program is free software; you can redistribute it and/or modify it under
9 # the terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 3 of the License, or (at your option) any later
13 # This program is distributed in the hope that it will be useful, but WITHOUT
14 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 # You should have received a copy of the GNU General Public License along with
19 # this program; if not, write to the Free Software Foundation, Inc., 51
20 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 unset CCACHE_COMPILERCHECK
29 unset CCACHE_EXTENSION
30 unset CCACHE_EXTRAFILES
41 unset CCACHE_SLOPPINESS
47 echo "SUITE: \"$testsuite\", TEST: \"$testname\" - $1"
51 echo "Test data and log file have been left in $TESTDIR"
60 while [ $i -lt $nlines ]; do
61 echo "int foo$nlines$i(int x) { return x; }"
70 value=`$CCACHE -s | grep "$stat" | cut -c34-40`
77 value=`getstat "$stat"`
78 if [ "$expected_value" != "$value" ]; then
79 test_failed "Expected \"$stat\" to be $expected_value, got $value"
85 test_failed "$1 not found"
87 if [ "`cat $1`" != "$2" ]; then
88 test_failed "Bad content of $1.\nExpected: $2\nActual: `cat $1`"
96 actual=`find $dir -name "$pattern" | wc -l`
97 if [ $actual -ne $expected ]; then
98 test_failed "Found $actual (expected $expected) $pattern files in $dir"
106 sed "$expr" > ${file}.sed < $file
112 touch -t 199901010000 "$@"
118 export CCACHE_NODIRECT
120 echo "starting testsuite $1"
125 testname="the tmp directory should be empty"
126 if [ -d $CCACHE_DIR/tmp ] && [ "`find $CCACHE_DIR/tmp -type f | wc -l`" -gt 0 ]; then
127 test_failed "$CCACHE_DIR/tmp is not empty"
132 checkstat 'cache hit (preprocessed)' 0
133 checkstat 'cache miss' 0
134 checkstat 'files in cache' 0
138 while [ $j -lt 32 ]; do
144 $CCACHE_COMPILE -c test1.c
145 checkstat 'cache hit (preprocessed)' 0
146 checkstat 'cache miss' 1
147 checkstat 'files in cache' 1
150 $CCACHE_COMPILE -c test1.c
151 checkstat 'cache hit (preprocessed)' 1
152 checkstat 'cache miss' 1
153 checkstat 'files in cache' 1
156 $CCACHE_COMPILE -c test1.c -g
157 checkstat 'cache hit (preprocessed)' 1
158 checkstat 'cache miss' 2
159 checkstat 'files in cache' 2
162 $CCACHE_COMPILE -c test1.c -g
163 checkstat 'cache hit (preprocessed)' 2
164 checkstat 'cache miss' 2
167 $CCACHE_COMPILE -c test1.c -o foo.o
168 checkstat 'cache hit (preprocessed)' 3
169 checkstat 'cache miss' 2
172 $CCACHE_COMPILE test1.c -o test 2> /dev/null
173 checkstat 'called for link' 1
176 $CCACHE_COMPILE foo.o -o test 2> /dev/null
177 checkstat 'called for link' 2
179 testname="preprocessing"
180 $CCACHE_COMPILE -E -c test1.c > /dev/null 2>&1
181 checkstat 'called for preprocessing' 1
184 $CCACHE_COMPILE -c test1.c test2.c
185 checkstat 'multiple source files' 1
188 $CCACHE blahblah -c test1.c 2> /dev/null
189 checkstat "couldn't find the compiler" 1
192 $CCACHE_COMPILE -c test1.c -I 2> /dev/null
193 checkstat 'bad compiler arguments' 1
195 testname="unsupported source language"
196 ln -f test1.c test1.ccc
197 $CCACHE_COMPILE -c test1.ccc 2> /dev/null
198 checkstat 'unsupported source language' 1
200 testname="unsupported"
201 $CCACHE_COMPILE -M foo -c test1.c > /dev/null 2>&1
202 checkstat 'unsupported compiler option' 1
205 $CCACHE echo foo -c test1.c > /dev/null
206 checkstat 'compiler produced stdout' 1
208 testname="non-regular"
210 $CCACHE_COMPILE -o testd -c test1.c > /dev/null 2>&1
212 checkstat 'output to a non-regular file' 1
215 $CCACHE_COMPILE -c -O2 2> /dev/null
216 checkstat 'no input file' 1
218 testname="CCACHE_DISABLE"
219 CCACHE_DISABLE=1 $CCACHE_COMPILE -c test1.c 2> /dev/null
220 checkstat 'cache hit (preprocessed)' 3
221 $CCACHE_COMPILE -c test1.c
222 checkstat 'cache hit (preprocessed)' 4
224 testname="CCACHE_CPP2"
225 CCACHE_CPP2=1 $CCACHE_COMPILE -c test1.c -O -O
226 checkstat 'cache hit (preprocessed)' 4
227 checkstat 'cache miss' 3
229 CCACHE_CPP2=1 $CCACHE_COMPILE -c test1.c -O -O
230 checkstat 'cache hit (preprocessed)' 5
231 checkstat 'cache miss' 3
233 testname="CCACHE_NOSTATS"
234 CCACHE_NOSTATS=1 $CCACHE_COMPILE -c test1.c -O -O
235 checkstat 'cache hit (preprocessed)' 5
236 checkstat 'cache miss' 3
238 testname="CCACHE_RECACHE"
239 CCACHE_RECACHE=1 $CCACHE_COMPILE -c test1.c -O -O
240 checkstat 'cache hit (preprocessed)' 5
241 checkstat 'cache miss' 4
243 # strictly speaking should be 3 - RECACHE causes a double counting!
244 checkstat 'files in cache' 4
245 $CCACHE -c > /dev/null
246 checkstat 'files in cache' 3
248 testname="CCACHE_HASHDIR"
249 CCACHE_HASHDIR=1 $CCACHE_COMPILE -c test1.c -O -O
250 checkstat 'cache hit (preprocessed)' 5
251 checkstat 'cache miss' 5
253 CCACHE_HASHDIR=1 $CCACHE_COMPILE -c test1.c -O -O
254 checkstat 'cache hit (preprocessed)' 6
255 checkstat 'cache miss' 5
256 checkstat 'files in cache' 4
259 echo '/* a silly comment */' > test1-comment.c
260 cat test1.c >> test1-comment.c
261 $CCACHE_COMPILE -c test1-comment.c
263 checkstat 'cache hit (preprocessed)' 6
264 checkstat 'cache miss' 6
266 testname="CCACHE_UNIFY"
267 CCACHE_UNIFY=1 $CCACHE_COMPILE -c test1.c
268 checkstat 'cache hit (preprocessed)' 6
269 checkstat 'cache miss' 7
270 mv test1.c test1-saved.c
271 echo '/* another comment */' > test1.c
272 cat test1-saved.c >> test1.c
273 CCACHE_UNIFY=1 $CCACHE_COMPILE -c test1.c
274 mv test1-saved.c test1.c
275 checkstat 'cache hit (preprocessed)' 7
276 checkstat 'cache miss' 7
278 testname="cache-size"
280 $CCACHE_COMPILE -c $f
282 checkstat 'cache hit (preprocessed)' 8
283 checkstat 'cache miss' 37
284 checkstat 'files in cache' 36
286 $CCACHE -C >/dev/null
289 $CCACHE_COMPILE -c test1.c -E > test1.i
290 checkstat 'cache hit (preprocessed)' 8
291 checkstat 'cache miss' 37
293 testname="direct .i compile"
294 $CCACHE_COMPILE -c test1.c
295 checkstat 'cache hit (preprocessed)' 8
296 checkstat 'cache miss' 38
298 $CCACHE_COMPILE -c test1.i
299 checkstat 'cache hit (preprocessed)' 9
300 checkstat 'cache miss' 38
302 $CCACHE_COMPILE -c test1.i
303 checkstat 'cache hit (preprocessed)' 10
304 checkstat 'cache miss' 38
307 $CCACHE_COMPILE -x c -c test1.ccc
308 checkstat 'cache hit (preprocessed)' 10
309 checkstat 'cache miss' 39
310 $CCACHE_COMPILE -x c -c test1.ccc
311 checkstat 'cache hit (preprocessed)' 11
312 checkstat 'cache miss' 39
315 $CCACHE_COMPILE -xc -c test1.ccc
316 checkstat 'cache hit (preprocessed)' 12
317 checkstat 'cache miss' 39
320 $CCACHE_COMPILE -x assembler -x none -c test1.c
321 checkstat 'cache hit (preprocessed)' 13
322 checkstat 'cache miss' 39
324 testname="-x unknown"
325 $CCACHE_COMPILE -x unknown -c test1.c 2>/dev/null
326 checkstat 'cache hit (preprocessed)' 13
327 checkstat 'cache miss' 39
328 checkstat 'unsupported source language' 2
330 testname="-D not hashed"
331 $CCACHE_COMPILE -DNOT_AFFECTING=1 -c test1.c 2>/dev/null
332 checkstat 'cache hit (preprocessed)' 14
333 checkstat 'cache miss' 39
335 if [ -x /usr/bin/printf ]; then
336 /usr/bin/printf '#include <wchar.h>\nwchar_t foo[] = L"\xbf";\n' >latin1.c
337 if CCACHE_DISABLE=1 $COMPILER -c -finput-charset=latin1 latin1.c >/dev/null 2>&1; then
338 testname="-finput-charset"
339 CCACHE_CPP2=1 $CCACHE_COMPILE -c -finput-charset=latin1 latin1.c
340 checkstat 'cache hit (preprocessed)' 14
341 checkstat 'cache miss' 40
342 $CCACHE_COMPILE -c -finput-charset=latin1 latin1.c
343 checkstat 'cache hit (preprocessed)' 15
344 checkstat 'cache miss' 40
348 testname="compilercheck=mtime"
349 $CCACHE -Cz >/dev/null
350 cat >compiler.sh <<EOF
352 CCACHE_DISABLE=1 # If $COMPILER happens to be a ccache symlink...
353 export CCACHE_DISABLE
359 CCACHE_COMPILERCHECK=mtime $CCACHE ./compiler.sh -c test1.c
360 checkstat 'cache hit (preprocessed)' 0
361 checkstat 'cache miss' 1
362 sed_in_place 's/comment/yoghurt/' compiler.sh # Don't change the size
365 CCACHE_COMPILERCHECK=mtime $CCACHE ./compiler.sh -c test1.c
366 checkstat 'cache hit (preprocessed)' 1
367 checkstat 'cache miss' 1
369 CCACHE_COMPILERCHECK=mtime $CCACHE ./compiler.sh -c test1.c
370 checkstat 'cache hit (preprocessed)' 1
371 checkstat 'cache miss' 2
373 testname="compilercheck=content"
374 $CCACHE -z >/dev/null
375 CCACHE_COMPILERCHECK=content $CCACHE ./compiler.sh -c test1.c
376 checkstat 'cache hit (preprocessed)' 0
377 checkstat 'cache miss' 1
379 CCACHE_COMPILERCHECK=content $CCACHE ./compiler.sh -c test1.c
380 checkstat 'cache hit (preprocessed)' 1
381 checkstat 'cache miss' 1
382 echo "# Compiler upgrade" >>compiler.sh
384 CCACHE_COMPILERCHECK=content $CCACHE ./compiler.sh -c test1.c
385 checkstat 'cache hit (preprocessed)' 1
386 checkstat 'cache miss' 2
388 testname="compilercheck=none"
389 $CCACHE -z >/dev/null
391 CCACHE_COMPILERCHECK=none $CCACHE ./compiler.sh -c test1.c
392 checkstat 'cache hit (preprocessed)' 0
393 checkstat 'cache miss' 1
394 CCACHE_COMPILERCHECK=none $CCACHE ./compiler.sh -c test1.c
395 checkstat 'cache hit (preprocessed)' 1
396 checkstat 'cache miss' 1
397 echo "# Compiler upgrade" >>compiler.sh
398 CCACHE_COMPILERCHECK=none $CCACHE ./compiler.sh -c test1.c
399 checkstat 'cache hit (preprocessed)' 2
400 checkstat 'cache miss' 1
402 testname="compilercheck=command"
403 $CCACHE -z >/dev/null
405 CCACHE_COMPILERCHECK='echo %compiler%' $CCACHE ./compiler.sh -c test1.c
406 checkstat 'cache hit (preprocessed)' 0
407 checkstat 'cache miss' 1
408 echo "# Compiler upgrade" >>compiler.sh
409 CCACHE_COMPILERCHECK="echo ./compiler.sh" $CCACHE ./compiler.sh -c test1.c
410 checkstat 'cache hit (preprocessed)' 1
411 checkstat 'cache miss' 1
418 CCACHE_COMPILERCHECK='./foobar.sh' $CCACHE ./compiler.sh -c test1.c
419 checkstat 'cache hit (preprocessed)' 1
420 checkstat 'cache miss' 2
421 CCACHE_COMPILERCHECK='echo foo; echo bar' $CCACHE ./compiler.sh -c test1.c
422 checkstat 'cache hit (preprocessed)' 2
423 checkstat 'cache miss' 2
425 testname="compilercheck=unknown_command"
426 $CCACHE -z >/dev/null
428 CCACHE_COMPILERCHECK="unknown_command" $CCACHE ./compiler.sh -c test1.c 2>/dev/null
429 if [ "$?" -eq 0 ]; then
430 test_failed "Expected failure running unknown_command to verify compiler but was success"
432 checkstat 'compiler check failed' 1
434 testname="no object file"
435 cat <<'EOF' >test_no_obj.c
438 cat <<'EOF' >prefix-remove.sh
441 [ x$3 = x-o ] && rm $4
443 chmod +x prefix-remove.sh
444 CCACHE_PREFIX=`pwd`/prefix-remove.sh $CCACHE_COMPILE -c test_no_obj.c
445 checkstat 'compiler produced no output' 1
447 testname="empty object file"
448 cat <<'EOF' >test_empty_obj.c
451 cat <<'EOF' >prefix-empty.sh
454 [ x$3 = x-o ] && cp /dev/null $4
456 chmod +x prefix-empty.sh
457 CCACHE_PREFIX=`pwd`/prefix-empty.sh $CCACHE_COMPILE -c test_empty_obj.c
458 checkstat 'compiler produced empty output' 1
460 testname="stderr-files"
461 $CCACHE -Cz >/dev/null
462 num=`find $CCACHE_DIR -name '*.stderr' | wc -l`
463 if [ $num -ne 0 ]; then
464 test_failed "$num stderr files found, expected 0"
469 /* Trigger warning by having no return statement. */
472 checkstat 'files in cache' 0
473 $CCACHE_COMPILE -Wall -W -c stderr.c 2>/dev/null
474 num=`find $CCACHE_DIR -name '*.stderr' | wc -l`
475 if [ $num -ne 1 ]; then
476 test_failed "$num stderr files found, expected 1"
478 checkstat 'files in cache' 2
480 testname="zero-stats"
481 $CCACHE -z > /dev/null
482 checkstat 'cache hit (preprocessed)' 0
483 checkstat 'cache miss' 0
484 checkstat 'files in cache' 2
487 $CCACHE -C > /dev/null
488 checkstat 'files in cache' 0
494 CCACHE_COMPILE="$CCACHE $COMPILER"
499 if [ `dirname $COMPILER` = . ]; then
500 ln -s ../ccache $COMPILER
501 CCACHE_COMPILE="./$COMPILER"
504 echo "Compiler ($COMPILER) not taken from PATH -- not running link test"
509 CCACHE_COMPILE="$CCACHE $COMPILER"
511 export CCACHE_HARDLINK
513 export CCACHE_NOCOMPRESS
515 unset CCACHE_HARDLINK
516 unset CCACHE_NOCOMPRESS
520 CCACHE_COMPILE="$CCACHE $COMPILER"
528 CCACHE_COMPILE="$CCACHE $COMPILER"
530 export CCACHE_NLEVELS
536 CCACHE_COMPILE="$CCACHE $COMPILER"
538 export CCACHE_NLEVELS
544 unset CCACHE_NODIRECT
546 ##################################################################
547 # Create some code to compile.
563 backdate test1.h test2.h test3.h
565 ##################################################################
566 # First compilation is a miss.
567 testname="first compilation"
568 $CCACHE -z >/dev/null
569 $CCACHE $COMPILER -c test.c
570 checkstat 'cache hit (direct)' 0
571 checkstat 'cache hit (preprocessed)' 0
572 checkstat 'cache miss' 1
574 ##################################################################
575 # Another compilation should now generate a direct hit.
576 testname="direct hit"
577 $CCACHE -z >/dev/null
578 $CCACHE $COMPILER -c test.c
579 checkstat 'cache hit (direct)' 1
580 checkstat 'cache hit (preprocessed)' 0
581 checkstat 'cache miss' 0
583 ##################################################################
584 # Check that corrupt manifest files are handled and rewritten.
585 testname="corrupt manifest file"
586 $CCACHE -z >/dev/null
587 manifest_file=`find $CCACHE_DIR -name '*.manifest'`
590 $CCACHE $COMPILER -c test.c
591 checkstat 'cache hit (direct)' 0
592 checkstat 'cache hit (preprocessed)' 1
593 checkstat 'cache miss' 0
594 $CCACHE $COMPILER -c test.c
595 checkstat 'cache hit (direct)' 1
596 checkstat 'cache hit (preprocessed)' 1
597 checkstat 'cache miss' 0
599 ##################################################################
600 # Compiling with CCACHE_NODIRECT set should generate a preprocessed hit.
601 testname="preprocessed hit"
602 $CCACHE -z >/dev/null
603 CCACHE_NODIRECT=1 $CCACHE $COMPILER -c test.c
604 checkstat 'cache hit (direct)' 0
605 checkstat 'cache hit (preprocessed)' 1
606 checkstat 'cache miss' 0
608 ##################################################################
609 # Test compilation of a modified include file.
610 testname="modified include file"
611 $CCACHE -z >/dev/null
612 echo "int test3_2;" >>test3.h
614 $CCACHE $COMPILER -c test.c
615 checkstat 'cache hit (direct)' 0
616 checkstat 'cache hit (preprocessed)' 0
617 checkstat 'cache miss' 1
619 $CCACHE $COMPILER -c test.c
620 checkstat 'cache hit (direct)' 1
621 checkstat 'cache hit (preprocessed)' 0
622 checkstat 'cache miss' 1
624 ##################################################################
625 # A removed but previously compiled header file should be handled
627 testname="missing header file"
628 $CCACHE -z >/dev/null
630 mv test1.h test1.h.saved
631 mv test3.h test3.h.saved
633 /* No more include of test3.h */
638 $CCACHE $COMPILER -c test.c
639 checkstat 'cache hit (direct)' 0
640 checkstat 'cache hit (preprocessed)' 0
641 checkstat 'cache miss' 1
643 $CCACHE $COMPILER -c test.c
644 checkstat 'cache hit (direct)' 1
645 checkstat 'cache hit (preprocessed)' 0
646 checkstat 'cache miss' 1
649 mv test1.h.saved test1.h
650 mv test3.h.saved test3.h
654 ##################################################################
655 # Check calculation of dependency file names.
656 $CCACHE -Cz >/dev/null
657 checkstat 'files in cache' 0
659 for ext in .obj "" . .foo.bar; do
660 testname="dependency file calculation from object file 'test$ext'"
661 dep_file=test.dir/`echo test$ext | sed 's/\.[^.]*\$//'`.d
662 $CCACHE $COMPILER -MD -c test.c -o test.dir/test$ext
664 $CCACHE $COMPILER -MD -c test.c -o test.dir/test$ext
665 if [ ! -f $dep_file ]; then
666 test_failed "$dep_file missing"
670 checkstat 'files in cache' 12
672 ##################################################################
673 # Check that -Wp,-MD,file.d works.
675 $CCACHE -z >/dev/null
676 $CCACHE $COMPILER -c -Wp,-MD,other.d test.c
677 checkstat 'cache hit (direct)' 0
678 checkstat 'cache hit (preprocessed)' 0
679 checkstat 'cache miss' 1
680 checkfile other.d "test.o: test.c test1.h test3.h test2.h"
684 $CCACHE $COMPILER -c -Wp,-MD,other.d test.c
685 checkstat 'cache hit (direct)' 1
686 checkstat 'cache hit (preprocessed)' 0
687 checkstat 'cache miss' 1
688 checkfile other.d "test.o: test.c test1.h test3.h test2.h"
692 ##################################################################
693 # Check that -Wp,-MMD,file.d works.
695 $CCACHE -C >/dev/null
696 $CCACHE -z >/dev/null
697 $CCACHE $COMPILER -c -Wp,-MMD,other.d test.c
698 checkstat 'cache hit (direct)' 0
699 checkstat 'cache hit (preprocessed)' 0
700 checkstat 'cache miss' 1
701 checkfile other.d "test.o: test.c test1.h test3.h test2.h"
705 $CCACHE $COMPILER -c -Wp,-MMD,other.d test.c
706 checkstat 'cache hit (direct)' 1
707 checkstat 'cache hit (preprocessed)' 0
708 checkstat 'cache miss' 1
709 checkfile other.d "test.o: test.c test1.h test3.h test2.h"
713 ##################################################################
714 # Check that -Wp,-MD,file.d,-P disables direct mode.
715 testname="-Wp,-MD,file.d,-P"
716 $CCACHE -z >/dev/null
717 $CCACHE $COMPILER -c -Wp,-MD,$DEVNULL,-P test.c
718 checkstat 'cache hit (direct)' 0
719 checkstat 'cache hit (preprocessed)' 0
720 checkstat 'cache miss' 1
722 $CCACHE $COMPILER -c -Wp,-MD,$DEVNULL,-P test.c
723 checkstat 'cache hit (direct)' 0
724 checkstat 'cache hit (preprocessed)' 1
725 checkstat 'cache miss' 1
727 ##################################################################
728 # Check that -Wp,-MMD,file.d,-P disables direct mode.
729 testname="-Wp,-MDD,file.d,-P"
730 $CCACHE -z >/dev/null
731 $CCACHE $COMPILER -c -Wp,-MMD,$DEVNULL,-P test.c
732 checkstat 'cache hit (direct)' 0
733 checkstat 'cache hit (preprocessed)' 0
734 checkstat 'cache miss' 1
736 $CCACHE $COMPILER -c -Wp,-MMD,$DEVNULL,-P test.c
737 checkstat 'cache hit (direct)' 0
738 checkstat 'cache hit (preprocessed)' 1
739 checkstat 'cache miss' 1
741 ##################################################################
742 # Test some header modifications to get multiple objects in the manifest.
743 testname="several objects"
744 $CCACHE -z >/dev/null
745 for i in 0 1 2 3 4; do
746 echo "int test1_$i;" >>test1.h
748 $CCACHE $COMPILER -c test.c
749 $CCACHE $COMPILER -c test.c
751 checkstat 'cache hit (direct)' 5
752 checkstat 'cache hit (preprocessed)' 0
753 checkstat 'cache miss' 5
755 ##################################################################
756 # Check that -MD works.
758 $CCACHE -z >/dev/null
759 $CCACHE $COMPILER -c -MD test.c
760 checkstat 'cache hit (direct)' 0
761 checkstat 'cache hit (preprocessed)' 0
762 checkstat 'cache miss' 1
763 checkfile test.d "test.o: test.c test1.h test3.h test2.h"
767 $CCACHE $COMPILER -c -MD test.c
768 checkstat 'cache hit (direct)' 1
769 checkstat 'cache hit (preprocessed)' 0
770 checkstat 'cache miss' 1
771 checkfile test.d "test.o: test.c test1.h test3.h test2.h"
773 ##################################################################
774 # Check the scenario of running a ccache with direct mode on a cache
775 # built up by a ccache without direct mode support.
776 testname="direct mode on old cache"
777 $CCACHE -z >/dev/null
778 $CCACHE -C >/dev/null
779 CCACHE_NODIRECT=1 $CCACHE $COMPILER -c -MD test.c
780 checkstat 'cache hit (direct)' 0
781 checkstat 'cache hit (preprocessed)' 0
782 checkstat 'cache miss' 1
783 checkfile test.d "test.o: test.c test1.h test3.h test2.h"
787 CCACHE_NODIRECT=1 $CCACHE $COMPILER -c -MD test.c
788 checkstat 'cache hit (direct)' 0
789 checkstat 'cache hit (preprocessed)' 1
790 checkstat 'cache miss' 1
791 checkfile test.d "test.o: test.c test1.h test3.h test2.h"
795 $CCACHE $COMPILER -c -MD test.c
796 checkstat 'cache hit (direct)' 0
797 checkstat 'cache hit (preprocessed)' 2
798 checkstat 'cache miss' 1
799 checkfile test.d "test.o: test.c test1.h test3.h test2.h"
803 $CCACHE $COMPILER -c -MD test.c
804 checkstat 'cache hit (direct)' 1
805 checkstat 'cache hit (preprocessed)' 2
806 checkstat 'cache miss' 1
807 checkfile test.d "test.o: test.c test1.h test3.h test2.h"
809 ##################################################################
810 # Check that -MF works.
812 $CCACHE -C >/dev/null
813 $CCACHE -z >/dev/null
814 $CCACHE $COMPILER -c -MD -MF other.d test.c
815 checkstat 'cache hit (direct)' 0
816 checkstat 'cache hit (preprocessed)' 0
817 checkstat 'cache miss' 1
818 checkfile other.d "test.o: test.c test1.h test3.h test2.h"
822 $CCACHE $COMPILER -c -MD -MF other.d test.c
823 checkstat 'cache hit (direct)' 1
824 checkstat 'cache hit (preprocessed)' 0
825 checkstat 'cache miss' 1
826 checkfile other.d "test.o: test.c test1.h test3.h test2.h"
828 ##################################################################
829 # Check that a missing .d file in the cache is handled correctly.
830 testname="missing dependency file"
831 $CCACHE -z >/dev/null
832 $CCACHE -C >/dev/null
834 $CCACHE $COMPILER -c -MD test.c
835 checkstat 'cache hit (direct)' 0
836 checkstat 'cache hit (preprocessed)' 0
837 checkstat 'cache miss' 1
838 checkfile other.d "test.o: test.c test1.h test3.h test2.h"
840 $CCACHE $COMPILER -c -MD test.c
841 checkstat 'cache hit (direct)' 1
842 checkstat 'cache hit (preprocessed)' 0
843 checkstat 'cache miss' 1
844 checkfile other.d "test.o: test.c test1.h test3.h test2.h"
846 find $CCACHE_DIR -name '*.d' -exec rm -f '{}' \;
848 $CCACHE $COMPILER -c -MD test.c
849 checkstat 'cache hit (direct)' 1
850 checkstat 'cache hit (preprocessed)' 1
851 checkstat 'cache miss' 1
852 checkfile other.d "test.o: test.c test1.h test3.h test2.h"
854 ##################################################################
855 # Check that stderr from both the preprocessor and the compiler is emitted
856 # in direct mode too.
857 testname="cpp stderr"
858 $CCACHE -z >/dev/null
859 $CCACHE -C >/dev/null
860 cat <<EOF >cpp-warning.c
862 /* Trigger preprocessor warning about extra token after #endif. */
866 /* Trigger compiler warning by having no return statement. */
869 $CCACHE $COMPILER -Wall -W -c cpp-warning.c 2>stderr-orig.txt
870 checkstat 'cache hit (direct)' 0
871 checkstat 'cache hit (preprocessed)' 0
872 checkstat 'cache miss' 1
875 export CCACHE_NODIRECT
876 $CCACHE $COMPILER -Wall -W -c cpp-warning.c 2>stderr-cpp.txt
877 unset CCACHE_NODIRECT
878 checkstat 'cache hit (direct)' 0
879 checkstat 'cache hit (preprocessed)' 1
880 checkstat 'cache miss' 1
881 checkfile stderr-cpp.txt "`cat stderr-orig.txt`"
883 $CCACHE $COMPILER -Wall -W -c cpp-warning.c 2>stderr-mf.txt
884 checkstat 'cache hit (direct)' 1
885 checkstat 'cache hit (preprocessed)' 1
886 checkstat 'cache miss' 1
887 checkfile stderr-mf.txt "`cat stderr-orig.txt`"
889 ##################################################################
890 # Check that changes in comments are ignored when hashing.
891 testname="changes in comments"
892 $CCACHE -C >/dev/null
893 $CCACHE -z >/dev/null
894 cat <<EOF >comments.h
900 cat <<'EOF' >comments.c
901 #include "comments.h"
903 /* apple */ // banana"; // foo comment
906 $CCACHE $COMPILER -c comments.c
907 checkstat 'cache hit (direct)' 0
908 checkstat 'cache hit (preprocessed)' 0
909 checkstat 'cache miss' 1
911 sed_in_place 's/foo/ignored/' comments.h comments.c
914 $CCACHE $COMPILER -c comments.c
915 checkstat 'cache hit (direct)' 1
916 checkstat 'cache hit (preprocessed)' 0
917 checkstat 'cache miss' 1
919 # Check that comment-like string contents are hashed.
920 sed_in_place 's/apple/orange/' comments.c
923 $CCACHE $COMPILER -c comments.c
924 checkstat 'cache hit (direct)' 1
925 checkstat 'cache hit (preprocessed)' 0
926 checkstat 'cache miss' 2
928 ##################################################################
929 # Check that it's possible to compile and cache an empty source code file.
930 testname="empty source file"
931 $CCACHE -Cz >/dev/null
933 $CCACHE $COMPILER -c empty.c
934 checkstat 'cache hit (direct)' 0
935 checkstat 'cache hit (preprocessed)' 0
936 checkstat 'cache miss' 1
937 $CCACHE $COMPILER -c empty.c
938 checkstat 'cache hit (direct)' 1
939 checkstat 'cache hit (preprocessed)' 0
940 checkstat 'cache miss' 1
942 ##################################################################
943 # Check that empty include files are handled as well.
944 testname="empty include file"
945 $CCACHE -Cz >/dev/null
947 cat <<EOF >include_empty.c
951 $CCACHE $COMPILER -c include_empty.c
952 checkstat 'cache hit (direct)' 0
953 checkstat 'cache hit (preprocessed)' 0
954 checkstat 'cache miss' 1
955 $CCACHE $COMPILER -c include_empty.c
956 checkstat 'cache hit (direct)' 1
957 checkstat 'cache hit (preprocessed)' 0
958 checkstat 'cache miss' 1
960 ##################################################################
961 # Check that direct mode correctly detects file name/path changes.
962 testname="__FILE__ in source file"
963 $CCACHE -Cz >/dev/null
965 #define file __FILE__
968 $CCACHE $COMPILER -c file.c
969 checkstat 'cache hit (direct)' 0
970 checkstat 'cache hit (preprocessed)' 0
971 checkstat 'cache miss' 1
972 $CCACHE $COMPILER -c file.c
973 checkstat 'cache hit (direct)' 1
974 checkstat 'cache hit (preprocessed)' 0
975 checkstat 'cache miss' 1
976 $CCACHE $COMPILER -c `pwd`/file.c
977 checkstat 'cache hit (direct)' 1
978 checkstat 'cache hit (preprocessed)' 0
979 checkstat 'cache miss' 2
981 testname="__FILE__ in include file"
982 $CCACHE -Cz >/dev/null
984 #define file __FILE__
991 $CCACHE $COMPILER -c file_h.c
992 checkstat 'cache hit (direct)' 0
993 checkstat 'cache hit (preprocessed)' 0
994 checkstat 'cache miss' 1
995 $CCACHE $COMPILER -c file_h.c
996 checkstat 'cache hit (direct)' 1
997 checkstat 'cache hit (preprocessed)' 0
998 checkstat 'cache miss' 1
999 mv file_h.c file2_h.c
1000 $CCACHE $COMPILER -c `pwd`/file2_h.c
1001 checkstat 'cache hit (direct)' 1
1002 checkstat 'cache hit (preprocessed)' 0
1003 checkstat 'cache miss' 2
1005 ##################################################################
1006 # Check that direct mode ignores __FILE__ if sloppiness is specified.
1007 testname="__FILE__ in source file, sloppy"
1008 $CCACHE -Cz >/dev/null
1010 #define file __FILE__
1013 CCACHE_SLOPPINESS=file_macro $CCACHE $COMPILER -c file.c
1014 checkstat 'cache hit (direct)' 0
1015 checkstat 'cache hit (preprocessed)' 0
1016 checkstat 'cache miss' 1
1017 CCACHE_SLOPPINESS=file_macro $CCACHE $COMPILER -c file.c
1018 checkstat 'cache hit (direct)' 1
1019 checkstat 'cache hit (preprocessed)' 0
1020 checkstat 'cache miss' 1
1021 CCACHE_SLOPPINESS=file_macro $CCACHE $COMPILER -c `pwd`/file.c
1022 checkstat 'cache hit (direct)' 2
1023 checkstat 'cache hit (preprocessed)' 0
1024 checkstat 'cache miss' 1
1026 testname="__FILE__ in include file, sloppy"
1027 $CCACHE -Cz >/dev/null
1029 #define file __FILE__
1036 CCACHE_SLOPPINESS=file_macro $CCACHE $COMPILER -c file_h.c
1037 checkstat 'cache hit (direct)' 0
1038 checkstat 'cache hit (preprocessed)' 0
1039 checkstat 'cache miss' 1
1040 CCACHE_SLOPPINESS=file_macro $CCACHE $COMPILER -c file_h.c
1041 checkstat 'cache hit (direct)' 1
1042 checkstat 'cache hit (preprocessed)' 0
1043 checkstat 'cache miss' 1
1044 mv file_h.c file2_h.c
1045 CCACHE_SLOPPINESS=file_macro $CCACHE $COMPILER -c `pwd`/file2_h.c
1046 checkstat 'cache hit (direct)' 2
1047 checkstat 'cache hit (preprocessed)' 0
1048 checkstat 'cache miss' 1
1050 ##################################################################
1051 # Check that we never get direct hits when __TIME__ is used.
1052 testname="__TIME__ in source file"
1053 $CCACHE -Cz >/dev/null
1055 #define time __TIME__
1058 $CCACHE $COMPILER -c time.c
1059 checkstat 'cache hit (direct)' 0
1060 checkstat 'cache hit (preprocessed)' 0
1061 checkstat 'cache miss' 1
1062 $CCACHE $COMPILER -c time.c
1063 checkstat 'cache hit (direct)' 0
1064 checkstat 'cache hit (preprocessed)' 1
1065 checkstat 'cache miss' 1
1067 testname="__TIME__ in include time"
1068 $CCACHE -Cz >/dev/null
1070 #define time __TIME__
1077 $CCACHE $COMPILER -c time_h.c
1078 checkstat 'cache hit (direct)' 0
1079 checkstat 'cache hit (preprocessed)' 0
1080 checkstat 'cache miss' 1
1081 $CCACHE $COMPILER -c time_h.c
1082 checkstat 'cache hit (direct)' 0
1083 checkstat 'cache hit (preprocessed)' 1
1084 checkstat 'cache miss' 1
1086 ##################################################################
1087 # Check that direct mode ignores __TIME__ when sloppiness is specified.
1088 testname="__TIME__ in source file, sloppy"
1089 $CCACHE -Cz >/dev/null
1091 #define time __TIME__
1094 CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER -c time.c
1095 checkstat 'cache hit (direct)' 0
1096 checkstat 'cache hit (preprocessed)' 0
1097 checkstat 'cache miss' 1
1098 CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER -c time.c
1099 checkstat 'cache hit (direct)' 1
1100 checkstat 'cache hit (preprocessed)' 0
1101 checkstat 'cache miss' 1
1103 testname="__TIME__ in include time, sloppy"
1104 $CCACHE -Cz >/dev/null
1106 #define time __TIME__
1113 CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER -c time_h.c
1114 checkstat 'cache hit (direct)' 0
1115 checkstat 'cache hit (preprocessed)' 0
1116 checkstat 'cache miss' 1
1117 CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER -c time_h.c
1118 checkstat 'cache hit (direct)' 1
1119 checkstat 'cache hit (preprocessed)' 0
1120 checkstat 'cache miss' 1
1122 ##################################################################
1123 # Check that a too new include file turns off direct mode.
1124 testname="too new include file"
1125 $CCACHE -Cz >/dev/null
1132 touch -t 203801010000 new.h
1133 $CCACHE $COMPILER -c new.c
1134 checkstat 'cache hit (direct)' 0
1135 checkstat 'cache hit (preprocessed)' 0
1136 checkstat 'cache miss' 1
1137 $CCACHE $COMPILER -c new.c
1138 checkstat 'cache hit (direct)' 0
1139 checkstat 'cache hit (preprocessed)' 1
1140 checkstat 'cache miss' 1
1142 ##################################################################
1143 # Check that include file mtime is ignored when sloppiness is specified.
1144 testname="too new include file, sloppy"
1145 $CCACHE -Cz >/dev/null
1152 touch -t 203801010000 new.h
1153 CCACHE_SLOPPINESS=include_file_mtime $CCACHE $COMPILER -c new.c
1154 checkstat 'cache hit (direct)' 0
1155 checkstat 'cache hit (preprocessed)' 0
1156 checkstat 'cache miss' 1
1157 CCACHE_SLOPPINESS=include_file_mtime $CCACHE $COMPILER -c new.c
1158 checkstat 'cache hit (direct)' 1
1159 checkstat 'cache hit (preprocessed)' 0
1160 checkstat 'cache miss' 1
1164 ##################################################################
1165 # Create some code to compile.
1166 mkdir -p dir1/src dir1/include
1167 cat <<EOF >dir1/src/test.c
1170 cat <<EOF >dir1/include/test.h
1174 backdate dir1/include/test.h dir2/include/test.h
1179 /* Trigger warning by having no return statement. */
1187 ##################################################################
1188 # CCACHE_BASEDIR="" and using absolute include path will result in a cache
1190 testname="empty CCACHE_BASEDIR"
1191 $CCACHE -z >/dev/null
1194 CCACHE_BASEDIR="" $CCACHE $COMPILER -I`pwd`/include -c src/test.c
1195 checkstat 'cache hit (direct)' 0
1196 checkstat 'cache hit (preprocessed)' 0
1197 checkstat 'cache miss' 1
1201 CCACHE_BASEDIR="" $CCACHE $COMPILER -I`pwd`/include -c src/test.c
1202 checkstat 'cache hit (direct)' 0
1203 checkstat 'cache hit (preprocessed)' 0
1204 checkstat 'cache miss' 2
1207 ##################################################################
1208 # Setting CCACHE_BASEDIR will result in a cache hit because include paths
1209 # in the preprocessed output are rewritten.
1210 testname="set CCACHE_BASEDIR"
1211 $CCACHE -z >/dev/null
1212 $CCACHE -C >/dev/null
1215 CCACHE_BASEDIR="`pwd`" $CCACHE $COMPILER -I`pwd`/include -c src/test.c
1216 checkstat 'cache hit (direct)' 0
1217 checkstat 'cache hit (preprocessed)' 0
1218 checkstat 'cache miss' 1
1222 # The space after -I is there to test an extra code path.
1223 CCACHE_BASEDIR="`pwd`" $CCACHE $COMPILER -I `pwd`/include -c src/test.c
1224 checkstat 'cache hit (direct)' 0
1225 checkstat 'cache hit (preprocessed)' 1
1226 checkstat 'cache miss' 1
1229 ##################################################################
1230 # Setting CCACHE_BASEDIR will result in a cache hit because -I arguments
1231 # are rewritten, as are the paths stored in the manifest.
1232 testname="set CCACHE_BASEDIR, direct lookup"
1233 $CCACHE -z >/dev/null
1234 $CCACHE -C >/dev/null
1235 unset CCACHE_NODIRECT
1238 CCACHE_BASEDIR="`pwd`" $CCACHE $COMPILER -I`pwd`/include -c src/test.c
1239 checkstat 'cache hit (direct)' 0
1240 checkstat 'cache hit (preprocessed)' 0
1241 checkstat 'cache miss' 1
1245 CCACHE_BASEDIR="`pwd`" $CCACHE $COMPILER -I`pwd`/include -c src/test.c
1246 checkstat 'cache hit (direct)' 1
1247 checkstat 'cache hit (preprocessed)' 0
1248 checkstat 'cache miss' 1
1251 ##################################################################
1252 # CCACHE_BASEDIR="" is the default.
1253 testname="default CCACHE_BASEDIR"
1255 $CCACHE -z >/dev/null
1256 $CCACHE $COMPILER -I`pwd`/include -c src/test.c
1257 checkstat 'cache hit (direct)' 0
1258 checkstat 'cache hit (preprocessed)' 0
1259 checkstat 'cache miss' 1
1262 ##################################################################
1263 # Rewriting triggered by CCACHE_BASEDIR should handle paths with multiple
1264 # slashes correctly.
1265 testname="path normalization"
1267 $CCACHE -z >/dev/null
1268 CCACHE_BASEDIR=`pwd` $CCACHE $COMPILER -I`pwd`//include -c `pwd`//src/test.c
1269 checkstat 'cache hit (direct)' 1
1270 checkstat 'cache hit (preprocessed)' 0
1271 checkstat 'cache miss' 0
1274 ##################################################################
1275 # Check that rewriting triggered by CCACHE_BASEDIR also affects stderr.
1277 $CCACHE -z >/dev/null
1278 CCACHE_BASEDIR=`pwd` $CCACHE $COMPILER -Wall -W -I`pwd` -c `pwd`/stderr.c -o `pwd`/stderr.o 2>stderr.txt
1279 checkstat 'cache hit (direct)' 0
1280 checkstat 'cache hit (preprocessed)' 0
1281 checkstat 'cache miss' 1
1282 if grep `pwd` stderr.txt >/dev/null 2>&1; then
1283 test_failed "Base dir (`pwd`) found in stderr:\n`cat stderr.txt`"
1286 CCACHE_BASEDIR=`pwd` $CCACHE $COMPILER -Wall -W -I`pwd` -c `pwd`/stderr.c -o `pwd`/stderr.o 2>stderr.txt
1287 checkstat 'cache hit (direct)' 1
1288 checkstat 'cache hit (preprocessed)' 0
1289 checkstat 'cache miss' 1
1290 if grep `pwd` stderr.txt >/dev/null 2>&1; then
1291 test_failed "Base dir (`pwd`) found in stderr:\n`cat stderr.txt`"
1295 compression_suite() {
1296 ##################################################################
1297 # Create some code to compile.
1302 ##################################################################
1303 # Check that compressed and uncompressed files get the same hash sum.
1304 testname="compression hash sum"
1305 CCACHE_COMPRESS=1 $CCACHE $COMPILER -c test.c
1306 checkstat 'cache hit (direct)' 0
1307 checkstat 'cache hit (preprocessed)' 0
1308 checkstat 'cache miss' 1
1310 CCACHE_COMPRESS=1 $CCACHE $COMPILER -c test.c
1311 checkstat 'cache hit (direct)' 0
1312 checkstat 'cache hit (preprocessed)' 1
1313 checkstat 'cache miss' 1
1315 $CCACHE $COMPILER -c test.c
1316 checkstat 'cache hit (direct)' 0
1317 checkstat 'cache hit (preprocessed)' 2
1318 checkstat 'cache miss' 1
1322 ##################################################################
1323 # Create some code to compile.
1324 echo "int test;" >test.c
1325 echo "int test2;" >test2.c
1327 # Cache a compilation.
1328 $CCACHE $COMPILER -c test.c -o test.o
1329 checkstat 'cache hit (preprocessed)' 0
1330 checkstat 'cache miss' 1
1332 # Make the cache readonly
1333 # Check that readonly mode finds the result.
1334 testname="cache hit"
1336 chmod -R a-w $CCACHE_DIR
1337 CCACHE_READONLY=1 CCACHE_TEMPDIR=/tmp CCACHE_PREFIX=false $CCACHE $COMPILER -c test.c -o test.o
1339 chmod -R a+w $CCACHE_DIR
1340 if [ $status -ne 0 ]; then
1341 test_failed "failure when compiling test.c readonly"
1343 if [ ! -f test.o ]; then
1344 test_failed "test.o missing"
1347 # Check that readonly mode doesn't try to store new results.
1348 testname="cache miss"
1349 files_before=`find $CCACHE_DIR -type f | wc -l`
1350 CCACHE_READONLY=1 CCACHE_TEMPDIR=/tmp $CCACHE $COMPILER -c test2.c -o test2.o
1351 if [ $? -ne 0 ]; then
1352 test_failed "failure when compiling test2.c readonly"
1354 if [ ! -f test2.o ]; then
1355 test_failed "test2.o missing"
1357 files_after=`find $CCACHE_DIR -type f | wc -l`
1358 if [ $files_before -ne $files_after ]; then
1359 test_failed "readonly mode stored files in the cache"
1362 # Check that readonly mode and direct mode works.
1363 unset CCACHE_NODIRECT
1364 files_before=`find $CCACHE_DIR -type f | wc -l`
1365 CCACHE_READONLY=1 CCACHE_TEMPDIR=/tmp $CCACHE $COMPILER -c test.c -o test.o
1367 export CCACHE_NODIRECT
1368 if [ $? -ne 0 ]; then
1369 test_failed "failure when compiling test2.c readonly"
1371 files_after=`find $CCACHE_DIR -type f | wc -l`
1372 if [ $files_before -ne $files_after ]; then
1373 test_failed "readonly mode + direct mode stored files in the cache"
1376 ##################################################################
1379 extrafiles_suite() {
1380 ##################################################################
1381 # Create some code to compile.
1388 ##################################################################
1389 # Test the CCACHE_EXTRAFILES feature.
1391 testname="cache hit"
1392 $CCACHE $COMPILER -c test.c
1393 checkstat 'cache hit (preprocessed)' 0
1394 checkstat 'cache miss' 1
1396 testname="cache miss"
1397 $CCACHE $COMPILER -c test.c
1398 checkstat 'cache hit (preprocessed)' 1
1399 checkstat 'cache miss' 1
1401 testname="cache miss a b"
1402 CCACHE_EXTRAFILES="a${PATH_DELIM}b" $CCACHE $COMPILER -c test.c
1403 checkstat 'cache hit (preprocessed)' 1
1404 checkstat 'cache miss' 2
1406 testname="cache hit a b"
1407 CCACHE_EXTRAFILES="a${PATH_DELIM}b" $CCACHE $COMPILER -c test.c
1408 checkstat 'cache hit (preprocessed)' 2
1409 checkstat 'cache miss' 2
1411 testname="cache miss a b2"
1413 CCACHE_EXTRAFILES="a${PATH_DELIM}b" $CCACHE $COMPILER -c test.c
1414 checkstat 'cache hit (preprocessed)' 2
1415 checkstat 'cache miss' 3
1417 testname="cache hit a b2"
1418 CCACHE_EXTRAFILES="a${PATH_DELIM}b" $CCACHE $COMPILER -c test.c
1419 checkstat 'cache hit (preprocessed)' 3
1420 checkstat 'cache miss' 3
1422 testname="cache miss doesntexist"
1423 CCACHE_EXTRAFILES="doesntexist" $CCACHE $COMPILER -c test.c
1424 checkstat 'cache hit (preprocessed)' 3
1425 checkstat 'cache miss' 3
1426 checkstat 'error hashing extra file' 1
1429 prepare_cleanup_test() {
1434 while [ $i -lt 10 ]; do
1435 perl -e 'print "A" x 4017' >$dir/result$i-4017.o
1436 touch $dir/result$i-4017.stderr
1437 touch $dir/result$i-4017.d
1438 if [ $i -gt 5 ]; then
1439 backdate $dir/result$i-4017.stderr
1443 # NUMFILES: 30, TOTALSIZE: 40 KiB, MAXFILES: 0, MAXSIZE: 0
1444 echo "0 0 0 0 0 0 0 0 0 0 0 30 40 0 0" >$dir/stats
1449 prepare_cleanup_test $CCACHE_DIR/a
1450 $CCACHE -C >/dev/null
1451 checkfilecount 0 '*.o' $CCACHE_DIR
1452 checkfilecount 0 '*.d' $CCACHE_DIR
1453 checkfilecount 0 '*.stderr' $CCACHE_DIR
1454 checkstat 'files in cache' 0
1456 testname="forced cleanup, no limits"
1457 $CCACHE -C >/dev/null
1458 prepare_cleanup_test $CCACHE_DIR/a
1459 $CCACHE -F 0 -M 0 >/dev/null
1460 $CCACHE -c >/dev/null
1461 checkfilecount 10 '*.o' $CCACHE_DIR
1462 checkfilecount 10 '*.d' $CCACHE_DIR
1463 checkfilecount 10 '*.stderr' $CCACHE_DIR
1464 checkstat 'files in cache' 30
1466 testname="forced cleanup, file limit"
1467 $CCACHE -C >/dev/null
1468 prepare_cleanup_test $CCACHE_DIR/a
1469 # (9/10) * 30 * 16 = 432
1470 $CCACHE -F 432 -M 0 >/dev/null
1471 $CCACHE -c >/dev/null
1472 # floor(0.8 * 9) = 7
1473 checkfilecount 7 '*.o' $CCACHE_DIR
1474 checkfilecount 7 '*.d' $CCACHE_DIR
1475 checkfilecount 7 '*.stderr' $CCACHE_DIR
1476 checkstat 'files in cache' 21
1477 for i in 0 1 2 3 4 5 9; do
1478 file=$CCACHE_DIR/a/result$i-4017.o
1479 if [ ! -f $file ]; then
1480 test_failed "File $file removed when it shouldn't"
1484 file=$CCACHE_DIR/a/result$i-4017.o
1485 if [ -f $file ]; then
1486 test_failed "File $file not removed when it should"
1490 testname="forced cleanup, size limit"
1491 $CCACHE -C >/dev/null
1492 prepare_cleanup_test $CCACHE_DIR/a
1493 # (4/10) * 10 * 4 * 16 = 256
1494 $CCACHE -F 0 -M 256K >/dev/null
1495 $CCACHE -c >/dev/null
1496 # floor(0.8 * 4) = 3
1497 checkfilecount 3 '*.o' $CCACHE_DIR
1498 checkfilecount 3 '*.d' $CCACHE_DIR
1499 checkfilecount 3 '*.stderr' $CCACHE_DIR
1500 checkstat 'files in cache' 9
1502 file=$CCACHE_DIR/a/result$i-4017.o
1503 if [ ! -f $file ]; then
1504 test_failed "File $file removed when it shouldn't"
1507 for i in 0 1 2 6 7 8 9; do
1508 file=$CCACHE_DIR/a/result$i-4017.o
1509 if [ -f $file ]; then
1510 test_failed "File $file not removed when it should"
1514 testname="autocleanup"
1515 $CCACHE -C >/dev/null
1516 for x in 0 1 2 3 4 5 6 7 8 9 a b c d e f; do
1517 prepare_cleanup_test $CCACHE_DIR/$x
1519 # (9/10) * 30 * 16 = 432
1520 $CCACHE -F 432 -M 0 >/dev/null
1522 checkfilecount 160 '*.o' $CCACHE_DIR
1523 checkfilecount 160 '*.d' $CCACHE_DIR
1524 checkfilecount 160 '*.stderr' $CCACHE_DIR
1525 checkstat 'files in cache' 480
1526 $CCACHE $COMPILER -c empty.c -o empty.o
1527 # floor(0.8 * 9) = 7
1528 checkfilecount 157 '*.o' $CCACHE_DIR
1529 checkfilecount 156 '*.d' $CCACHE_DIR
1530 checkfilecount 156 '*.stderr' $CCACHE_DIR
1531 checkstat 'files in cache' 469
1533 testname="sibling cleanup"
1534 $CCACHE -C >/dev/null
1535 prepare_cleanup_test $CCACHE_DIR/a
1536 # (9/10) * 30 * 16 = 432
1537 $CCACHE -F 432 -M 0 >/dev/null
1538 backdate $CCACHE_DIR/a/result2-4017.stderr
1539 $CCACHE -c >/dev/null
1540 # floor(0.8 * 9) = 7
1541 checkfilecount 7 '*.o' $CCACHE_DIR
1542 checkfilecount 7 '*.d' $CCACHE_DIR
1543 checkfilecount 7 '*.stderr' $CCACHE_DIR
1544 checkstat 'files in cache' 21
1545 for i in 0 1 3 4 5 8 9; do
1546 file=$CCACHE_DIR/a/result$i-4017.o
1547 if [ ! -f $file ]; then
1548 test_failed "File $file removed when it shouldn't"
1552 file=$CCACHE_DIR/a/result$i-4017.o
1553 if [ -f $file ]; then
1554 test_failed "File $file not removed when it should"
1558 testname="new unknown file"
1559 $CCACHE -C >/dev/null
1560 prepare_cleanup_test $CCACHE_DIR/a
1561 touch $CCACHE_DIR/a/abcd.unknown
1562 $CCACHE -c >/dev/null # update counters
1563 checkstat 'files in cache' 31
1564 # (9/10) * 30 * 16 = 432
1565 $CCACHE -F 432 -M 0 >/dev/null
1566 $CCACHE -c >/dev/null
1567 if [ ! -f $CCACHE_DIR/a/abcd.unknown ]; then
1568 test_failed "$CCACHE_DIR/a/abcd.unknown removed"
1570 checkstat 'files in cache' 19
1572 testname="old unknown file"
1573 $CCACHE -C >/dev/null
1574 prepare_cleanup_test $CCACHE_DIR/a
1575 # (9/10) * 30 * 16 = 432
1576 $CCACHE -F 432 -M 0 >/dev/null
1577 touch $CCACHE_DIR/a/abcd.unknown
1578 backdate $CCACHE_DIR/a/abcd.unknown
1579 $CCACHE -c >/dev/null
1580 if [ -f $CCACHE_DIR/a/abcd.unknown ]; then
1581 test_failed "$CCACHE_DIR/a/abcd.unknown not removed"
1584 testname="cleanup of tmp files"
1585 $CCACHE -C >/dev/null
1586 touch $CCACHE_DIR/a/abcd.tmp.efgh
1587 $CCACHE -c >/dev/null # update counters
1588 checkstat 'files in cache' 1
1589 backdate $CCACHE_DIR/a/abcd.tmp.efgh
1590 $CCACHE -c >/dev/null
1591 if [ -f $CCACHE_DIR/a/abcd.tmp.efgh ]; then
1592 test_failed "$CCACHE_DIR/a/abcd.tmp.unknown not removed"
1594 checkstat 'files in cache' 0
1596 testname="ignore .nfs* files"
1597 prepare_cleanup_test $CCACHE_DIR/a
1598 touch $CCACHE_DIR/a/.nfs0123456789
1599 $CCACHE -F 0 -M 0 >/dev/null
1600 $CCACHE -c >/dev/null
1601 checkfilecount 1 '.nfs*' $CCACHE_DIR
1602 checkstat 'files in cache' 30
1606 unset CCACHE_NODIRECT
1627 if $COMPILER -fpch-preprocess pch.h 2>/dev/null && [ -f pch.h.gch ] && $COMPILER pch.c -o pch; then
1630 echo "Compiler (`$COMPILER --version | head -1`) doesn't support precompiled headers -- not running pch test"
1634 ##################################################################
1635 # Tests for creating a .gch.
1639 testname="create .gch, -c, no -o"
1640 $CCACHE -zC >/dev/null
1641 $CCACHE $COMPILER -c pch.h
1642 checkstat 'cache hit (direct)' 0
1643 checkstat 'cache hit (preprocessed)' 0
1644 checkstat 'cache miss' 1
1646 $CCACHE $COMPILER -c pch.h
1647 checkstat 'cache hit (direct)' 1
1648 checkstat 'cache hit (preprocessed)' 0
1649 checkstat 'cache miss' 1
1650 if [ ! -f pch.h.gch ]; then
1651 test_failed "pch.h.gch missing"
1654 testname="create .gch, no -c, -o"
1655 $CCACHE -z >/dev/null
1656 $CCACHE $COMPILER pch.h -o pch.gch
1657 checkstat 'cache hit (direct)' 0
1658 checkstat 'cache hit (preprocessed)' 0
1659 checkstat 'cache miss' 1
1660 $CCACHE $COMPILER pch.h -o pch.gch
1661 checkstat 'cache hit (direct)' 1
1662 checkstat 'cache hit (preprocessed)' 0
1663 checkstat 'cache miss' 1
1664 if [ ! -f pch.gch ]; then
1665 test_failed "pch.gch missing"
1668 ##################################################################
1669 # Tests for using a .gch.
1674 testname="no -fpch-preprocess, #include"
1675 $CCACHE -Cz >/dev/null
1676 $CCACHE $COMPILER -c pch.c 2>/dev/null
1677 checkstat 'cache hit (direct)' 0
1678 checkstat 'cache hit (preprocessed)' 0
1679 checkstat 'cache miss' 0
1680 # Preprocessor error because GCC can't find the real include file when
1681 # trying to preprocess:
1682 checkstat 'preprocessor error' 1
1684 testname="no -fpch-preprocess, -include, no sloppy time macros"
1685 $CCACHE -Cz >/dev/null
1686 $CCACHE $COMPILER -c -include pch.h pch2.c 2>/dev/null
1687 checkstat 'cache hit (direct)' 0
1688 checkstat 'cache hit (preprocessed)' 0
1689 checkstat 'cache miss' 0
1690 # Must enable sloppy time macros:
1691 checkstat "can't use precompiled header" 1
1693 testname="no -fpch-preprocess, -include"
1694 $CCACHE -Cz >/dev/null
1695 CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER -c -include pch.h pch2.c 2>/dev/null
1696 checkstat 'cache hit (direct)' 0
1697 checkstat 'cache hit (preprocessed)' 0
1698 checkstat 'cache miss' 1
1699 CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER -c -include pch.h pch2.c 2>/dev/null
1700 checkstat 'cache hit (direct)' 1
1701 checkstat 'cache hit (preprocessed)' 0
1702 checkstat 'cache miss' 1
1704 testname="-fpch-preprocess, #include, no sloppy time macros"
1705 $CCACHE -Cz >/dev/null
1706 $CCACHE $COMPILER -c -fpch-preprocess pch.c
1707 checkstat 'cache hit (direct)' 0
1708 checkstat 'cache hit (preprocessed)' 0
1709 # Must enable sloppy time macros:
1710 checkstat "can't use precompiled header" 1
1712 testname="-fpch-preprocess, #include, sloppy time macros"
1713 $CCACHE -Cz >/dev/null
1714 CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER -c -fpch-preprocess pch.c
1715 checkstat 'cache hit (direct)' 0
1716 checkstat 'cache hit (preprocessed)' 0
1717 checkstat 'cache miss' 1
1718 CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER -c -fpch-preprocess pch.c
1719 checkstat 'cache hit (direct)' 1
1720 checkstat 'cache hit (preprocessed)' 0
1721 checkstat 'cache miss' 1
1723 testname="-fpch-preprocess, #include, file changed"
1724 echo "updated" >>pch.h.gch # GCC seems to cope with this...
1726 CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER -c -fpch-preprocess pch.c
1727 checkstat 'cache hit (direct)' 1
1728 checkstat 'cache hit (preprocessed)' 0
1729 checkstat 'cache miss' 2
1731 testname="preprocessor mode"
1732 $CCACHE -Cz >/dev/null
1733 CCACHE_NODIRECT=1 CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER -c -fpch-preprocess pch.c
1734 checkstat 'cache hit (direct)' 0
1735 checkstat 'cache hit (preprocessed)' 0
1736 checkstat 'cache miss' 1
1737 CCACHE_NODIRECT=1 CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER -c -fpch-preprocess pch.c
1738 checkstat 'cache hit (direct)' 0
1739 checkstat 'cache hit (preprocessed)' 1
1740 checkstat 'cache miss' 1
1742 testname="preprocessor mode, file changed"
1743 echo "updated" >>pch.h.gch # GCC seems to cope with this...
1745 CCACHE_NODIRECT=1 CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER -c -fpch-preprocess pch.c
1746 checkstat 'cache hit (direct)' 0
1747 checkstat 'cache hit (preprocessed)' 1
1748 checkstat 'cache miss' 2
1749 CCACHE_NODIRECT=1 CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER -c -fpch-preprocess pch.c
1750 checkstat 'cache hit (direct)' 0
1751 checkstat 'cache hit (preprocessed)' 2
1752 checkstat 'cache miss' 2
1755 ######################################################################
1759 if [ -n "$CC" ]; then
1764 if [ -z "$CCACHE" ]; then
1768 compiler_version="`$COMPILER --version 2>&1 | head -1`"
1769 case $compiler_version in
1773 echo "WARNING: Compiler $COMPILER not supported (version: $compiler_version) -- not running tests" >&2
1781 cd $TESTDIR || exit 1
1783 CCACHE_DIR=`pwd`/.ccache
1785 CCACHE_LOGFILE=`pwd`/ccache.log
1786 export CCACHE_LOGFILE
1788 # ---------------------------------------
1806 host_os="`uname -s`"
1809 export CCACHE_DETECT_SHEBANG
1810 CCACHE_DETECT_SHEBANG=1
1813 all_suites="`echo "$all_suites" | grep -v '!win32'`"
1818 all_suites="`echo "$all_suites" | cut -d' ' -f1`"
1822 if [ -z "$suites" ]; then
1823 suites="$all_suites"
1826 for suite in $suites; do
1830 # ---------------------------------------