mesa/src/glsl/glcpp/tests/glcpp-test
Carl Worth f4ddd026c6 glsl/glcpp: Add test script for testing various line-termination characters
The GLSL specification has a very broad definition of what is a
newline. Namely, it can be the carriage-return character, '\r', the newline
character, '\n', or any combination of the two, (though in combination, the
two are treated as a single newline).

Here, we add a new test-runner, glcpp-test-cr-lf, that, for each possible
line-termination combination, runs through the existing test suite with all
source files modified to use those line-termination characters. Instead of
using the .expected files for this, this script assumes that the regular test
suite has been run already and expects the output to match the .out
files. This avoids getting 4 test failures for any one bug, and instead will
hopefully only report bugs actually related to the line-termination
characters.

The new testing is not yet integrated into "make check". For that, some
munging of the testdir option will be necessary, (to support "make check" with
out-of-tree builds). For now, the scripts can just be run directly by hand.

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2014-08-07 16:08:29 -07:00

103 lines
2 KiB
Bash
Executable file

#!/bin/sh
if [ ! -z "$srcdir" ]; then
testdir=$srcdir/glcpp/tests
glcpp=`pwd`/glcpp/glcpp
else
testdir=.
glcpp=../glcpp
fi
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"
grep 'glcpp-args:' "$test" | 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=}"
;;
*)
echo "Unrecognized option: $option" >&2
echo >&2
usage
exit 1
;;
esac
done
total=0
pass=0
clean=0
echo "====== Testing for correctness ======"
for test in $testdir/*.c; do
echo -n "Testing $test..."
$glcpp $(test_specific_args $test) < $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 $testdir/*.c; do
echo -n "Testing $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