Home | History | Annotate | Download | only in tests
      1 #!/bin/sh
      2 
      3 if [ ! -z "$srcdir" ]; then
      4    testdir=$srcdir/glsl/glcpp/tests
      5    outdir=`pwd`/glsl/glcpp/tests
      6    glcpp=`pwd`/glsl/glcpp/glcpp
      7 else
      8    testdir=.
      9    outdir=.
     10    glcpp=../glcpp
     11 fi
     12 
     13 trap 'rm $test.valgrind-errors; exit 1' INT QUIT
     14 
     15 usage ()
     16 {
     17     cat <<EOF
     18 Usage: glcpp [options...]
     19 
     20 Run the test suite for mesa's GLSL pre-processor.
     21 
     22 Valid options include:
     23 
     24 	--testdir=<DIR>	Use tests in the given <DIR> (default is ".")
     25 	--valgrind	Run the test suite a second time under valgrind
     26 EOF
     27 }
     28 
     29 test_specific_args ()
     30 {
     31     test="$1"
     32 
     33     tr "\r" "\n" < "$test" | grep 'glcpp-args:' | sed -e 's,^.*glcpp-args: *,,'
     34 }
     35 
     36 # Parse command-line options
     37 for option; do
     38     case "${option}" in
     39         "--help")
     40             usage
     41             exit 0
     42             ;;
     43         "--valgrind")
     44 	    do_valgrind=yes
     45             ;;
     46         "--testdir="*)
     47             testdir="${option#--testdir=}"
     48             outdir="${outdir}/${option#--testdir=}"
     49             ;;
     50         *)
     51 	    echo "Unrecognized option: $option" >&2
     52 	    echo >&2
     53 	    usage
     54 	    exit 1
     55             ;;
     56         esac
     57 done
     58 
     59 total=0
     60 pass=0
     61 clean=0
     62 
     63 mkdir -p $outdir
     64 
     65 echo "====== Testing for correctness ======"
     66 for test in $testdir/*.c; do
     67     out=$outdir/${test##*/}.out
     68 
     69     printf "Testing $test... > $out ($test.expected) "
     70     $glcpp $(test_specific_args $test) < $test > $out 2>&1
     71     total=$((total+1))
     72     if cmp $test.expected $out >/dev/null 2>&1; then
     73 	echo "PASS"
     74 	pass=$((pass+1))
     75     else
     76 	echo "FAIL"
     77 	diff -u $test.expected $out
     78     fi
     79 done
     80 
     81 echo ""
     82 echo "$pass/$total tests returned correct results"
     83 echo ""
     84 
     85 if [ "$do_valgrind" = "yes" ]; then
     86     echo "====== Testing for valgrind cleanliness ======"
     87     for test in $testdir/*.c; do
     88 	printf "Testing $test with valgrind..."
     89 	valgrind --error-exitcode=31 --log-file=$test.valgrind-errors $glcpp $(test_specific_args $test) < $test >/dev/null 2>&1
     90 	if [ "$?" = "31" ]; then
     91 	    echo "ERRORS"
     92 	    cat $test.valgrind-errors
     93 	else
     94 	    echo "CLEAN"
     95 	    clean=$((clean+1))
     96 	    rm $test.valgrind-errors
     97 	fi
     98     done
     99 
    100     echo ""
    101     echo "$pass/$total tests returned correct results"
    102     echo "$clean/$total tests are valgrind-clean"
    103 fi
    104 
    105 if [ "$pass" = "$total" ] && [ "$do_valgrind" != "yes" ] || [ "$pass" = "$total" ]; then
    106     exit 0
    107 else
    108     exit 1
    109 fi
    110 
    111