• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2
3if [ ! -z "$srcdir" ]; then
4   testdir=$srcdir/glsl/glcpp/tests
5   outdir=`pwd`/glsl/glcpp/tests
6   glcpp=`pwd`/glsl/glcpp/glcpp
7else
8   testdir=.
9   outdir=.
10   glcpp=../glcpp
11fi
12
13trap 'rm $test.valgrind-errors; exit 1' INT QUIT
14
15usage ()
16{
17    cat <<EOF
18Usage: glcpp [options...]
19
20Run the test suite for mesa's GLSL pre-processor.
21
22Valid 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
26EOF
27}
28
29test_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
37for 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
57done
58
59total=0
60pass=0
61clean=0
62
63mkdir -p $outdir
64
65echo "====== Testing for correctness ======"
66for 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
79done
80
81echo ""
82echo "$pass/$total tests returned correct results"
83echo ""
84
85if [ "$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"
103fi
104
105if [ "$pass" = "$total" ] && [ "$do_valgrind" != "yes" ] || [ "$pass" = "$total" ]; then
106    exit 0
107else
108    exit 1
109fi
110
111