3
# a simple test suite for ccache
12
if test -n "$SWIG"; then
36
while [ $i -lt $nlines ]; do
37
echo "int foo$nlines$i(int x) { return x; }"
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; };"
60
value=`$CCACHE -s | grep "$stat" | cut -c34-40`
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"
76
echo "starting testsuite $testsuite"
78
checkstat 'cache hit' 0
79
checkstat 'cache miss' 0
83
while [ $j -lt 32 ]; do
89
$CCACHE_COMPILE -c test1.c
90
checkstat 'cache hit' 0
91
checkstat 'cache miss' 1
94
$CCACHE_COMPILE -c test1.c
95
checkstat 'cache hit' 1
96
checkstat 'cache miss' 1
99
$CCACHE_COMPILE -c test1.c -g
100
checkstat 'cache hit' 1
101
checkstat 'cache miss' 2
104
$CCACHE_COMPILE -c test1.c -g
105
checkstat 'cache hit' 2
106
checkstat 'cache miss' 2
109
$CCACHE_COMPILE -c test1.c -o foo.o
110
checkstat 'cache hit' 3
111
checkstat 'cache miss' 2
114
$CCACHE_COMPILE test1.c -o test 2> /dev/null
115
checkstat 'called for link' 1
118
$CCACHE_COMPILE -c test1.c test2.c
119
checkstat 'multiple source files' 1
122
$CCACHE blahblah -c test1.c 2> /dev/null
123
checkstat "couldn't find the compiler" 1
126
$CCACHE_COMPILE -c test1.c -I 2> /dev/null
127
checkstat 'bad compiler arguments' 1
130
ln -f test1.c test1.ccc
131
$CCACHE_COMPILE -c test1.ccc 2> /dev/null
132
checkstat 'not a C/C++ file' 1
134
testname="unsupported"
135
$CCACHE_COMPILE -M foo -c test1.c > /dev/null 2>&1
136
checkstat 'unsupported compiler option' 1
139
$CCACHE echo foo -c test1.c > /dev/null
140
checkstat 'compiler produced stdout' 1
142
testname="non-regular"
144
$CCACHE_COMPILE -o testd -c test1.c > /dev/null 2>&1
146
checkstat 'output to a non-regular file' 1
149
$CCACHE_COMPILE -c -O2 2> /dev/null
150
checkstat 'no input file' 1
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
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
164
CCACHE_CPP2=1 $CCACHE_COMPILE -c test1.c -O -O
165
checkstat 'cache hit' 5
166
checkstat 'cache miss' 3
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
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
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
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
189
CCACHE_HASHDIR=1 $CCACHE_COMPILE -c test1.c -O -O
190
checkstat 'cache hit' 6
191
checkstat 'cache miss' 5
193
checkstat 'files in cache' 8
196
echo '/* a silly comment */' > test1-comment.c
197
cat test1.c >> test1-comment.c
198
$CCACHE_COMPILE -c test1-comment.c
200
checkstat 'cache hit' 6
201
checkstat 'cache miss' 6
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
215
testname="cache-size"
217
$CCACHE_COMPILE -c $f
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'
228
$CCACHE_COMPILE -c test1.c -E > test1.i
229
checkstat 'cache hit' 8
230
checkstat 'cache miss' 37
232
testname="direct .i compile"
233
$CCACHE_COMPILE -c test1.c
234
checkstat 'cache hit' 8
235
checkstat 'cache miss' 38
237
$CCACHE_COMPILE -c test1.i
238
checkstat 'cache hit' 9
239
checkstat 'cache miss' 38
241
$CCACHE_COMPILE -c test1.i
242
checkstat 'cache hit' 10
243
checkstat 'cache miss' 38
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
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
254
# $CCACHE_COMPILE -c test1.ii
255
# checkstat 'cache hit' 11
256
# checkstat 'cache miss' 39
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
263
CCACHE_STRIPC=1 $CCACHE_COMPILE -c test1.c
264
checkstat 'cache hit' 11
265
checkstat 'cache miss' 39
267
testname="zero-stats"
268
$CCACHE -z > /dev/null
269
checkstat 'cache hit' 0
270
checkstat 'cache miss' 0
273
$CCACHE -C > /dev/null
274
checkstat 'files in cache' 0
281
echo "starting swig testsuite $testsuite"
283
checkstat 'cache hit' 0
284
checkstat 'cache miss' 0
288
genswigcode testswig1.i 1
291
$CCACHE_COMPILE -java testswig1.i
292
checkstat 'cache hit' 0
293
checkstat 'cache miss' 1
295
checkstat 'files in cache' 6
298
$CCACHE_COMPILE -java testswig1.i
299
checkstat 'cache hit' 1
300
checkstat 'cache miss' 1
303
$CCACHE_COMPILE -java testswig1.i -o foo_wrap.c
304
checkstat 'cache hit' 1
305
checkstat 'cache miss' 2
308
$CCACHE_COMPILE -java testswig1.i -I 2> /dev/null
309
checkstat 'bad compiler arguments' 1
312
$CCACHE_COMPILE -v -java testswig1.i > /dev/null
313
checkstat 'compiler produced stdout' 1
315
testname="non-regular"
317
$CCACHE_COMPILE -o testd -java testswig1.i > /dev/null 2>&1
319
checkstat 'output to a non-regular file' 1
322
$CCACHE_COMPILE -java 2> /dev/null
323
checkstat 'no input file' 1
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
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
337
CCACHE_CPP2=1 $CCACHE_COMPILE -java -O -O testswig1.i
338
checkstat 'cache hit' 3
339
checkstat 'cache miss' 3
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
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
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
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
362
CCACHE_HASHDIR=1 $CCACHE_COMPILE -java -O -O testswig1.i
363
checkstat 'cache hit' 4
364
checkstat 'cache miss' 5
366
checkstat 'files in cache' 24
369
$CCACHE_COMPILE -java -E testswig1.i > testswig1-preproc.i
370
checkstat 'cache hit' 4
371
checkstat 'cache miss' 5
373
testname="direct .i compile"
374
$CCACHE_COMPILE -java testswig1.i
375
checkstat 'cache hit' 5
376
checkstat 'cache miss' 5
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
383
$CCACHE_COMPILE -java -nopreprocess testswig1-preproc.i
384
checkstat 'cache hit' 6
385
checkstat 'cache miss' 6
388
CCACHE_STRIPC=1 $CCACHE_COMPILE -java -O -O testswig1.i
389
checkstat 'cache hit' 7
390
checkstat 'cache miss' 6
392
CCACHE_STRIPC=1 $CCACHE_COMPILE -java -O -O -O testswig1.i
393
checkstat 'cache hit' 7
394
checkstat 'cache miss' 7
396
rm -f testswig1-preproc.i
404
cd $TESTDIR || exit 1
405
CCACHE_DIR="ccache dir" # with space in directory name (like Windows default)
410
CCACHE_COMPILE="$CCACHE $COMPILER"
412
CCACHE_COMPILE="$CCACHE $SWIG"
415
if test -z "$NOSOFTLINKSTEST"; then
417
ln -s $CCACHE $COMPILER
418
CCACHE_COMPILE="./$COMPILER"
422
CCACHE_COMPILE="./$SWIG"
426
echo "skipping testsuite link"
430
CCACHE_COMPILE="env CCACHE_NOCOMPRESS=1 CCACHE_HARDLINK=1 $CCACHE $COMPILER"
432
CCACHE_COMPILE="env CCACHE_NOCOMPRESS=1 CCACHE_HARDLINK=1 $CCACHE $SWIG"
436
CCACHE_COMPILE="env CCACHE_CPP2=1 $CCACHE $COMPILER"
438
CCACHE_COMPILE="env CCACHE_CPP2=1 $CCACHE $SWIG"
442
CCACHE_COMPILE="env CCACHE_NLEVELS=4 $CCACHE $COMPILER"
446
CCACHE_COMPILE="env CCACHE_NLEVELS=1 $CCACHE $COMPILER"