]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
improved test suite
authorAndrew Tridgell <tridge@samba.org>
Mon, 17 Feb 2003 00:46:43 +0000 (01:46 +0100)
committerAndrew Tridgell <tridge@samba.org>
Mon, 17 Feb 2003 00:46:43 +0000 (01:46 +0100)
updated docs for CCACHE_HARDLINK

Makefile.in
ccache.1
ccache.yo
test.sh

index ef049eb413283f1bd0625f7e4d822e2ae33344f2..64abf8ab64d9836d5956a401c84afd319ac196cf 100644 (file)
@@ -37,5 +37,8 @@ install:
 clean:
        /bin/rm -f $(OBJS) *~ ccache
 
+test: test.sh
+       ./test.sh
+
 distclean: clean
        /bin/rm -f Makefile config.h config.sub config.log build-stamp config.status
index 7f4a1d0f85128b683fafbd938547d77027f67aad..7fbcbb55beeabba5b3a0a1d8c18e7eeebbd5c8ce 100644 (file)
--- a/ccache.1
+++ b/ccache.1
@@ -189,13 +189,12 @@ The environment variable CCACHE_NLEVELS allows
 you to choose the number of levels of hash in the cache directory\&. The
 default is 2\&. The minimum is 1 and the maximum is 8\&. 
 .IP 
-.IP "\fBCCACHE_NOLINK\fP" 
+.IP "\fBCCACHE_HARDLINK\fP" 
 If you set the environment variable
-CCACHE_NOLINK then ccache will not use hard links from the cache
-directory when creating the compiler output and will do a file copy
-instead\&. The main reason for setting this option is to avoid the
-update of the modification time on object files that are the result of
-the same compilation in a different directory\&.
+CCACHE_HARDLINK then ccache will attempt to use hard links from the
+cache directory when creating the compiler output rather than using a
+file copy\&. Using hard links is faster, but can confuse programs like
+\&'make\&' that rely on modification times\&.
 .IP 
 .IP "\fBCCACHE_RECACHE\fP" 
 This forces ccache to not use any cached
@@ -298,8 +297,6 @@ following conditions need to be met:
 .IP o 
 Use the same \fBCCACHE_DIR\fP environment variable setting
 .IP o 
-Set the \fBCCACHE_NOLINK\fP environment variable
-.IP o 
 Make sure that all users have write permission in the entire
 cache directory (and that you trust all users of the shared cache)\&. 
 .IP o 
index 8ff893f7ecac249ff026db84008e260bce4c3cf7..00c86ceeae0d7d10ffff283661474f446e221e8a 100644 (file)
--- a/ccache.yo
+++ b/ccache.yo
@@ -163,12 +163,11 @@ dit(bf(CCACHE_NLEVELS)) The environment variable CCACHE_NLEVELS allows
 you to choose the number of levels of hash in the cache directory. The
 default is 2. The minimum is 1 and the maximum is 8. 
 
-dit(bf(CCACHE_NOLINK)) If you set the environment variable
-CCACHE_NOLINK then ccache will not use hard links from the cache
-directory when creating the compiler output and will do a file copy
-instead. The main reason for setting this option is to avoid the
-update of the modification time on object files that are the result of
-the same compilation in a different directory.
+dit(bf(CCACHE_HARDLINK)) If you set the environment variable
+CCACHE_HARDLINK then ccache will attempt to use hard links from the
+cache directory when creating the compiler output rather than using a
+file copy. Using hard links is faster, but can confuse programs like
+'make' that rely on modification times.
 
 dit(bf(CCACHE_RECACHE)) This forces ccache to not use any cached
 results, even if it finds them. New results are still cached, but
