[Piglit] [PATCH 2/6] gen_tess_input_tests.py: move some formatting logic into the templates

Dylan Baker baker.dylan.c at gmail.com
Wed Oct 7 14:27:56 PDT 2015


This logic was purely used for making content to appear in the generated
files. It is both simpler and less code if it put in the template.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 generated_tests/gen_tess_input_tests.py            | 44 ++--------------------
 .../gen_tess_input_tests/tcs.shader_test.mako      | 16 +++++++-
 .../gen_tess_input_tests/tes.shader_test.mako      | 16 +++++++-
 3 files changed, 33 insertions(+), 43 deletions(-)

diff --git a/generated_tests/gen_tess_input_tests.py b/generated_tests/gen_tess_input_tests.py
index b623cce..cf1c1aa 100644
--- a/generated_tests/gen_tess_input_tests.py
+++ b/generated_tests/gen_tess_input_tests.py
@@ -36,7 +36,7 @@ import random
 
 from six.moves import range
 
-from modules.utils import safe_makedirs
+from modules.utils import safe_makedirs, lazy_property
 from templates import template_dir
 
 
@@ -107,26 +107,6 @@ class TcsTest(object):
     def tcs_var_ref(self):
         return '.' + self.var_name if self.interface_tcs_instance else self.var_name
 
-    @property
-    def uniform_string(self):
-        """Returns string for loading uniform data by the shader_runner."""
-        data = self.test_data()
-        uniforms = ''
-        if self.var_array:
-            for i in range(12):
-                for j in range(self.var_array):
-                    uniforms += 'uniform {0} reference[{1}].v[{2}] {3}\n'.format(
-                        self.var_type, i, j, data[i*j])
-        else:
-            for i in range(12):
-                uniforms += 'uniform {0} reference[{1}].v {2}\n'.format(
-                    self.var_type,
-                    i,
-                    data[i])
-
-        #strip last newline
-        return uniforms[:-1]
-
     def components(self):
         """Returns the number of scalar components of the used data type."""
         n = 1
@@ -143,6 +123,7 @@ class TcsTest(object):
 
         return n
 
+    @lazy_property
     def test_data(self):
         """Returns random but deterministic data as a list of strings.
 
@@ -288,26 +269,6 @@ class TesTest(object):
     def reference_size(self):
         return 4 if self.patch_in else 12
 
-    @property
-    def uniform_string(self):
-        """Returns string for loading uniform data by the shader_runner."""
-        data = self.test_data()
-        uniforms = ''
-        if self.var_array:
-            for i in range(self.reference_size):
-                for j in range(self.var_array):
-                    uniforms += 'uniform {0} reference[{1}].v[{2}] {3}\n'.format(
-                        self.var_type, i, j, data[i*j])
-        else:
-            for i in range(self.reference_size):
-                uniforms += 'uniform {0} reference[{1}].v {2}\n'.format(
-                    self.var_type,
-                    i,
-                    data[i])
-
-        #strip last newline
-        return uniforms[:-1]
-
     def components(self):
         """Returns the number of scalar components of the used data type."""
         n = 1
@@ -324,6 +285,7 @@ class TesTest(object):
 
         return n
 
+    @lazy_property
     def test_data(self):
         """Returns random but deterministic data as a list of strings.
 
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
index b5950c2..f57f84d 100644
--- a/generated_tests/templates/gen_tess_input_tests/tcs.shader_test.mako
+++ b/generated_tests/templates/gen_tess_input_tests/tcs.shader_test.mako
@@ -19,6 +19,12 @@
 ## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 ## SOFTWARE.
 
+<%!
+  import itertools
+
+  from six.moves import range
+%>
+
 
 # Test generated by:
 # ${generator_command}
@@ -107,7 +113,15 @@ void main()
 }
 
 [test]
-${params.uniform_string}
+% if params.var_array:
+  % for i, j in itertools.product(range(12), range(params.var_array)):
+uniform ${params.var_type} reference[${i}].v[${j}] ${params.test_data[i*j]}
+  % endfor
+% else:
+  % for i in range(12):
+uniform ${params.var_type} reference[${i}].v ${params.test_data[i]}
+  % endfor
+% endif
 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)
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
index 3428e11..ccde8bf 100644
--- a/generated_tests/templates/gen_tess_input_tests/tes.shader_test.mako
+++ b/generated_tests/templates/gen_tess_input_tests/tes.shader_test.mako
@@ -19,6 +19,12 @@
 ## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 ## SOFTWARE.
 
+<%!
+  import itertools
+
+  from six.moves import range
+%>
+
 
 # Test generated by:
 # ${generator_command}
@@ -106,7 +112,15 @@ void main()
 }
 
 [test]
-${params.uniform_string}
+% if params.var_array:
+  % for i, j in itertools.product(range(params.reference_size), range(params.var_array)):
+uniform ${params.var_type} reference[${i}].v[${j}] ${params.test_data[i*j]}
+  % endfor
+% else:
+  % for i in range(params.reference_size):
+uniform ${params.var_type} reference[${i}].v ${params.test_data[i]}
+  % endfor
+% endif
 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)
-- 
2.6.1



More information about the Piglit mailing list