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