[Piglit] [RFC 08/12] gen_constant_array_size_tests.py: split the generator and the template
Dylan Baker
baker.dylan.c at gmail.com
Mon Dec 8 17:11:29 PST 2014
Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
generated_tests/CMakeLists.txt | 1 +
generated_tests/gen_constant_array_size_tests.py | 41 ++--------------------
.../template.glsl_parser_test.mako | 33 +++++++++++++++++
3 files changed, 37 insertions(+), 38 deletions(-)
create mode 100644 generated_tests/templates/gen_constant_array_size_tests/template.glsl_parser_test.mako
diff --git a/generated_tests/CMakeLists.txt b/generated_tests/CMakeLists.txt
index f634330..98379c5 100644
--- a/generated_tests/CMakeLists.txt
+++ b/generated_tests/CMakeLists.txt
@@ -45,6 +45,7 @@ piglit_make_generated_tests(
builtins/glsl_types.py
builtins/generators.py
builtins/math.py
+ templates/gen_constant_array_size_tests/template.glsl_parser_test.mako
)
piglit_make_generated_tests(
const_builtin_equal_tests.list
diff --git a/generated_tests/gen_constant_array_size_tests.py b/generated_tests/gen_constant_array_size_tests.py
index 40b19e3..9fdd8bc 100644
--- a/generated_tests/gen_constant_array_size_tests.py
+++ b/generated_tests/gen_constant_array_size_tests.py
@@ -41,48 +41,13 @@ of the files; it doesn't generate them.
from __future__ import print_function, division
import os
-from mako.template import Template
-
import builtin_function
import builtin_function_fp64
from builtins import glsl_types, generators
+from templates import template_file
-
-TEMPLATE = Template("""\
-/* [config]
- * expect_result: pass
- * glsl_version: ${glsl_version}
-% if extension:
- * require_extensions: GL_${extension}
-% endif
- * [end config]
- *
- * Check that the following test vectors are constantfolded correctly:
-% for template, result in comments:
- * ${template} => ${result}
-% endfor
- */
-#version ${int(float(glsl_version) * 100)}
-% if extension:
-#extension GL_${extension} : require
-% endif
-
-void main()
-{
-% for i, vector in enumerate(vectors):
- ${type_[0]}[${vector} ? 1 : -1] array${i};
-% else:
- ## This is a clever (but maybe not good) use of python's for/else syntax.
- ## vectors is a generator, which means that we cannot get a value again
- ## after we've iterated passed it. This trick allows us to bypass that
- ## limitation and output an additional value on the last iteration without
- ## storing the value of i because the else is still part of the for loop,
- ## and all of the variables from the last iteration of the for loop are
- ## still in scope.
- ${output_var} = ${type_[1]}(${' + '.join('array{}.length()'.format(x) for x in xrange(i + 1))});
-% endfor
-}
-""")
+TEMPLATE = template_file(os.path.basename(os.path.splitext(__file__)[0]),
+ 'template.glsl_parser_test.mako')
def make_glsl_version(signature, stage):
diff --git a/generated_tests/templates/gen_constant_array_size_tests/template.glsl_parser_test.mako b/generated_tests/templates/gen_constant_array_size_tests/template.glsl_parser_test.mako
new file mode 100644
index 0000000..dc50adf
--- /dev/null
+++ b/generated_tests/templates/gen_constant_array_size_tests/template.glsl_parser_test.mako
@@ -0,0 +1,33 @@
+/* [config]
+ * expect_result: pass
+ * glsl_version: ${glsl_version}
+% if extension:
+ * require_extensions: GL_${extension}
+% endif
+ * [end config]
+ *
+ * Check that the following test vectors are constantfolded correctly:
+% for template, result in comments:
+ * ${template} => ${result}
+% endfor
+ */
+#version ${int(float(glsl_version) * 100)}
+% if extension:
+#extension GL_${extension} : require
+% endif
+
+void main()
+{
+% for i, vector in enumerate(vectors):
+ ${type_[0]}[${vector} ? 1 : -1] array${i};
+% else:
+ ## This is a clever (but maybe not good) use of python's for/else syntax.
+ ## vectors is a generator, which means that we cannot get a value again
+ ## after we've iterated passed it. This trick allows us to bypass that
+ ## limitation and output an additional value on the last iteration without
+ ## storing the value of i because the else is still part of the for loop,
+ ## and all of the variables from the last iteration of the for loop are
+ ## still in scope.
+ ${output_var} = ${type_[1]}(${' + '.join('array{}.length()'.format(x) for x in xrange(i + 1))});
+% endfor
+}
--
2.2.0
More information about the Piglit
mailing list