Home | History | Annotate | Download | only in tests
      1 #!/bin/sh
      2 
      3 trap 'rm $test.valgrind-errors; exit 1' INT QUIT
      4 
      5 usage ()
      6 {
      7     cat <<EOF
      8 Usage: glcpp [options...]
      9 
     10 Run the test suite for mesa's GLSL pre-processor.
     11 
     12 Valid options include:
     13 
     14 	--valgrind	Run the test suite a second time under valgrind
     15 EOF
     16 }
     17 
     18 # Parse command-line options
     19 for option; do
     20     if [ "${option}" = '--help' ] ; then
     21 	usage
     22 	exit 0
     23     elif [ "${option}" = '--valgrind' ] ; then
     24 	do_valgrind=yes
     25     else
     26 	echo "Unrecognized option: $option" >&2
     27 	echo >&2
     28 	usage
     29 	exit 1
     30     fi
     31 done
     32 
     33 total=0
     34 pass=0
     35 clean=0
     36 
     37 echo "====== Testing for correctness ======"
     38 for test in *.c; do
     39     echo -n "Testing $test..."
     40     ../glcpp < $test > $test.out 2>&1
     41     total=$((total+1))
     42     if cmp $test.expected $test.out >/dev/null 2>&1; then
     43 	echo "PASS"
     44 	pass=$((pass+1))
     45     else
     46 	echo "FAIL"
     47 	diff -u $test.expected $test.out
     48     fi
     49 done
     50 
     51 echo ""
     52 echo "$pass/$total tests returned correct results"
     53 echo ""
     54 
     55 if [ "$do_valgrind" = "yes" ]; then
     56     echo "====== Testing for valgrind cleanliness ======"
     57     for test in *.c; do
     58 	echo -n "Testing $test with valgrind..."
     59 	valgrind --error-exitcode=31 --log-file=$test.valgrind-errors ../glcpp < $test >/dev/null 2>&1
     60 	if [ "$?" = "31" ]; then
     61 	    echo "ERRORS"
     62 	    cat $test.valgrind-errors
     63 	else
     64 	    echo "CLEAN"
     65 	    clean=$((clean+1))
     66 	    rm $test.valgrind-errors
     67 	fi
     68     done
     69 
     70     echo ""
     71     echo "$pass/$total tests returned correct results"
     72     echo "$clean/$total tests are valgrind-clean"
     73 fi
     74 
     75 if [ "$pass" = "$total" ] && [ "$do_valgrind" != "yes" ] || [ "$pass" = "$total" ]; then
     76     exit 0
     77 else
     78     exit 1
     79 fi
     80 
     81