[Piglit] [RESEND RFC 20/25] gen_tess_input_tests.py: Use mako to generate tests

baker.dylan.c at gmail.com baker.dylan.c at gmail.com
Wed Oct 21 10:20:29 PDT 2015


From: Dylan Baker <baker.dylan.c at gmail.com>

This gives us a cached template, speeding up regenerating these tests,
which is especially helpful in a CI system like Jenkins.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 generated_tests/CMakeLists.txt                     |   5 +-
 generated_tests/gen_tess_input_tests.py            | 210 ++-------------------
 .../gen_tess_input_tests/tcs.shader_test.mako      | 115 +++++++++++
 .../gen_tess_input_tests/tes.shader_test.mako      | 114 +++++++++++
 4 files changed, 245 insertions(+), 199 deletions(-)
 create mode 100644 generated_tests/templates/gen_tess_input_tests/tcs.shader_test.mako
 create mode 100644 generated_tests/templates/gen_tess_input_tests/tes.shader_test.mako

diff --git a/generated_tests/CMakeLists.txt b/generated_tests/CMakeLists.txt
index dbfd5c8..ed8ee02 100644
--- a/generated_tests/CMakeLists.txt
+++ b/generated_tests/CMakeLists.txt
@@ -44,7 +44,10 @@ piglit_make_generated_tests(
 	)
 piglit_make_generated_tests(
 	tess_input_tests.list
-	gen_tess_input_tests.py)
+	gen_tess_input_tests.py
+	templates/gen_tess_input_tests/tcs.shader_test.mako
+	templates/gen_tess_input_tests/tes.shader_test.mako
+    )
 piglit_make_generated_tests(
 	interpolation_tests.list
 	gen_interpolation_tests.py
diff --git a/generated_tests/gen_tess_input_tests.py b/generated_tests/gen_tess_input_tests.py
index 3149471..b623cce 100644
--- a/generated_tests/gen_tess_input_tests.py
+++ b/generated_tests/gen_tess_input_tests.py
@@ -33,11 +33,14 @@ from __future__ import print_function, absolute_import, division
 import os
 import sys
 import random
-import textwrap
 
 from six.moves import range
 
 from modules.utils import safe_makedirs
+from templates import template_dir
+
+
+_TEMPLATES = template_dir(os.path.basename(os.path.splitext(__file__)[0]))
 
 
 class TcsTest(object):
@@ -53,6 +56,8 @@ class TcsTest(object):
     Draw four tessellated quads. Each should cover one quarter of the screen.
 
     """
+    TEMPLATE = _TEMPLATES.get_template('tcs.shader_test.mako')
+
     def __init__(self, type_name, array, name):
         """Creates a test.
 
@@ -185,109 +190,12 @@ class TcsTest(object):
 
     def generate(self):
         """Generates and writes the test to disc."""
-        test = textwrap.dedent("""\
-            # Test generated by:
-            # {generator_command}
-            # Test tessellation control shader inputs
-            [require]
-            GLSL >= 1.50
-            GL_ARB_tessellation_shader
-
-            [vertex shader]
-            uniform struct S0 {{
-                    {self.var_type_full} v;
-            }} reference[12];
-
-            out {self.interface_name} {{
-                    {self.var_type_full} {self.var_name};
-            }} {self.interface_vs_instance};
-
-            void main()
-            {{
-                    {self.interface_vs_instance}{self.vs_var_ref} = reference[gl_VertexID].v;
-            }}
-
-            [tessellation control shader]
-            #extension GL_ARB_tessellation_shader : require
-            layout(vertices = 3) out;
-
-            uniform struct S0 {{
-                    {self.var_type_full} v;
-            }} reference[12];
-
-            in {self.interface_name} {{
-                    {self.var_type_full} {self.var_name};
-            }} {self.interface_tcs_instance}[];
-
-            out int pass[];
-
-            void main()
-            {{
-                    const int vertices_in = 3;
-                    int local_pass = 1;
-                    for (int i = 0; i < vertices_in; ++i) {{
-                            int vertex_ID = gl_PrimitiveID * vertices_in + i;
-                            if ({self.interface_tcs_instance}[i]{self.tcs_var_ref} != reference[vertex_ID].v)
-                                    local_pass = 0;
-                    }}
-                    pass[gl_InvocationID] = local_pass;
-                    gl_TessLevelOuter = float[4](1.0, 1.0, 1.0, 1.0);
-                    gl_TessLevelInner = float[2](1.0, 1.0);
-            }}
-
-            [tessellation evaluation shader]
-            #extension GL_ARB_tessellation_shader : require
-            layout(quads) in;
-
-            in int pass[];
-
-            out vec4 vert_color;
-
-            void main()
-            {{
-                    const vec4 red = vec4(1, 0, 0, 1);
-                    const vec4 green = vec4(0, 1, 0, 1);
-                    vec2[3] position = vec2[3](
-                            vec2(float(gl_PrimitiveID / 2) - 1.0, float(gl_PrimitiveID % 2) - 1.0),
-                            vec2(float(gl_PrimitiveID / 2) - 0.0, float(gl_PrimitiveID % 2) - 1.0),
-                            vec2(float(gl_PrimitiveID / 2) - 1.0, float(gl_PrimitiveID % 2) - 0.0)
-                    );
-                    gl_Position = vec4(position[0]
-                                + (position[1] - position[0]) * gl_TessCoord[0]
-                                + (position[2] - position[0]) * gl_TessCoord[1], 0.0, 1.0);
-                    vert_color = green;
-                    if (pass[0] == 0 || pass[1] == 0 || pass[2] == 0) {{
-                            vert_color = red;
-                    }}
-            }}
-
-            [fragment shader]
-
-            in vec4 vert_color;
-
-            out vec4 frag_color;
-
-            void main()
-            {{
-                    frag_color = vert_color;
-            }}
-
-            [test]
-            {self.uniform_string}
-            draw arrays GL_PATCHES 0 12
-            relative probe rgb (0.25, 0.25) (0.0, 1.0, 0.0)
-            relative probe rgb (0.75, 0.25) (0.0, 1.0, 0.0)
-            relative probe rgb (0.25, 0.75) (0.0, 1.0, 0.0)
-            relative probe rgb (0.75, 0.75) (0.0, 1.0, 0.0)
-            """)
-
-        test = test.format(self=self, generator_command=" ".join(sys.argv))
-
         filename = self.filename()
         dirname = os.path.dirname(filename)
         safe_makedirs(dirname)
         with open(filename, 'w') as f:
-            f.write(test)
+            f.write(self.TEMPLATE.render_unicode(
+                params=self, generator_command=" ".join(sys.argv)))
 
 
 class TesTest(object):
@@ -304,6 +212,8 @@ class TesTest(object):
     Draw four tessellated quads. Each should cover one quarter of the screen.
 
     """
+    TEMPLATE = _TEMPLATES.get_template('tes.shader_test.mako')
+
     def __init__(self, type_name, array, patch_in, name):
         """Creates a test.
 
@@ -463,108 +373,12 @@ class TesTest(object):
 
     def generate(self):
         """Generates and writes the test to disc."""
-        test = textwrap.dedent("""\
-            # Test generated by:
-            # {generator_command}
-            # Test tessellation control shader inputs
-            [require]
-            GLSL >= 1.50
-            GL_ARB_tessellation_shader
-
-            [vertex shader]
-            void main()
-            {{
-                    gl_Position = vec4(0);
-            }}
-
-            [tessellation control shader]
-            #extension GL_ARB_tessellation_shader : require
-            layout(vertices = 3) out;
-
-            uniform struct S0 {{
-                    {self.var_type_full} v;
-            }} reference[12];
-
-            #if {self.use_block}
-            {self.interface_prefix}out {self.interface_name} {{
-                    {self.var_type_full} {self.var_name};
-            }} {self.interface_tcs_instance}{self.interface_postfix};
-            #else
-            {self.interface_prefix}out {self.var_type_full} {self.var_name};
-            #endif
-
-            void main()
-            {{
-                    const int vertices_in = 3;
-                    {self.interface_tcs_instance}{self.tcs_var_ref} = reference[{self.tcs_reference_index}].v;
-                    gl_TessLevelOuter = float[4](1.0, 1.0, 1.0, 1.0);
-                    gl_TessLevelInner = float[2](1.0, 1.0);
-            }}
-
-            [tessellation evaluation shader]
-            #extension GL_ARB_tessellation_shader : require
-            layout(quads) in;
-
-            uniform struct S0 {{
-                    {self.var_type_full} v;
-            }} reference[12];
-
-            #if {self.use_block}
-            {self.interface_prefix}in {self.interface_name} {{
-                    {self.var_type_full} {self.var_name};
-            }} {self.interface_tes_instance}{self.interface_postfix};
-            #else
-            {self.interface_prefix}in {self.var_type_full} {self.var_name};
-            #endif
-
-            out vec4 vert_color;
-
-            void main()
-            {{
-                    const int vertices_in = 3;
-                    const vec4 red = vec4(1, 0, 0, 1);
-                    const vec4 green = vec4(0, 1, 0, 1);
-                    vert_color = green;
-                    for (int i = 0; i < vertices_in; ++i)
-                            if ({self.interface_tes_instance}{self.tes_var_ref} != reference[{self.tes_reference_index}].v)
-                                    vert_color = red;
-                    vec2[3] position = vec2[3](
-                            vec2(float(gl_PrimitiveID / 2) - 1.0, float(gl_PrimitiveID % 2) - 1.0),
-                            vec2(float(gl_PrimitiveID / 2) - 0.0, float(gl_PrimitiveID % 2) - 1.0),
-                            vec2(float(gl_PrimitiveID / 2) - 1.0, float(gl_PrimitiveID % 2) - 0.0)
-                    );
-                    gl_Position = vec4(position[0]
-                                + (position[1] - position[0]) * gl_TessCoord[0]
-                                + (position[2] - position[0]) * gl_TessCoord[1], 0.0, 1.0);
-            }}
-
-            [fragment shader]
-
-            in vec4 vert_color;
-
-            out vec4 frag_color;
-
-            void main()
-            {{
-                    frag_color = vert_color;
-            }}
-
-            [test]
-            {self.uniform_string}
-            draw arrays GL_PATCHES 0 12
-            relative probe rgb (0.25, 0.25) (0.0, 1.0, 0.0)
-            relative probe rgb (0.75, 0.25) (0.0, 1.0, 0.0)
-            relative probe rgb (0.25, 0.75) (0.0, 1.0, 0.0)
-            relative probe rgb (0.75, 0.75) (0.0, 1.0, 0.0)
-            """)
-
-        test = test.format(self=self, generator_command=" ".join(sys.argv))
-
         filename = self.filename()
         dirname = os.path.dirname(filename)
         safe_makedirs(dirname)
         with open(filename, 'w') as f:
-            f.write(test)
+            f.write(self.TEMPLATE.render_unicode(
+                params=self, generator_command=" ".join(sys.argv)))
 
 
 def all_tests():
diff --git a/generated_tests/templates/gen_tess_input_tests/tcs.shader_test.mako b/generated_tests/templates/gen_tess_input_tests/tcs.shader_test.mako
new file mode 100644
index 0000000..b5950c2
--- /dev/null
+++ b/generated_tests/templates/gen_tess_input_tests/tcs.shader_test.mako
@@ -0,0 +1,115 @@
+## Copyright (c) 2014 The Piglit Project
+## Copyright (c) 2015 Intel Corporation
+##
+## 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 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.
+
+
+# Test generated by:
+# ${generator_command}
+# Test tessellation control shader inputs
+[require]
+GLSL >= 1.50
+GL_ARB_tessellation_shader
+
+[vertex shader]
+uniform struct S0 {
+        ${params.var_type_full} v;
+} reference[12];
+
+out ${params.interface_name} {
+        ${params.var_type_full} ${params.var_name};
+} ${params.interface_vs_instance};
+
+void main()
+{
+        ${params.interface_vs_instance}${params.vs_var_ref} = reference[gl_VertexID].v;
+}
+
+[tessellation control shader]
+#extension GL_ARB_tessellation_shader : require
+layout(vertices = 3) out;
+
+uniform struct S0 {
+        ${params.var_type_full} v;
+} reference[12];
+
+in ${params.interface_name} {
+        ${params.var_type_full} ${params.var_name};
+} ${params.interface_tcs_instance}[];
+
+out int pass[];
+
+void main()
+{
+        const int vertices_in = 3;
+        int local_pass = 1;
+        for (int i = 0; i < vertices_in; ++i) {
+                int vertex_ID = gl_PrimitiveID * vertices_in + i;
+                if (${params.interface_tcs_instance}[i]${params.tcs_var_ref} != reference[vertex_ID].v)
+                        local_pass = 0;
+        }
+        pass[gl_InvocationID] = local_pass;
+        gl_TessLevelOuter = float[4](1.0, 1.0, 1.0, 1.0);
+        gl_TessLevelInner = float[2](1.0, 1.0);
+}
+
+[tessellation evaluation shader]
+#extension GL_ARB_tessellation_shader : require
+layout(quads) in;
+
+in int pass[];
+
+out vec4 vert_color;
+
+void main()
+{
+        const vec4 red = vec4(1, 0, 0, 1);
+        const vec4 green = vec4(0, 1, 0, 1);
+        vec2[3] position = vec2[3](
+                vec2(float(gl_PrimitiveID / 2) - 1.0, float(gl_PrimitiveID % 2) - 1.0),
+                vec2(float(gl_PrimitiveID / 2) - 0.0, float(gl_PrimitiveID % 2) - 1.0),
+                vec2(float(gl_PrimitiveID / 2) - 1.0, float(gl_PrimitiveID % 2) - 0.0)
+        );
+        gl_Position = vec4(position[0]
+                    + (position[1] - position[0]) * gl_TessCoord[0]
+                    + (position[2] - position[0]) * gl_TessCoord[1], 0.0, 1.0);
+        vert_color = green;
+        if (pass[0] == 0 || pass[1] == 0 || pass[2] == 0) {
+                vert_color = red;
+        }
+}
+
+[fragment shader]
+
+in vec4 vert_color;
+
+out vec4 frag_color;
+
+void main()
+{
+        frag_color = vert_color;
+}
+
+[test]
+${params.uniform_string}
+draw arrays GL_PATCHES 0 12
+relative probe rgb (0.25, 0.25) (0.0, 1.0, 0.0)
+relative probe rgb (0.75, 0.25) (0.0, 1.0, 0.0)
+relative probe rgb (0.25, 0.75) (0.0, 1.0, 0.0)
+relative probe rgb (0.75, 0.75) (0.0, 1.0, 0.0)
diff --git a/generated_tests/templates/gen_tess_input_tests/tes.shader_test.mako b/generated_tests/templates/gen_tess_input_tests/tes.shader_test.mako
new file mode 100644
index 0000000..3428e11
--- /dev/null
+++ b/generated_tests/templates/gen_tess_input_tests/tes.shader_test.mako
@@ -0,0 +1,114 @@
+## Copyright (c) 2014 The Piglit Project
+## Copyright (c) 2015 Intel Corporation
+##
+## 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 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.
+
+
+# Test generated by:
+# ${generator_command}
+# Test tessellation control shader inputs
+[require]
+GLSL >= 1.50
+GL_ARB_tessellation_shader
+
+[vertex shader]
+void main()
+{
+        gl_Position = vec4(0);
+}
+
+[tessellation control shader]
+#extension GL_ARB_tessellation_shader : require
+layout(vertices = 3) out;
+
+uniform struct S0 {
+        ${params.var_type_full} v;
+} reference[12];
+
+#if ${params.use_block}
+${params.interface_prefix}out ${params.interface_name} {
+        ${params.var_type_full} ${params.var_name};
+} ${params.interface_tcs_instance}${params.interface_postfix};
+#else
+${params.interface_prefix}out ${params.var_type_full} ${params.var_name};
+#endif
+
+void main()
+{
+        const int vertices_in = 3;
+        ${params.interface_tcs_instance}${params.tcs_var_ref} = reference[${params.tcs_reference_index}].v;
+        gl_TessLevelOuter = float[4](1.0, 1.0, 1.0, 1.0);
+        gl_TessLevelInner = float[2](1.0, 1.0);
+}
+
+[tessellation evaluation shader]
+#extension GL_ARB_tessellation_shader : require
+layout(quads) in;
+
+uniform struct S0 {
+        ${params.var_type_full} v;
+} reference[12];
+
+#if ${params.use_block}
+${params.interface_prefix}in ${params.interface_name} {
+        ${params.var_type_full} ${params.var_name};
+} ${params.interface_tes_instance}${params.interface_postfix};
+#else
+${params.interface_prefix}in ${params.var_type_full} ${params.var_name};
+#endif
+
+out vec4 vert_color;
+
+void main()
+{
+        const int vertices_in = 3;
+        const vec4 red = vec4(1, 0, 0, 1);
+        const vec4 green = vec4(0, 1, 0, 1);
+        vert_color = green;
+        for (int i = 0; i < vertices_in; ++i)
+                if (${params.interface_tes_instance}${params.tes_var_ref} != reference[${params.tes_reference_index}].v)
+                        vert_color = red;
+        vec2[3] position = vec2[3](
+                vec2(float(gl_PrimitiveID / 2) - 1.0, float(gl_PrimitiveID % 2) - 1.0),
+                vec2(float(gl_PrimitiveID / 2) - 0.0, float(gl_PrimitiveID % 2) - 1.0),
+                vec2(float(gl_PrimitiveID / 2) - 1.0, float(gl_PrimitiveID % 2) - 0.0)
+        );
+        gl_Position = vec4(position[0]
+                    + (position[1] - position[0]) * gl_TessCoord[0]
+                    + (position[2] - position[0]) * gl_TessCoord[1], 0.0, 1.0);
+}
+
+[fragment shader]
+
+in vec4 vert_color;
+
+out vec4 frag_color;
+
+void main()
+{
+        frag_color = vert_color;
+}
+
+[test]
+${params.uniform_string}
+draw arrays GL_PATCHES 0 12
+relative probe rgb (0.25, 0.25) (0.0, 1.0, 0.0)
+relative probe rgb (0.75, 0.25) (0.0, 1.0, 0.0)
+relative probe rgb (0.25, 0.75) (0.0, 1.0, 0.0)
+relative probe rgb (0.75, 0.75) (0.0, 1.0, 0.0)
-- 
2.6.1



More information about the Piglit mailing list