• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2
3if [ -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`/../../../
14fi
15
16testdir=$srcdir/glsl/glcpp/tests
17outdir=$abs_builddir/glsl/glcpp/tests
18glcpp=$abs_builddir/glsl/glcpp/glcpp
19
20trap 'rm $test.valgrind-errors; exit 1' INT QUIT
21
22usage ()
23{
24    cat <<EOF
25Usage: `basename "$0"` [options...]
26
27Run the test suite for mesa's GLSL pre-processor.
28
29Valid 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
33EOF
34}
35
36test_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
44for 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
64done
65
66total=0
67pass=0
68clean=0
69
70mkdir -p $outdir
71
72echo "====== Testing for correctness ======"
73for 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
86done
87
88if [ $total -eq 0 ]; then
89    echo "Could not find any tests."
90    exit 1
91fi
92
93echo ""
94echo "$pass/$total tests returned correct results"
95echo ""
96
97if [ "$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"
115fi
116
117if [ "$pass" = "$total" ] && [ "$do_valgrind" != "yes" ] || [ "$pass" = "$total" ]; then
118    exit 0
119else
120    exit 1
121fi
122
123