1#!/bin/sh
2
3trap 'rm $test.valgrind-errors; exit 1' INT QUIT
4
5usage ()
6{
7    cat <<EOF
8Usage: glcpp [options...]
9
10Run the test suite for mesa's GLSL pre-processor.
11
12Valid options include:
13
14	--valgrind	Run the test suite a second time under valgrind
15EOF
16}
17
18# Parse command-line options
19for 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
31done
32
33total=0
34pass=0
35clean=0
36
37echo "====== Testing for correctness ======"
38for 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
49done
50
51echo ""
52echo "$pass/$total tests returned correct results"
53echo ""
54
55if [ "$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"
73fi
74
75if [ "$pass" = "$total" ] && [ "$do_valgrind" != "yes" ] || [ "$pass" = "$total" ]; then
76    exit 0
77else
78    exit 1
79fi
80
81