[Mesa-dev] [PATCH 06/10] glsl: Add "make check" tests for correct handling of #line directives

Carl Worth cworth at cworth.org
Sat Dec 8 13:43:41 PST 2012


Verifing that both the source number and line number get correctly reflected
into error messages.

Note that this is distinct from existing testing of the proeprocessor,
(in glcpp/tests), since here we are testing that the GLSL compiler
itself is correctly handling those #line directives that are emitted
by the preprocessor.
---
 src/glsl/tests/Makefile.am                         |    1 +
 src/glsl/tests/directives-test                     |   33 ++++++++++++++++++++
 src/glsl/tests/directives/.gitignore               |    1 +
 .../00-line-number-in-error-message.glsl           |    8 +++++
 .../00-line-number-in-error-message.glsl.expected  |    2 ++
 .../01-hash-line-number-in-error-message.glsl      |   11 +++++++
 ...hash-line-number-in-error-message.glsl.expected |    2 ++
 .../directives/02-hash-line-number-increments.glsl |   13 ++++++++
 .../02-hash-line-number-increments.glsl.expected   |    2 ++
 .../directives/03-hash-line-source-number.glsl     |   11 +++++++
 .../03-hash-line-source-number.glsl.expected       |    2 ++
 11 files changed, 86 insertions(+)
 create mode 100755 src/glsl/tests/directives-test
 create mode 100644 src/glsl/tests/directives/.gitignore
 create mode 100644 src/glsl/tests/directives/00-line-number-in-error-message.glsl
 create mode 100644 src/glsl/tests/directives/00-line-number-in-error-message.glsl.expected
 create mode 100644 src/glsl/tests/directives/01-hash-line-number-in-error-message.glsl
 create mode 100644 src/glsl/tests/directives/01-hash-line-number-in-error-message.glsl.expected
 create mode 100644 src/glsl/tests/directives/02-hash-line-number-increments.glsl
 create mode 100644 src/glsl/tests/directives/02-hash-line-number-increments.glsl.expected
 create mode 100644 src/glsl/tests/directives/03-hash-line-source-number.glsl
 create mode 100644 src/glsl/tests/directives/03-hash-line-source-number.glsl.expected

diff --git a/src/glsl/tests/Makefile.am b/src/glsl/tests/Makefile.am
index 957bb55..5a6380d 100644
--- a/src/glsl/tests/Makefile.am
+++ b/src/glsl/tests/Makefile.am
@@ -9,6 +9,7 @@ TESTS_ENVIRONMENT= \
 	export PYTHON_FLAGS=$(PYTHON_FLAGS);
 
 TESTS = \
+	directives-test \
 	optimization-test \
 	ralloc-test \
 	uniform-initializer-test
