summaryrefslogtreecommitdiffstats
path: root/src/glsl/glcpp/tests/glcpp-test
blob: 1f371398f69647cc215c6ddfc792267829b8b21d (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
#!/bin/sh

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:

	--valgrind	Run the test suite a second time under valgrind
EOF
}

# Parse command-line options
for option; do
    if [ "${option}" = '--help' ] ; then
	usage
	exit 0
    elif [ "${option}" = '--valgrind' ] ; then
	do_valgrind=yes
    else
	echo "Unrecognized option: $option" >&2
	echo >&2
	usage
	exit 1
    fi
done

total=0
pass=0
clean=0

builddir=`pwd`
testdir=`dirname $0`
cd $testdir

echo "====== Testing for correctness ======"
for test in *.c; do
    echo -n "Testing $test..."
    $builddir/glcpp < $test > $test.out 2>&1
    total=$((total+1))
    if cmp $test.expected $test.out >/dev/null 2>&1; then
	echo "PASS"
	pass=$((pass+1))
    else
	echo "FAIL"
	diff -u $test.expected $test.out
    fi
done

echo ""
echo "$pass/$total tests returned correct results"
echo ""

if [ "$do_valgrind" = "yes" ]; then
    echo "====== Testing for valgrind cleanliness ======"
    for test in *.c; do
	echo -n "Testing $test with valgrind..."
	valgrind --error-exitcode=31 --log-file=$test.valgrind-errors ../glcpp < $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