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