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-07-02 17:14:51 -07:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
2014-07-03 13:25:47 -07:00
|
|
|
# The build system runs this test from a different working directory, and may
|
|
|
|
|
# be in a build directory entirely separate from the source. So if the
|
|
|
|
|
# "srcdir" variable is set, we must use it to locate the test files and the
|
|
|
|
|
# glcpp-test script.
|
|
|
|
|
|
|
|
|
|
if [ ! -z "$srcdir" ]; then
|
|
|
|
|
testdir="$srcdir/glcpp/tests"
|
|
|
|
|
glcpp_test="$srcdir/glcpp/tests/glcpp-test"
|
|
|
|
|
else
|
|
|
|
|
testdir=.
|
|
|
|
|
glcpp_test=./glcpp-test
|
|
|
|
|
fi
|
|
|
|
|
|
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-07-02 17:14:51 -07:00
|
|
|
total=0
|
|
|
|
|
pass=0
|
|
|
|
|
|
|
|
|
|
# This supports a pipe that doesn't destroy the exit status of first command
|
|
|
|
|
#
|
|
|
|
|
# http://unix.stackexchange.com/questions/14270/get-exit-status-of-process-thats-piped-to-another
|
|
|
|
|
stdintoexitstatus() {
|
|
|
|
|
read exitstatus
|
|
|
|
|
return $exitstatus
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
run_test ()
|
|
|
|
|
{
|
|
|
|
|
cmd="$1"
|
|
|
|
|
|
|
|
|
|
total=$((total+1))
|
|
|
|
|
|
|
|
|
|
if [ "$VERBOSE" = "yes" ]; then
|
|
|
|
|
if $cmd; then
|
|
|
|
|
echo "PASS"
|
|
|
|
|
pass=$((pass+1))
|
|
|
|
|
else
|
|
|
|
|
echo "FAIL"
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
# This is "$cmd | tail -2" but with the exit status of "$cmd" not "tail -2"
|
|
|
|
|
if (((($cmd; echo $? >&3) | tail -2 | head -1 >&4) 3>&1) | stdintoexitstatus) 4>&1; then
|
|
|
|
|
echo "PASS"
|
|
|
|
|
pass=$((pass+1))
|
|
|
|
|
else
|
|
|
|
|
echo "FAIL"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
usage ()
|
|
|
|
|
{
|
|
|
|
|
cat <<EOF
|
|
|
|
|
Usage: glcpp-cr-lf [options...]
|
|
|
|
|
|
|
|
|
|
Run the entire glcpp-test suite several times, each time with each source
|
|
|
|
|
file transformed to use a non-standard line-termination character. Each
|
|
|
|
|
entire run with a different line-termination character is considered a
|
|
|
|
|
single test.
|
|
|
|
|
|
|
|
|
|
Valid options include:
|
|
|
|
|
|
|
|
|
|
-v|--verbose Print all output from the various sub-tests
|
|
|
|
|
EOF
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Parse command-line options
|
|
|
|
|
for option; do
|
|
|
|
|
case "${option}" in
|
|
|
|
|
-v|--verbose)
|
|
|
|
|
VERBOSE=yes;
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
echo "Unrecognized option: $option" >&2
|
|
|
|
|
echo >&2
|
|
|
|
|
usage
|
|
|
|
|
exit 1
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
# All tests depend on the .out files being present. So first do a
|
|
|
|
|
# normal run of the test suite, (silently) just to create the .out
|
|
|
|
|
# files as a side effect.
|
2014-07-03 13:25:47 -07:00
|
|
|
rm -rf ./subtest-lf
|
|
|
|
|
mkdir subtest-lf
|
|
|
|
|
for file in "$testdir"/*.c; do
|
|
|
|
|
base=$(basename "$file")
|
|
|
|
|
cp "$file" subtest-lf
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
${glcpp_test} --testdir=subtest-lf >/dev/null 2>&1
|
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-07-02 17:14:51 -07:00
|
|
|
|
|
|
|
|
echo "===== Testing with \\\\r line terminators (old Mac format) ====="
|
|
|
|
|
|
|
|
|
|
# Prepare test files with '\r' instead of '\n'
|
|
|
|
|
rm -rf ./subtest-cr
|
|
|
|
|
mkdir subtest-cr
|
2014-07-03 13:25:47 -07:00
|
|
|
for file in "$testdir"/*.c; do
|
|
|
|
|
base=$(basename "$file")
|
|
|
|
|
tr "\n" "\r" < "$file" > subtest-cr/"$base"
|
|
|
|
|
cp subtest-lf/"$base".out subtest-cr/"$base".expected
|
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-07-02 17:14:51 -07:00
|
|
|
done
|
|
|
|
|
|
2014-07-03 13:25:47 -07:00
|
|
|
run_test "${glcpp_test} --testdir=subtest-cr"
|
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-07-02 17:14:51 -07:00
|
|
|
|
|
|
|
|
echo "===== Testing with \\\\r\\\\n line terminators (DOS format) ====="
|
|
|
|
|
|
|
|
|
|
# Prepare test files with '\r\n' instead of '\n'
|
|
|
|
|
rm -rf ./subtest-cr-lf
|
|
|
|
|
mkdir subtest-cr-lf
|
2014-07-03 13:25:47 -07:00
|
|
|
for file in "$testdir"/*.c; do
|
|
|
|
|
base=$(basename "$file")
|
|
|
|
|
sed -e 's/$/\r/' < "$file" > subtest-cr-lf/"$base"
|
|
|
|
|
cp subtest-lf/"$base".out subtest-cr-lf/"$base".expected
|
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-07-02 17:14:51 -07:00
|
|
|
done
|
|
|
|
|
|
2014-07-03 13:25:47 -07:00
|
|
|
run_test "${glcpp_test} --testdir=subtest-cr-lf"
|
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-07-02 17:14:51 -07:00
|
|
|
|
|
|
|
|
echo "===== Testing with \\\\n\\\\r (bizarre, but allowed by GLSL spec.) ====="
|
|
|
|
|
|
|
|
|
|
# Prepare test files with '\n\r' instead of '\n'
|
|
|
|
|
rm -rf ./subtest-lf-cr
|
|
|
|
|
mkdir subtest-lf-cr
|
2014-07-03 13:25:47 -07:00
|
|
|
for file in "$testdir"/*.c; do
|
|
|
|
|
base=$(basename "$file")
|
|
|
|
|
tr "\n" "\r" < "$file" | sed -e 's/\r/\n\r/g' > subtest-lf-cr/"$base"
|
|
|
|
|
cp subtest-lf/"$base".out subtest-lf-cr/"$base".expected
|
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-07-02 17:14:51 -07:00
|
|
|
done
|
|
|
|
|
|
2014-07-03 13:25:47 -07:00
|
|
|
run_test "${glcpp_test} --testdir=subtest-lf-cr"
|
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-07-02 17:14:51 -07:00
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
|
echo "$pass/$total tests returned correct results"
|
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
|
|
if [ "$pass" = "$total" ]; then
|
|
|
|
|
exit 0
|
|
|
|
|
else
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|