diff --git a/src/glsl/tests/directives-test b/src/glsl/tests/directives-test
new file mode 100755
index 0000000..9e33cf4
--- /dev/null
+++ b/src/glsl/tests/directives-test
@@ -0,0 +1,33 @@
+#!/bin/bash
+
+total=0
+pass=0
+
+# These tests are for preprocessor directives that are emitted from
+# the preprocessor itself (such as #line, #version, #extension, and
+# #pragma) as opposed to those which are handled and removed by the
+# preprocesor (such as #define, #ifdef, #if, #elid, #endif, etc.)
+
+echo "====== Testing preprocessor directives ======"
+for test in directives/*.glsl; do
+    echo -n "Testing $test..."
+    ../builtin_compiler/builtin_compiler "$test" 2>&1 | grep -v "^Info log" > "$test.out"
+    total=$((total+1))
+    if diff "$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 [[ $pass == $total ]]; then
+    exit 0
+else
+    exit 1
+fi
diff --git a/src/glsl/tests/directives/.gitignore b/src/glsl/tests/directives/.gitignore
new file mode 100644
index 0000000..f47cb20
--- /dev/null
+++ b/src/glsl/tests/directives/.gitignore
@@ -0,0 +1 @@
+*.out
diff --git a/src/glsl/tests/directives/00-line-number-in-error-message.glsl b/src/glsl/tests/directives/00-line-number-in-error-message.glsl
new file mode 100644
index 0000000..c994bb7
--- /dev/null
+++ b/src/glsl/tests/directives/00-line-number-in-error-message.glsl
@@ -0,0 +1,8 @@
+void main(void)
+{
+      /* Syntax error should be reported on source string 0, line 7.
+       * This is just a simple test of line numbers being tracked
+       * without any #line directives.
+       */
+      if (; /* Syntax error on line 7 */
+}
diff --git a/src/glsl/tests/directives/00-line-number-in-error-message.glsl.expected b/src/glsl/tests/directives/00-line-number-in-error-message.glsl.expected
new file mode 100644
index 0000000..1251474
--- /dev/null
+++ b/src/glsl/tests/directives/00-line-number-in-error-message.glsl.expected
@@ -0,0 +1,2 @@
+0:7(6): error: syntax error, unexpected ';'
+
diff --git a/src/glsl/tests/directives/01-hash-line-number-in-error-message.glsl b/src/glsl/tests/directives/01-hash-line-number-in-error-message.glsl
new file mode 100644
index 0000000..074669b
--- /dev/null
+++ b/src/glsl/tests/directives/01-hash-line-number-in-error-message.glsl
@@ -0,0 +1,11 @@
+void main(void)
+{
+
+      /* In this test, we verify that a #line directive causes the
+       * syntax error on the subsequent line to be reported against the
+       * line number in the #line directive, (so source 0, line 17).
+       */
+
+#line 17
+      if (; /* Syntax error on line 17 */
+}
diff --git a/src/glsl/tests/directives/01-hash-line-number-in-error-message.glsl.expected b/src/glsl/tests/directives/01-hash-line-number-in-error-message.glsl.expected
new file mode 100644
index 0000000..e64182d
--- /dev/null
+++ b/src/glsl/tests/directives/01-hash-line-number-in-error-message.glsl.expected
@@ -0,0 +1,2 @@
+0:17(6): error: syntax error, unexpected ';'
+
diff --git a/src/glsl/tests/directives/02-hash-line-number-increments.glsl b/src/glsl/tests/directives/02-hash-line-number-increments.glsl
new file mode 100644
index 0000000..eeca49e
--- /dev/null
+++ b/src/glsl/tests/directives/02-hash-line-number-increments.glsl
@@ -0,0 +1,13 @@
+void main(void)
+{
+
+      /* In this test, we verify that line numbers are correctly
+       * incremented following a #line directive. So the syntax
+       * error should be reported on source 0, line 21.
+       */
+
+#line 19
+      /* line 19 */
+      /* line 20 */
+      if (; /* Syntax error on line 21 */
+}
diff --git a/src/glsl/tests/directives/02-hash-line-number-increments.glsl.expected b/src/glsl/tests/directives/02-hash-line-number-increments.glsl.expected
new file mode 100644
index 0000000..673f99f
--- /dev/null
+++ b/src/glsl/tests/directives/02-hash-line-number-increments.glsl.expected
@@ -0,0 +1,2 @@
+0:21(6): error: syntax error, unexpected ';'
+
diff --git a/src/glsl/tests/directives/03-hash-line-source-number.glsl b/src/glsl/tests/directives/03-hash-line-source-number.glsl
new file mode 100644
index 0000000..fea94cf
--- /dev/null
+++ b/src/glsl/tests/directives/03-hash-line-source-number.glsl
@@ -0,0 +1,11 @@
+void main(void)
+{
+
+      /* In this test, we verify that a source number in a #line
+       * directive is reflected in a subsequent error message.
+       * Syntax error should be reported on line 3 of source 42.
+       */
+
+#line 3 42
+      if (; /* Syntax error on line 3 of source 42 */
+}
diff --git a/src/glsl/tests/directives/03-hash-line-source-number.glsl.expected b/src/glsl/tests/directives/03-hash-line-source-number.glsl.expected
new file mode 100644
index 0000000..f687b1f
--- /dev/null
+++ b/src/glsl/tests/directives/03-hash-line-source-number.glsl.expected
@@ -0,0 +1,2 @@
+42:3(6): error: syntax error, unexpected ';'
+
-- 
1.7.10



More information about the mesa-dev mailing list