1899
|
1 #!/bin/sh
|
|
2
|
|
3 # a simple test suite for ccache
|
|
4 # tridge@samba.org
|
|
5
|
|
6 if test -n "$CC"; then
|
|
7 COMPILER="$CC"
|
|
8 else
|
|
9 COMPILER=cc
|
|
10 fi
|
|
11
|
|
12 if test -n "$SWIG"; then
|
|
13 SWIG="$SWIG"
|
|
14 else
|
|
15 SWIG=swig
|
|
16 fi
|
|
17
|
|
18 CCACHE=../ccache-swig
|
|
19 TESTDIR=test.$$
|
|
20
|
|
21 test_failed() {
|
|
22 reason="$1"
|
|
23 echo $1
|
|
24 $CCACHE -s
|
|
25 cd ..
|
|
26 rm -rf $TESTDIR
|
|
27 echo TEST FAILED
|
|
28 exit 1
|
|
29 }
|
|
30
|
|
31 randcode() {
|
|
32 outfile="$1"
|
|
33 nlines=$2
|
|
34 i=0;
|
|
35 (
|
|
36 while [ $i -lt $nlines ]; do
|
|
37 echo "int foo$nlines$i(int x) { return x; }"
|
|
38 i=`expr $i + 1`
|
|
39 done
|
|
40 ) >> "$outfile"
|
|
41 }
|
|
42
|
|
43 genswigcode() {
|
|
44 outfile="$1"
|
|
45 nlines=$2
|
|
46 i=0;
|
|
47 (
|
|
48 echo "%module swigtest$2;"
|
|
49 while [ $i -lt $nlines ]; do
|
|
50 echo "int foo$nlines$i(int x);"
|
|
51 echo "struct Bar$nlines$i { int y; };"
|
|
52 i=`expr $i + 1`
|
|
53 done
|
|
54 ) >> "$outfile"
|
|
55 }
|
|
56
|
|
57
|
|
58 getstat() {
|
|
59 stat="$1"
|
|
60 value=`$CCACHE -s | grep "$stat" | cut -c34-40`
|
|
61 echo $value
|
|
62 }
|
|
63
|
|
64 checkstat() {
|
|
65 stat="$1"
|
|
66 expected_value="$2"
|
|
67 value=`getstat "$stat"`
|
|
68 # echo "exp: $expected_value got: $value $testname"
|
|
69 if [ "$expected_value" != "$value" ]; then
|
|
70 test_failed "SUITE: $testsuite TEST: $testname - Expected $stat to be $expected_value got $value"
|
|
71 fi
|
|
72 }
|
|
73
|
|
74
|
|
75 basetests() {
|
|
76 echo "starting testsuite $testsuite"
|
|
77 rm -rf "$CCACHE_DIR"
|
|
78 checkstat 'cache hit' 0
|
|
79 checkstat 'cache miss' 0
|
|
80
|
|
81 j=1
|
|
82 rm -f *.c
|
|
83 while [ $j -lt 32 ]; do
|
|
84 randcode test$j.c $j
|
|
85 j=`expr $j + 1`
|
|
86 done
|
|
87
|
|
88 testname="BASIC"
|
|
89 $CCACHE_COMPILE -c test1.c
|
|
90 checkstat 'cache hit' 0
|
|
91 checkstat 'cache miss' 1
|
|
92
|
|
93 testname="BASIC2"
|
|
94 $CCACHE_COMPILE -c test1.c
|
|
95 checkstat 'cache hit' 1
|
|
96 checkstat 'cache miss' 1
|
|
97
|
|
98 testname="debug"
|
|
99 $CCACHE_COMPILE -c test1.c -g
|
|
100 checkstat 'cache hit' 1
|
|
101 checkstat 'cache miss' 2
|
|
102
|
|
103 testname="debug2"
|
|
104 $CCACHE_COMPILE -c test1.c -g
|
|
105 checkstat 'cache hit' 2
|
|
106 checkstat 'cache miss' 2
|
|
107
|
|
108 testname="output"
|
|
109 $CCACHE_COMPILE -c test1.c -o foo.o
|
|
110 checkstat 'cache hit' 3
|
|
111 checkstat 'cache miss' 2
|
|
112
|
|
113 testname="link"
|
|
114 $CCACHE_COMPILE test1.c -o test 2> /dev/null
|
|
115 checkstat 'called for link' 1
|
|
116
|
|
117 testname="multiple"
|
|
118 $CCACHE_COMPILE -c test1.c test2.c
|
|
119 checkstat 'multiple source files' 1
|
|
120
|
|
121 testname="find"
|
|
122 $CCACHE blahblah -c test1.c 2> /dev/null
|
|
123 checkstat "couldn't find the compiler" 1
|
|
124
|
|
125 testname="bad"
|
|
126 $CCACHE_COMPILE -c test1.c -I 2> /dev/null
|
|
127 checkstat 'bad compiler arguments' 1
|
|
128
|
|
129 testname="c/c++"
|
|
130 ln -f test1.c test1.ccc
|
|
131 $CCACHE_COMPILE -c test1.ccc 2> /dev/null
|
|
132 checkstat 'not a C/C++ file' 1
|
|
133
|
|
134 testname="unsupported"
|
|
135 $CCACHE_COMPILE -M foo -c test1.c > /dev/null 2>&1
|
|
136 checkstat 'unsupported compiler option' 1
|
|
137
|
|
138 testname="stdout"
|
|
139 $CCACHE echo foo -c test1.c > /dev/null
|
|
140 checkstat 'compiler produced stdout' 1
|
|
141
|
|
142 testname="non-regular"
|
|
143 mkdir testd
|
|
144 $CCACHE_COMPILE -o testd -c test1.c > /dev/null 2>&1
|
|
145 rm -rf testd
|
|
146 checkstat 'output to a non-regular file' 1
|
|
147
|
|
148 testname="no-input"
|
|
149 $CCACHE_COMPILE -c -O2 2> /dev/null
|
|
150 checkstat 'no input file' 1
|
|
151
|
|
152
|
|
153 testname="CCACHE_DISABLE"
|
|
154 CCACHE_DISABLE=1 $CCACHE_COMPILE -c test1.c 2> /dev/null
|
|
155 checkstat 'cache hit' 3
|
|
156 $CCACHE_COMPILE -c test1.c
|
|
157 checkstat 'cache hit' 4
|
|
158
|
|
159 testname="CCACHE_CPP2"
|
|
160 CCACHE_CPP2=1 $CCACHE_COMPILE -c test1.c -O -O
|
|
161 checkstat 'cache hit' 4
|
|
162 checkstat 'cache miss' 3
|
|
163
|
|
164 CCACHE_CPP2=1 $CCACHE_COMPILE -c test1.c -O -O
|
|
165 checkstat 'cache hit' 5
|
|
166 checkstat 'cache miss' 3
|
|
167
|
|
168 testname="CCACHE_NOSTATS"
|
|
169 CCACHE_NOSTATS=1 $CCACHE_COMPILE -c test1.c -O -O
|
|
170 checkstat 'cache hit' 5
|
|
171 checkstat 'cache miss' 3
|
|
172
|
|
173 testname="CCACHE_RECACHE"
|
|
174 CCACHE_RECACHE=1 $CCACHE_COMPILE -c test1.c -O -O
|
|
175 checkstat 'cache hit' 5
|
|
176 checkstat 'cache miss' 4
|
|
177
|
|
178 # strictly speaking should be 6 - RECACHE causes a double counting!
|
|
179 checkstat 'files in cache' 8
|
|
180 $CCACHE -c > /dev/null
|
|
181 checkstat 'files in cache' 6
|
|
182
|
|
183
|
|
184 testname="CCACHE_HASHDIR"
|
|
185 CCACHE_HASHDIR=1 $CCACHE_COMPILE -c test1.c -O -O
|
|
186 checkstat 'cache hit' 5
|
|
187 checkstat 'cache miss' 5
|
|
188
|
|
189 CCACHE_HASHDIR=1 $CCACHE_COMPILE -c test1.c -O -O
|
|
190 checkstat 'cache hit' 6
|
|
191 checkstat 'cache miss' 5
|
|
192
|
|
193 checkstat 'files in cache' 8
|
|
194
|
|
195 testname="comments"
|
|
196 echo '/* a silly comment */' > test1-comment.c
|
|
197 cat test1.c >> test1-comment.c
|
|
198 $CCACHE_COMPILE -c test1-comment.c
|
|
199 rm -f test1-comment*
|
|
200 checkstat 'cache hit' 6
|
|
201 checkstat 'cache miss' 6
|
|
202
|
|
203 testname="CCACHE_UNIFY"
|
|
204 CCACHE_UNIFY=1 $CCACHE_COMPILE -c test1.c
|
|
205 checkstat 'cache hit' 6
|
|
206 checkstat 'cache miss' 7
|
|
207 mv test1.c test1-saved.c
|
|
208 echo '/* another comment */' > test1.c
|
|
209 cat test1-saved.c >> test1.c
|
|
210 CCACHE_UNIFY=1 $CCACHE_COMPILE -c test1.c
|
|
211 mv test1-saved.c test1.c
|
|
212 checkstat 'cache hit' 7
|
|
213 checkstat 'cache miss' 7
|
|
214
|
|
215 testname="cache-size"
|
|
216 for f in *.c; do
|
|
217 $CCACHE_COMPILE -c $f
|
|
218 done
|
|
219 checkstat 'cache hit' 8
|
|
220 checkstat 'cache miss' 37
|
|
221 checkstat 'files in cache' 72
|
|
222 $CCACHE -F 48 -c > /dev/null
|
|
223 if [ `getstat 'files in cache'` -gt 48 ]; then
|
|
224 test_failed '-F test failed'
|
|
225 fi
|
|
226
|
|
227 testname="cpp call"
|
|
228 $CCACHE_COMPILE -c test1.c -E > test1.i
|
|
229 checkstat 'cache hit' 8
|
|
230 checkstat 'cache miss' 37
|
|
231
|
|
232 testname="direct .i compile"
|
|
233 $CCACHE_COMPILE -c test1.c
|
|
234 checkstat 'cache hit' 8
|
|
235 checkstat 'cache miss' 38
|
|
236
|
|
237 $CCACHE_COMPILE -c test1.i
|
|
238 checkstat 'cache hit' 9
|
|
239 checkstat 'cache miss' 38
|
|
240
|
|
241 $CCACHE_COMPILE -c test1.i
|
|
242 checkstat 'cache hit' 10
|
|
243 checkstat 'cache miss' 38
|
|
244
|
|
245 # removed these tests as some compilers (including newer versions of gcc)
|
|
246 # determine which language to use based on .ii/.i extension, and C++ may
|
|
247 # not be installed
|
|
248 # testname="direct .ii file"
|
|
249 # mv test1.i test1.ii
|
|
250 # $CCACHE_COMPILE -c test1.ii
|
|
251 # checkstat 'cache hit' 10
|
|
252 # checkstat 'cache miss' 39
|
|
253
|
|
254 # $CCACHE_COMPILE -c test1.ii
|
|
255 # checkstat 'cache hit' 11
|
|
256 # checkstat 'cache miss' 39
|
|
257
|
|
258 testname="stripc" # This test might not be portable
|
|
259 CCACHE_STRIPC=1 $CCACHE_COMPILE -c test1.c
|
|
260 checkstat 'cache hit' 10
|
|
261 checkstat 'cache miss' 39
|
|
262
|
|
263 CCACHE_STRIPC=1 $CCACHE_COMPILE -c test1.c
|
|
264 checkstat 'cache hit' 11
|
|
265 checkstat 'cache miss' 39
|
|
266
|
|
267 testname="zero-stats"
|
|
268 $CCACHE -z > /dev/null
|
|
269 checkstat 'cache hit' 0
|
|
270 checkstat 'cache miss' 0
|
|
271
|
|
272 testname="clear"
|
|
273 $CCACHE -C > /dev/null
|
|
274 checkstat 'files in cache' 0
|
|
275
|
|
276
|
|
277 rm -f test1.c
|
|
278 }
|
|
279
|
|
280 swigtests() {
|
|
281 echo "starting swig testsuite $testsuite"
|
|
282 rm -rf "$CCACHE_DIR"
|
|
283 checkstat 'cache hit' 0
|
|
284 checkstat 'cache miss' 0
|
|
285
|
|
286 j=1
|
|
287 rm -f *.i
|
|
288 genswigcode testswig1.i 1
|
|
289
|
|
290 testname="BASIC"
|
|
291 $CCACHE_COMPILE -java testswig1.i
|
|
292 checkstat 'cache hit' 0
|
|
293 checkstat 'cache miss' 1
|
|
294
|
|
295 checkstat 'files in cache' 6
|
|
296
|
|
297 testname="BASIC2"
|
|
298 $CCACHE_COMPILE -java testswig1.i
|
|
299 checkstat 'cache hit' 1
|
|
300 checkstat 'cache miss' 1
|
|
301
|
|
302 testname="output"
|
|
303 $CCACHE_COMPILE -java testswig1.i -o foo_wrap.c
|
|
304 checkstat 'cache hit' 1
|
|
305 checkstat 'cache miss' 2
|
|
306
|
|
307 testname="bad"
|
|
308 $CCACHE_COMPILE -java testswig1.i -I 2> /dev/null
|
|
309 checkstat 'bad compiler arguments' 1
|
|
310
|
|
311 testname="stdout"
|
|
312 $CCACHE_COMPILE -v -java testswig1.i > /dev/null
|
|
313 checkstat 'compiler produced stdout' 1
|
|
314
|
|
315 testname="non-regular"
|
|
316 mkdir testd
|
|
317 $CCACHE_COMPILE -o testd -java testswig1.i > /dev/null 2>&1
|
|
318 rm -rf testd
|
|
319 checkstat 'output to a non-regular file' 1
|
|
320
|
|
321 testname="no-input"
|
|
322 $CCACHE_COMPILE -java 2> /dev/null
|
|
323 checkstat 'no input file' 1
|
|
324
|
|
325
|
|
326 testname="CCACHE_DISABLE"
|
|
327 CCACHE_DISABLE=1 $CCACHE_COMPILE -java testswig1.i 2> /dev/null
|
|
328 checkstat 'cache hit' 1
|
|
329 $CCACHE_COMPILE -java testswig1.i
|
|
330 checkstat 'cache hit' 2
|
|
331
|
|
332 testname="CCACHE_CPP2"
|
|
333 CCACHE_CPP2=1 $CCACHE_COMPILE -java -O -O testswig1.i
|
|
334 checkstat 'cache hit' 2
|
|
335 checkstat 'cache miss' 3
|
|
336
|
|
337 CCACHE_CPP2=1 $CCACHE_COMPILE -java -O -O testswig1.i
|
|
338 checkstat 'cache hit' 3
|
|
339 checkstat 'cache miss' 3
|
|
340
|
|
341 testname="CCACHE_NOSTATS"
|
|
342 CCACHE_NOSTATS=1 $CCACHE_COMPILE -java -O -O testswig1.i
|
|
343 checkstat 'cache hit' 3
|
|
344 checkstat 'cache miss' 3
|
|
345
|
|
346 testname="CCACHE_RECACHE"
|
|
347 CCACHE_RECACHE=1 $CCACHE_COMPILE -java -O -O testswig1.i
|
|
348 checkstat 'cache hit' 3
|
|
349 checkstat 'cache miss' 4
|
|
350
|
|
351 # strictly speaking should be 3x6=18 instead of 4x6=24 - RECACHE causes a double counting!
|
|
352 checkstat 'files in cache' 24
|
|
353 $CCACHE -c > /dev/null
|
|
354 checkstat 'files in cache' 18
|
|
355
|
|
356
|
|
357 testname="CCACHE_HASHDIR"
|
|
358 CCACHE_HASHDIR=1 $CCACHE_COMPILE -java -O -O testswig1.i
|
|
359 checkstat 'cache hit' 3
|
|
360 checkstat 'cache miss' 5
|
|
361
|
|
362 CCACHE_HASHDIR=1 $CCACHE_COMPILE -java -O -O testswig1.i
|
|
363 checkstat 'cache hit' 4
|
|
364 checkstat 'cache miss' 5
|
|
365
|
|
366 checkstat 'files in cache' 24
|
|
367
|
|
368 testname="cpp call"
|
|
369 $CCACHE_COMPILE -java -E testswig1.i > testswig1-preproc.i
|
|
370 checkstat 'cache hit' 4
|
|
371 checkstat 'cache miss' 5
|
|
372
|
|
373 testname="direct .i compile"
|
|
374 $CCACHE_COMPILE -java testswig1.i
|
|
375 checkstat 'cache hit' 5
|
|
376 checkstat 'cache miss' 5
|
|
377
|
|
378 # No cache hit due to different input file name, -nopreprocess should not be given twice to SWIG
|
|
379 $CCACHE_COMPILE -java -nopreprocess testswig1-preproc.i
|
|
380 checkstat 'cache hit' 5
|
|
381 checkstat 'cache miss' 6
|
|
382
|
|
383 $CCACHE_COMPILE -java -nopreprocess testswig1-preproc.i
|
|
384 checkstat 'cache hit' 6
|
|
385 checkstat 'cache miss' 6
|
|
386
|
|
387 testname="stripc"
|
|
388 CCACHE_STRIPC=1 $CCACHE_COMPILE -java -O -O testswig1.i
|
|
389 checkstat 'cache hit' 7
|
|
390 checkstat 'cache miss' 6
|
|
391
|
|
392 CCACHE_STRIPC=1 $CCACHE_COMPILE -java -O -O -O testswig1.i
|
|
393 checkstat 'cache hit' 7
|
|
394 checkstat 'cache miss' 7
|
|
395
|
|
396 rm -f testswig1-preproc.i
|
|
397 rm -f testswig1.i
|
|
398 }
|
|
399
|
|
400 ######
|
|
401 # main program
|
|
402 rm -rf $TESTDIR
|
|
403 mkdir $TESTDIR
|
|
404 cd $TESTDIR || exit 1
|
|
405 CCACHE_DIR="ccache dir" # with space in directory name (like Windows default)
|
|
406 mkdir "$CCACHE_DIR"
|
|
407 export CCACHE_DIR
|
|
408
|
|
409 testsuite="base"
|
|
410 CCACHE_COMPILE="$CCACHE $COMPILER"
|
|
411 basetests
|
|
412 CCACHE_COMPILE="$CCACHE $SWIG"
|
|
413 swigtests
|
|
414
|
|
415 if test -z "$NOSOFTLINKSTEST"; then
|
|
416 testsuite="link"
|
|
417 ln -s $CCACHE $COMPILER
|
|
418 CCACHE_COMPILE="./$COMPILER"
|
|
419 basetests
|
|
420 rm "./$COMPILER"
|
|
421 ln -s $CCACHE $SWIG
|
|
422 CCACHE_COMPILE="./$SWIG"
|
|
423 swigtests
|
|
424 rm "./$SWIG"
|
|
425 else
|
|
426 echo "skipping testsuite link"
|
|
427 fi
|
|
428
|
|
429 testsuite="hardlink"
|
|
430 CCACHE_COMPILE="env CCACHE_NOCOMPRESS=1 CCACHE_HARDLINK=1 $CCACHE $COMPILER"
|
|
431 basetests
|
|
432 CCACHE_COMPILE="env CCACHE_NOCOMPRESS=1 CCACHE_HARDLINK=1 $CCACHE $SWIG"
|
|
433 swigtests
|
|
434
|
|
435 testsuite="cpp2"
|
|
436 CCACHE_COMPILE="env CCACHE_CPP2=1 $CCACHE $COMPILER"
|
|
437 basetests
|
|
438 CCACHE_COMPILE="env CCACHE_CPP2=1 $CCACHE $SWIG"
|
|
439 swigtests
|
|
440
|
|
441 testsuite="nlevels4"
|
|
442 CCACHE_COMPILE="env CCACHE_NLEVELS=4 $CCACHE $COMPILER"
|
|
443 basetests
|
|
444
|
|
445 testsuite="nlevels1"
|
|
446 CCACHE_COMPILE="env CCACHE_NLEVELS=1 $CCACHE $COMPILER"
|
|
447 basetests
|
|
448
|
|
449 cd ..
|
|
450 rm -rf $TESTDIR
|
|
451 echo test done - OK
|
|
452 exit 0
|