5069235868af946d6562219b5b3f55a4ee2f7ed1
[mesa.git] / src / compiler / glsl / tests / optimization-test.sh
1 #!/bin/sh
2
3 if [ -z "$PYTHON2" ]; then
4 PYTHON2=python2
5 fi
6
7 which $PYTHON2 >/dev/null
8 if [ $? -ne 0 ]; then
9 echo "Could not find python2. Make sure that PYTHON2 variable is correctly set."
10 exit 1
11 fi
12
13 if [ -z "$srcdir" -o -z "$abs_builddir" ]; then
14 echo ""
15 echo "Warning: you're invoking the script manually and things may fail."
16 echo "Attempting to determine/set srcdir and abs_builddir variables."
17 echo ""
18
19 # Variable should point to the Makefile.glsl.am
20 srcdir=./../../
21 cd `dirname "$0"`
22 # Variable should point to the folder two levels above glsl_test
23 abs_builddir=`pwd`/../../
24 fi
25
26 compare_ir=$srcdir/glsl/tests/compare_ir.py
27
28 total=0
29 pass=0
30 has_tests=0
31
32 # Store our location before we start diving into subdirectories.
33 ORIGDIR=`pwd`
34 echo "====== Generating tests ======"
35 for dir in $srcdir/glsl/tests/*/; do
36 if [ -e "${dir}create_test_cases.py" ]; then
37 # construct the correct builddir
38 completedir="$abs_builddir/glsl/tests/`echo ${dir} | sed 's|.*/glsl/tests/||g'`"
39 mkdir -p $completedir
40 cd $dir;
41 $PYTHON2 create_test_cases.py --runner $abs_builddir/glsl/glsl_test --outdir $completedir;
42 if [ $? -eq 0 ]; then
43 has_tests=1
44 fi
45 cd ..
46 fi
47 echo "$dir"
48 done
49 cd "$ORIGDIR"
50
51 if [ $has_tests -eq 0 ]; then
52 echo "Could not generate any tests."
53 exit 1
54 fi
55
56 if [ ! -f "$compare_ir" ]; then
57 echo "Could not find compare_ir. Make sure that srcdir variable is correctly set."
58 exit 1
59 fi
60
61 echo "====== Testing optimization passes ======"
62 for test in `find . -iname '*.opt_test'`; do
63 echo -n "Testing $test..."
64 ./$test > "$test.out" 2>&1
65 total=$((total+1))
66 if $PYTHON2 $PYTHON_FLAGS $compare_ir "$test.expected" "$test.out" >/dev/null 2>&1; then
67 echo "PASS"
68 pass=$((pass+1))
69 else
70 echo "FAIL"
71 $PYTHON2 $PYTHON_FLAGS $compare_ir "$test.expected" "$test.out"
72 fi
73 done
74
75 if [ $total -eq 0 ]; then
76 echo "Could not find any tests."
77 exit 1
78 fi
79
80 echo ""
81 echo "$pass/$total tests returned correct results"
82 echo ""
83
84 if [ $pass = $total ]; then
85 exit 0
86 else
87 exit 1
88 fi