[Mesa-dev] [PATCH] glsl/glcpp: Integrate recent glcpp-test-cr-lf test into "make check"

Carl Worth cworth at cworth.org
Thu Jul 3 13:49:04 PDT 2014

Beyond just listing this in the TESTS variable in Makefile.am, only minor
changes were needed to make this work. The primary issue is that the build
system runs the test script from a different directory than the script
itself. So we have to use the $srcdir variable to find the test input files.

Using $srcdir in this way also ensures that this test works when using an
out-of-tree build.

 > The new testing is not yet hooked up to "make check", but must currently be
 > manually invoked by running ./glcpp-test-cr-lf.

 And this patch fixes that, of course.

 I'll feel much better knowing that if future changes to glcpp break the
 support for shaders with alternate newlines, that at least "make check"
 should catch that.


 src/glsl/Makefile.am                  |  1 +
 src/glsl/glcpp/tests/glcpp-test-cr-lf | 40 ++++++++++++++++++++++++-----------
 2 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/src/glsl/Makefile.am b/src/glsl/Makefile.am
index 00261fd..866ef97 100644
--- a/src/glsl/Makefile.am
+++ b/src/glsl/Makefile.am
 include Makefile.sources
 TESTS = glcpp/tests/glcpp-test				\
+	glcpp/tests/glcpp-test-cr-lf			\
 	tests/general-ir-test				\
 	tests/optimization-test				\
 	tests/ralloc-test				\
diff --git a/src/glsl/glcpp/tests/glcpp-test-cr-lf b/src/glsl/glcpp/tests/glcpp-test-cr-lf
index 708fce5..918f857 100755
--- a/src/glsl/glcpp/tests/glcpp-test-cr-lf
+++ b/src/glsl/glcpp/tests/glcpp-test-cr-lf
@@ -1,5 +1,18 @@
+# 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"
+   testdir=.
+   glcpp_test=./glcpp-test
@@ -76,36 +89,39 @@ echo "===== Testing with \\\\r line terminators (old Mac format) ====="
 # Prepare test files with '\r' instead of '\n'
 rm -rf ./subtest-cr
 mkdir subtest-cr
-for file in *.c; do
-    tr "\n" "\r" < "$file" > subtest-cr/"$file"
-    cp "$file".out subtest-cr/"$file".expected
+for file in "$testdir"/*.c; do
+    base=$(basename "$file")
+    tr "\n" "\r" < "$file" > subtest-cr/"$base"
+    cp "$file".out subtest-cr/"$base".expected
-run_test "./glcpp-test --testdir=subtest-cr"
+run_test "${glcpp_test} --testdir=subtest-cr"
 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
-for file in *.c; do
-    sed -e 's/$/\r/' < "$file" > subtest-cr-lf/"$file"
-    cp "$file".out subtest-cr-lf/"$file".expected
+for file in "$testdir"/*.c; do
+    base=$(basename "$file")
+    sed -e 's/$/\r/' < "$file" > subtest-cr-lf/"$base"
+    cp "$file".out subtest-cr-lf/"$base".expected
-run_test "./glcpp-test --testdir=subtest-cr-lf"
+run_test "${glcpp_test} --testdir=subtest-cr-lf"
 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
-for file in *.c; do
-    tr "\n" "\r" < "$file" | sed -e 's/\r/\n\r/g' > subtest-lf-cr/"$file"
-    cp "$file".out subtest-lf-cr/"$file".expected
+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 "$file".out subtest-lf-cr/"$base".expected
-run_test "./glcpp-test --testdir=subtest-lf-cr"
+run_test "${glcpp_test} --testdir=subtest-lf-cr"
 echo ""
 echo "$pass/$total tests returned correct results"

More information about the mesa-dev mailing list