[Piglit] [PATCH 15/45] gen_shader_bit_encoding_tests.py: split template into separate file

Dylan Baker baker.dylan.c at gmail.com
Wed Nov 12 15:45:57 PST 2014


Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 generated_tests/CMakeLists.txt                     |   4 +-
 generated_tests/gen_shader_bit_encoding_tests.py   | 102 ++-------------------
 .../template.shader_test.mako                      |  87 ++++++++++++++++++
 3 files changed, 98 insertions(+), 95 deletions(-)
 create mode 100644 generated_tests/templates/gen_shader_bit_encoding_tests/template.shader_test.mako

diff --git a/generated_tests/CMakeLists.txt b/generated_tests/CMakeLists.txt
index a043c32..434b285 100644
--- a/generated_tests/CMakeLists.txt
+++ b/generated_tests/CMakeLists.txt
@@ -44,7 +44,9 @@ piglit_make_generated_tests(
 	gen_texture_query_lod_tests.py)
 piglit_make_generated_tests(
 	shader_bit_encoding_tests.list
-	gen_shader_bit_encoding_tests.py)
+	gen_shader_bit_encoding_tests.py
+	templates/gen_shader_bit_encoding_tests/template.shader_test.mako
+	)
 piglit_make_generated_tests(
 	uniform-initializer_tests.list
 	gen_uniform_initializer_tests.py
diff --git a/generated_tests/gen_shader_bit_encoding_tests.py b/generated_tests/gen_shader_bit_encoding_tests.py
index 6f8755d..84b9390 100644
--- a/generated_tests/gen_shader_bit_encoding_tests.py
+++ b/generated_tests/gen_shader_bit_encoding_tests.py
@@ -1,6 +1,6 @@
 # coding=utf-8
 #
-# Copyright © 2013 Intel Corporation
+# Copyright © 2013, 2014 Intel Corporation
 #
 # Permission is hereby granted, free of charge, to any person obtaining a
 # copy of this software and associated documentation files (the "Software"),
@@ -23,9 +23,12 @@
 
 import struct
 import os
-import os.path
-from mako.template import Template
-from textwrap import dedent
+
+from templates import template_file
+
+TEMPLATE = template_file(os.path.basename(os.path.splitext(__file__)[0]),
+                         'template.shader_test.mako')
+
 
 def floatBitsToInt(f):
     return struct.unpack('i', struct.pack('f', f))[0]
@@ -123,95 +126,6 @@ requirements = {
     }
 }
 
-template = Template(dedent("""\
-    [require]
-    GLSL >= ${version}
-    % for extension in extensions:
-    ${extension}
-    % endfor
-
-    [vertex shader]
-    % if execution_stage == 'vs':
-    % for extension in extensions:
-    #extension ${extension}: enable
-    % endfor
-
-    uniform ${input_type} given;
-    uniform ${output_type} expected;
-    out vec4 color;
-    % endif
-
-    in vec4 vertex;
-
-    void main() {
-        gl_Position = vertex;
-
-        % if execution_stage == 'vs':
-        color = vec4(0.0, 1.0, 0.0, 1.0);
-
-        if (expected.x != ${func}(${in_modifier_func}(given.x)))
-                color.r = 1.0;
-        if (expected.xy != ${func}(${in_modifier_func}(given.xy)))
-                color.r = 1.0;
-        if (expected.xyz != ${func}(${in_modifier_func}(given.xyz)))
-                color.r = 1.0;
-        if (expected != ${func}(${in_modifier_func}(given)))
-                color.r = 1.0;
-        % endif
-    }
-
-    [fragment shader]
-    % if execution_stage == 'fs':
-    % for extension in extensions:
-    #extension ${extension}: enable
-    % endfor
-
-    uniform ${input_type} given;
-    uniform ${output_type} expected;
-    % else:
-    in vec4 color;
-    % endif
-
-    out vec4 frag_color;
-
-    void main() {
-        % if execution_stage == 'fs':
-        frag_color = vec4(0.0, 1.0, 0.0, 1.0);
-
-        if (expected.x != ${func}(${in_modifier_func}(given.x)))
-                frag_color.r = 1.0;
-        if (expected.xy != ${func}(${in_modifier_func}(given.xy)))
-                frag_color.r = 1.0;
-        if (expected.xyz != ${func}(${in_modifier_func}(given.xyz)))
-                frag_color.r = 1.0;
-        if (expected != ${func}(${in_modifier_func}(given)))
-                frag_color.r = 1.0;
-        % else:
-        frag_color = color;
-        % endif
-    }
-
-    [vertex data]
-    vertex/float/2
-    -1.0 -1.0
-     1.0 -1.0
-     1.0  1.0
-    -1.0  1.0
-
-    [test]
-    % for name, data in sorted(test_data.iteritems()):
-    % if name == '-0.0' and in_modifier_func != '' and func == 'intBitsToFloat':
-    # ${in_modifier_func}(INT_MIN) doesn't fit in a 32-bit int. Cannot test.
-    % else:
-    # ${name}
-    uniform ${input_type} given ${' '.join(str(in_func(d)) for d in data)}
-    uniform ${output_type} expected ${' '.join(str(out_func(modifier_func(in_func(d)))) for d in data)}
-    draw arrays GL_TRIANGLE_FAN 0 4
-    probe all rgba 0.0 1.0 0.0 1.0
-    % endif
-
-    % endfor
-"""))
 
 for api, requirement in requirements.iteritems():
     version = requirement['version']
