glsl/tests/optimization-test: add fallback srcdir/abs_builddir defines
[mesa.git] / src / compiler / glsl / tests / optimization-test.sh
1 #!/bin/sh
2
3 if [ ! -z "$srcdir" ]; then
4 compare_ir=`pwd`/tests/compare_ir.py
5 else
6 compare_ir=./compare_ir.py
7 fi
8
9 if [ -z "$PYTHON2" ]; then
10 PYTHON2=python2
11 fi
12
13 which $PYTHON2 >/dev/null
14 if [ $? -ne 0 ]; then
15 echo "Could not find python2. Make sure that PYTHON2 variable is correctly set."
16 exit 1
17 fi
18
19 if [ -z "$srcdir" -o -z "$abs_builddir" ]; then
20 echo ""
21 echo "Warning: you're invoking the script manually and things may fail."
22 echo "Attempting to determine/set srcdir and abs_builddir variables."
23 echo ""
24
25 # Variable should point to the Makefile.glsl.am
26 srcdir=./../../
27 cd `dirname "$0"`
28 # Variable should point to the folder two levels above glsl_test
29 abs_builddir=`pwd`/../../
30 fi
31
32 total=0
33 pass=0
34
35 echo "====== Generating tests ======"
36 for dir in tests/*/; do
37 if [ -e "${dir}create_test_cases.py" ]; then
38 cd $dir; $PYTHON2 create_test_cases.py; cd ..
39 fi
40 echo "$dir"
41 done
42
43 echo "====== Testing optimization passes ======"
44 for test in `find . -iname '*.opt_test'`; do
45 echo -n "Testing $test..."
46 (cd `dirname "$test"`; ./`basename "$test"`) > "$test.out" 2>&1
47 total=$((total+1))
48 if $PYTHON2 $PYTHON_FLAGS $compare_ir "$test.expected" "$test.out" >/dev/null 2>&1; then
49 echo "PASS"
50 pass=$((pass+1))
51 else
52 echo "FAIL"
53 $PYTHON2 $PYTHON_FLAGS $compare_ir "$test.expected" "$test.out"
54 fi
55 done
56
57 echo ""
58 echo "$pass/$total tests returned correct results"
59 echo ""
60
61 if [ $pass = $total ]; then
62 exit 0
63 else
64 exit 1
65 fi