diff mbox

[2/3] add generated_tests/gen_non-lvalue_es-tests.py

Message ID 1364932713-8221-2-git-send-email-tom.gall@linaro.org
State New
Headers show

Commit Message

Tom Gall April 2, 2013, 7:58 p.m. UTC
This adds a series l-value tests for glslparsertest. This new
python code creates glsl es versions of the tests. This "new"
code was directly based on generated_tests/gen_non-lvalue_tests.py.
The new es version outputs to generated_tests/spec/glsl-es-1.00.

Signed-off-by: Tom Gall <tom.gall@linaro.org>
---
 generated_tests/gen_non-lvalue_es-tests.py |  174 ++++++++++++++++++++++++++++
 1 file changed, 174 insertions(+)
 create mode 100644 generated_tests/gen_non-lvalue_es-tests.py

Comments

Eric Anholt May 3, 2013, 10:34 p.m. UTC | #1
Tom Gall <tom.gall@linaro.org> writes:

> This adds a series l-value tests for glslparsertest. This new
> python code creates glsl es versions of the tests. This "new"
> code was directly based on generated_tests/gen_non-lvalue_tests.py.
> The new es version outputs to generated_tests/spec/glsl-es-1.00.

Given that the functional code change from the file you copied from is:

-class Test(object):
+class TestES1(object):

-                            'glsl-1.10',
+                            'glsl-es-1.00',

- * glsl_version: 1.10
+ * glsl_version: 1.00

-                              yield Test(type_name, op, usage, shader_target)
+                              yield TestES1(type_name, op, usage, shader_target)

and the spec quote being slightly different between 1.00 and 1.10, this
should pretty clearly be a small addition to the existing generator.
diff mbox

Patch

diff --git a/generated_tests/gen_non-lvalue_es-tests.py b/generated_tests/gen_non-lvalue_es-tests.py
new file mode 100644
index 0000000..cc254fd
--- /dev/null
+++ b/generated_tests/gen_non-lvalue_es-tests.py
@@ -0,0 +1,174 @@ 
+# coding=utf-8
+#
+# Copyright © 2012 Intel Corporation
+# Copyright © 2013 Linaro Inc
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice (including the next
+# paragraph) shall be included in all copies or substantial portions of the
+# Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+# DEALINGS IN THE SOFTWARE.
+
+import os
+
+
+class TestES1(object):
+    def __init__(self, type_name, op, usage, shader_target):
+        self.type_name = type_name
+        self.op = op
+        self.usage = usage
+        self.shader_target = shader_target
+
+    def filename(self):
+        if self.op == "++t":
+            name_base = "preincrement"
+        elif self.op == "--t":
+            name_base = "predecrement"
+        elif self.op == "t++":
+            name_base = "postincrement"
+        elif self.op == "t--":
+            name_base = "postdecrement"
+
+        return os.path.join('spec',
+                            'glsl-es-1.00',
+                            'compiler',
+                            'expressions',
+                            '{0}-{1}-non-lvalue-for-{2}.{3}'.format(
+                                name_base, self.type_name, self.usage,
+                                self.shader_target))
+
+    def generate(self):
+        if self.usage == 'assignment':
+            test = """/* [config]
+ * expect_result: fail
+ * glsl_version: 1.00
+ * [end config]
+ *
+ * Page 46, Section 5.8 of the GLSL ES 1.00.17 spec says:
+ *
+ *     "Variables that are built-in types, entire structures, structure
+ *     fields, l-values with the field selector ( . ) applied to select
+ *     components or swizzles without repeated fields, l-values within
+ *     parentheses and and l-values dereferenced with the array subscript
+ *     operator ( [ ] ) are all l-values. Other unary, binary, ternary
+ *     expressions, are not l-values. This includes assignments, function
+ *     names, swizzles with repeated fields and constants.
+ *
+ *     Array variables are l-values and maybe passed to parameters declared as
+ *     out or inout. However, they may not be used as the target of assignment.
+ *     Similiarly, structures containing arrays may be passed to parameters
+ *     declared as out or inout but may not be used as the target of an
+ *     assignment.
+ */
+uniform {self.type_name} u;
+{mode} vec4 v;
+
+void main()
+{{
+    {self.type_name} t = u;
+
+    {self.op} = {self.type_name}(v{components});
+    {dest} = {var_as_vec4};
+}}
+"""
+        else:
+            test = """/* [config]
+ * expect_result: fail
+ * glsl_version: 1.00
+ * [end config]
+ *
+ * Page 46, Section 5.8 of the GLSL ES 1.00.17 spec says:
+ *
+ *     "Variables that are built-in types, entire structures, structure
+ *     fields, l-values with the field selector ( . ) applied to select
+ *     components or swizzles without repeated fields, l-values within
+ *     parentheses and and l-values dereferenced with the array subscript
+ *     operator ( [ ] ) are all l-values. Other unary, binary, ternary
+ *     expressions, are not l-values. This includes assignments, function
+ *     names, swizzles with repeated fields and constants.
+ *
+ *     Array variables are l-values and maybe passed to parameters declared as
+ *     out or inout. However, they may not be used as the target of assignment.
+ *     Similiarly, structures containing arrays may be passed to parameters
+ *     declared as out or inout but may not be used as the target of an
+ *     assignment.
+ */
+uniform {self.type_name} u;
+{mode} vec4 v;
+
+void f(out {self.type_name} p)
+{{
+    p = {self.type_name}(v{components});
+}}
+
+void main()
+{{
+    {self.type_name} t = u;
+
+    f({self.op});
+    {dest} = {var_as_vec4};
+}}
+"""
+        if '2' in self.type_name:
+            var_as_vec4 = 'vec4(t.xyxy)'
+            components = '.xy'
+        elif '3' in self.type_name:
+            var_as_vec4 = 'vec4(t.xyzx)'
+            components = '.xyz'
+        elif '4' in self.type_name:
+            var_as_vec4 = 'vec4(t)'
+            components = ''
+        else:
+            var_as_vec4 = 'vec4(t)'
+            components = '.x'
+
+        if self.shader_target == 'vert':
+            dest = "gl_Position"
+            mode = 'attribute'
+        else:
+            mode = 'varying'
+            dest = "gl_FragColor"
+
+        test = test.format(self = self,
+                           components = components,
+                           dest = dest,
+                           var_as_vec4 = var_as_vec4,
+                           mode = mode)
+
+        filename = self.filename()
+	dirname = os.path.dirname(filename)
+	if not os.path.exists(dirname):
+	    os.makedirs(dirname)
+	with open(filename, 'w') as f:
+	    f.write(test)
+
+
+def all_tests():
+    for type_name in ['float', 'vec2',  'vec3',  'vec4',
+                 'int',   'ivec2', 'ivec3', 'ivec4']:
+        for op in ["++t", "--t", "t++", "t--"]:
+            for usage in ['assignment', 'out-parameter']:
+                          for shader_target in ['vert', 'frag']:
+                              yield TestES1(type_name, op, usage, shader_target)
+
+def main():
+    for test in all_tests():
+	test.generate()
+	print test.filename()
+
+
+if __name__ == '__main__':
+    main()