@@ -265,7 +264,6 @@ following conditions need to be met:
 
 itemize(
   it() Use the same bf(CCACHE_DIR) environment variable setting
-  it() Set the bf(CCACHE_NOLINK) environment variable
   it() Make sure that all users have write permission in the entire
   cache directory (and that you trust all users of the shared cache). 
   it() Tell your users to set a umask that allows group writes
diff --git a/test.sh b/test.sh
index ca8a4dc522a3d463cc1eb0eaf2a1dea81f409819..8e2c1455c67b6b1e2f60e97451526f37da83d5d5 100755 (executable)
--- a/test.sh
+++ b/test.sh
@@ -1,10 +1,12 @@
 #!/bin/sh
 
+# a simple test suite for ccache
+# tridge@samba.org
+
 COMPILER=cc
 CCACHE=../ccache
 TESTDIR=test.$$
 
-
 test_failed() {
     reason="$1"
     echo $1
@@ -17,14 +19,14 @@ test_failed() {
 
 randcode() {
     outfile="$1"
-    nlines=`expr $RANDOM % 100`
+    nlines=$2
     i=0;
     (
     while [ $i -lt $nlines ]; do
-       echo "int foo$i(int x) { return x; }"
+       echo "int foo$nlines$i(int x) { return x; }"
        i=`expr $i + 1`
     done
-    ) > "$outfile"
+    ) >> "$outfile"
 }
 
 
@@ -39,95 +41,119 @@ checkstat() {
     expected_value="$2"
     value=`getstat "$stat"`
     if [ "$expected_value" != "$value" ]; then
-       test_failed "Expected $stat to be $expected_value - got $value"
+       test_failed "SUITE: $testsuite TEST: $testname - Expected $stat to be $expected_value got $value"
     fi
 }
 
 
 basetests() {
-    $CCACHE -z > /dev/null
+    echo "starting testsuite $testsuite"
+    rm -rf .ccache
     checkstat 'cache hit' 0
     checkstat 'cache miss' 0
 
-    randcode test1.c
-    randcode test2.c
-    
+    j=0
+    rm -f *.c
+    while [ $j -lt 32 ]; do
+       randcode test$j.c $j
+       j=`expr $j + 1`
+    done
+
+    testname="BASIC"
     $CCACHE_COMPILE -c test1.c
     checkstat 'cache hit' 0
     checkstat 'cache miss' 1
     
+    testname="BASIC2"
     $CCACHE_COMPILE -c test1.c
     checkstat 'cache hit' 1
     checkstat 'cache miss' 1
     
+    testname="debug"
     $CCACHE_COMPILE -c test1.c -g
     checkstat 'cache hit' 1
     checkstat 'cache miss' 2
     
+    testname="debug2"
     $CCACHE_COMPILE -c test1.c -g
     checkstat 'cache hit' 2
     checkstat 'cache miss' 2
     
+    testname="output"
     $CCACHE_COMPILE -c test1.c -o foo.o
     checkstat 'cache hit' 3
     checkstat 'cache miss' 2
 
+    testname="link"
     $CCACHE_COMPILE test1.c -o test 2> /dev/null
     checkstat 'called for link' 1
 
+    testname="multiple"
     $CCACHE_COMPILE -c test1.c test2.c
     checkstat 'multiple source files' 1
 
+    testname="find"
     $CCACHE blahblah -c test1.c 2> /dev/null
     checkstat "couldn't find the compiler" 1 
 
+    testname="bad"
     $CCACHE_COMPILE -c test1.c -I 2> /dev/null
     checkstat 'bad compiler arguments' 1
 
+    testname="c/c++"
     ln -f test1.c test1.ccc
     $CCACHE_COMPILE -c test1.ccc 2> /dev/null
     checkstat 'not a C/C++ file' 1
 
+    testname="unsupported"
     $CCACHE_COMPILE -M foo -c test1.c > /dev/null 2>&1
     checkstat 'unsupported compiler option' 1
 
+    testname="stdout"
     $CCACHE echo foo -c test1.c > /dev/null
     checkstat 'compiler produced stdout' 1
 
+    testname="non-regular"
     $CCACHE_COMPILE -o /dev/zero -c test1.c
     checkstat 'output to a non-regular file' 1
 
+    testname="no-input"
     $CCACHE_COMPILE -c -O2 2> /dev/null
     checkstat 'no input file' 1
 
 
+    testname="CCACHE_DISABLE"
     CCACHE_DISABLE=1 $CCACHE_COMPILE -c test1.c 2> /dev/null
-    checkstat 'cache hit' 3
-
-    $CCACHE_COMPILE -c test1.c 2> /dev/null
-    checkstat 'cache hit' 4
+    checkstat 'cache hit' 3 
+    $CCACHE_COMPILE -c test1.c
+    checkstat 'cache hit' 4 
 
+    testname="CCACHE_CPP2"
     CCACHE_CPP2=1 $CCACHE_COMPILE -c test1.c -O -Wall
-    checkstat 'cache hit' 4
+    checkstat 'cache hit' 4 
     checkstat 'cache miss' 3
 
     CCACHE_CPP2=1 $CCACHE_COMPILE -c test1.c -O -Wall
-    checkstat 'cache hit' 5
+    checkstat 'cache hit' 5 
     checkstat 'cache miss' 3
 
+    testname="CCACHE_NOSTATS"
     CCACHE_NOSTATS=1 $CCACHE_COMPILE -c test1.c -O -Wall
     checkstat 'cache hit' 5
     checkstat 'cache miss' 3
-
+    
+    testname="CCACHE_RECACHE"
     CCACHE_RECACHE=1 $CCACHE_COMPILE -c test1.c -O -Wall
-    checkstat 'cache hit' 5
+    checkstat 'cache hit' 5 
     checkstat 'cache miss' 4
 
     # strictly speaking should be 6 - RECACHE causes a double counting!
-    checkstat 'files in cache' 8
+    checkstat 'files in cache' 8 
     $CCACHE -c > /dev/null
     checkstat 'files in cache' 6
 
+
+    testname="CCACHE_HASHDIR"
     CCACHE_HASHDIR=1 $CCACHE_COMPILE -c test1.c -O -Wall
     checkstat 'cache hit' 5
     checkstat 'cache miss' 5
@@ -138,29 +164,39 @@ basetests() {
 
     checkstat 'files in cache' 8
     
+    testname="comments"
     echo '/* a silly comment */' >> test1.c
     $CCACHE_COMPILE -c test1.c
     checkstat 'cache hit' 6
     checkstat 'cache miss' 6
 
-    echo 'possible unify bug?'
-#    echo '/* another comment */' >> test1.c
-#    CCACHE_UNIFY=1 $CCACHE_COMPILE -c test1.c 2> /dev/null
-#    checkstat 'cache hit' 7
-#    checkstat 'cache miss' 6
-
-
-    echo 'possible -F bug?'
-#    $CCACHE -F 2 -c
-#    $CCACHE -c
-#    checkstat 'files in cache' 2
-
-    checkstat 'files in cache' 10
+    testname="CCACHE_UNIFY"
+    CCACHE_UNIFY=1 $CCACHE_COMPILE -c test1.c
+    checkstat 'cache hit' 6
+    checkstat 'cache miss' 7
+    echo '/* another comment */' >> test1.c
+    CCACHE_UNIFY=1 $CCACHE_COMPILE -c test1.c
+    checkstat 'cache hit' 7
+    checkstat 'cache miss' 7
+
+    testname="cache-size"
+    for f in *.c; do
+       $CCACHE_COMPILE -c $f
+    done
+    checkstat 'cache hit' 7
+    checkstat 'cache miss' 39
+    checkstat 'files in cache' 76
+    $CCACHE -F 48 -c > /dev/null
+    if [ `getstat 'files in cache'` -gt 48 ]; then
+       test_failed '-F test failed'
+    fi
 
+    testname="zero-stats"
     $CCACHE -z > /dev/null
     checkstat 'cache hit' 0
     checkstat 'cache miss' 0
 
+    testname="clear"
     $CCACHE -C > /dev/null
     checkstat 'files in cache' 0
 
@@ -172,18 +208,34 @@ basetests() {
 # main program
 rm -rf $TESTDIR
 mkdir $TESTDIR
-cd $TESTDIR
+cd $TESTDIR || exit 1
 mkdir .ccache
 export CCACHE_DIR=.ccache
 
+testsuite="base"
 CCACHE_COMPILE="$CCACHE $COMPILER"
 basetests
 
+testsuite="link"
 ln -s ../ccache $COMPILER
 CCACHE_COMPILE="./$COMPILER"
 basetests
 
+testsuite="hardlink"
+CCACHE_COMPILE="$CCACHE $COMPILER"
+CCACHE_HARDLINK=1 basetests
+
+testsuite="cpp2"
+CCACHE_COMPILE="$CCACHE $COMPILER"
+CCACHE_CPP2=1 basetests
 
+testsuite="nlevels4"
+CCACHE_COMPILE="$CCACHE $COMPILER"
+CCACHE_NLEVELS=4 basetests
+
+testsuite="nlevels1"
+CCACHE_COMPILE="$CCACHE $COMPILER"
+CCACHE_NLEVELS=1 basetests
 
 cd ..
 rm -rf $TESTDIR