@@ -251,7 +165,7 @@ for api, requirement in requirements.iteritems():
                     in_modifier_func = '-abs'
 
                 f = open(filename, 'w')
-                f.write(template.render(version=version,
+                f.write(TEMPLATE.render(version=version,
                                         extensions=extensions,
                                         execution_stage=execution_stage,
                                         func=func,
diff --git a/generated_tests/templates/gen_shader_bit_encoding_tests/template.shader_test.mako b/generated_tests/templates/gen_shader_bit_encoding_tests/template.shader_test.mako
new file mode 100644
index 0000000..83eb567
--- /dev/null
+++ b/generated_tests/templates/gen_shader_bit_encoding_tests/template.shader_test.mako
@@ -0,0 +1,87 @@
+[require]
+GLSL >= ${version}
+% for extension in extensions:
+${extension}
+% endfor
+
+[vertex shader]
+% if execution_stage == 'vs':
+% for extension in extensions:
+#extension ${extension}: enable
+% endfor
+
+uniform ${input_type} given;
+uniform ${output_type} expected;
+out vec4 color;
+% endif
+
+in vec4 vertex;
+
+void main() {
+    gl_Position = vertex;
+
+    % if execution_stage == 'vs':
+    color = vec4(0.0, 1.0, 0.0, 1.0);
+
+    if (expected.x != ${func}(${in_modifier_func}(given.x)))
+            color.r = 1.0;
+    if (expected.xy != ${func}(${in_modifier_func}(given.xy)))
+            color.r = 1.0;
+    if (expected.xyz != ${func}(${in_modifier_func}(given.xyz)))
+            color.r = 1.0;
+    if (expected != ${func}(${in_modifier_func}(given)))
+            color.r = 1.0;
+    % endif
+}
+
+[fragment shader]
+% if execution_stage == 'fs':
+% for extension in extensions:
+#extension ${extension}: enable
+% endfor
+
+uniform ${input_type} given;
+uniform ${output_type} expected;
+% else:
+in vec4 color;
+% endif
+
+out vec4 frag_color;
+
+void main() {
+    % if execution_stage == 'fs':
+    frag_color = vec4(0.0, 1.0, 0.0, 1.0);
+
+    if (expected.x != ${func}(${in_modifier_func}(given.x)))
+            frag_color.r = 1.0;
+    if (expected.xy != ${func}(${in_modifier_func}(given.xy)))
+            frag_color.r = 1.0;
+    if (expected.xyz != ${func}(${in_modifier_func}(given.xyz)))
+            frag_color.r = 1.0;
+    if (expected != ${func}(${in_modifier_func}(given)))
+            frag_color.r = 1.0;
+    % else:
+    frag_color = color;
+    % endif
+}
+
+[vertex data]
+vertex/float/2
+-1.0 -1.0
+ 1.0 -1.0
+ 1.0  1.0
+-1.0  1.0
+
+[test]
+% for name, data in sorted(test_data.iteritems()):
+% if name == '-0.0' and in_modifier_func != '' and func == 'intBitsToFloat':
+# ${in_modifier_func}(INT_MIN) doesn't fit in a 32-bit int. Cannot test.
+% else:
+# ${name}
+uniform ${input_type} given ${' '.join(str(in_func(d)) for d in data)}
+uniform ${output_type} expected ${' '.join(str(out_func(modifier_func(in_func(d)))) for d in data)}
+draw arrays GL_TRIANGLE_FAN 0 4
+probe all rgba 0.0 1.0 0.0 1.0
+% endif
+
+% endfor
-- 
2.1.3



More information about the Piglit mailing list