[Piglit] [PATCH 08/34] generators: python2/3 hybridize gen_outerproduct_tests.py

Dylan Baker baker.dylan.c at gmail.com
Fri Feb 20 18:17:55 PST 2015


This uses six in both the mako templates and in the main python script
to create a generator that runs under both python2.7 and python 3.2, and
this produces not differences when run with python2 or python3.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 generated_tests/gen_outerproduct_tests.py              |  4 +++-
 .../gen_outerproduct_tests/template.shader_test.mako   | 18 +++++++++++-------
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/generated_tests/gen_outerproduct_tests.py b/generated_tests/gen_outerproduct_tests.py
index 42c527b..7fd6eb2 100644
--- a/generated_tests/gen_outerproduct_tests.py
+++ b/generated_tests/gen_outerproduct_tests.py
@@ -25,6 +25,8 @@ import os
 import itertools
 import collections
 
+from six.moves import range
+
 from templates import template_file
 from modules import utils
 
@@ -41,7 +43,7 @@ def main():
     utils.safe_makedirs(dirname)
 
 
-    for c, r in itertools.product(xrange(2, 5), repeat=2):
+    for c, r in itertools.product(range(2, 5), repeat=2):
         vecs = [
             Parameters(c, r, 'vec', 'mat{0}x{1}'.format(r, c)),
             Parameters(c, r, 'ivec', 'mat{0}x{1}'.format(r, c))
diff --git a/generated_tests/templates/gen_outerproduct_tests/template.shader_test.mako b/generated_tests/templates/gen_outerproduct_tests/template.shader_test.mako
index 5d7561a..8c2d6c9 100644
--- a/generated_tests/templates/gen_outerproduct_tests/template.shader_test.mako
+++ b/generated_tests/templates/gen_outerproduct_tests/template.shader_test.mako
@@ -18,6 +18,10 @@
 ## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 ## SOFTWARE.
 
+<%!
+  from six.moves import range
+%>
+
 <%def name="spec()">
 /* From page 43 (page 49 of the PDF) of the GLSL 1.20 spec:
  *
@@ -42,9 +46,9 @@
 </%def>
 
 <%def name="const_shader_data()">
-const ${params.vec_type}${params.columns} c = ${params.vec_type}${params.columns}(${", ".join(str(i + 1) for i in xrange(1, params.columns + 1))});
-const ${params.vec_type}${params.rows} r = ${params.vec_type}${params.rows}(${", ".join(str(i + 1 + params.columns) for i in xrange(1, params.rows + 1))});
-uniform ${params.matrix} expected = ${params.matrix}(${", ".join(str((i + 1 + params.columns) * (j + 1)) for i in xrange(1, params.rows + 1) for j in xrange(1, params.columns + 1))});
+const ${params.vec_type}${params.columns} c = ${params.vec_type}${params.columns}(${", ".join(str(i + 1) for i in range(1, params.columns + 1))});
+const ${params.vec_type}${params.rows} r = ${params.vec_type}${params.rows}(${", ".join(str(i + 1 + params.columns) for i in range(1, params.rows + 1))});
+uniform ${params.matrix} expected = ${params.matrix}(${", ".join(str((i + 1 + params.columns) * (j + 1)) for i in range(1, params.rows + 1) for j in range(1, params.columns + 1))});
 </%def>
 
 <%def name="uniform_shader_data()">
@@ -109,10 +113,10 @@ clear
 ortho
 
 %if type == 'uniform':
-% for x in xrange(1, 5):
-uniform ${params.vec_type}${params.columns} c ${" ".join(str(i + x) for i in xrange(1, params.columns + 1))}
-uniform ${params.vec_type}${params.rows} r ${" ".join(str(i + x + params.columns) for i in xrange(1, params.rows + 1))}
-uniform mat${params.rows}x${params.columns} expected ${" ".join(str((i + x + params.columns) * (j + x)) for i in xrange(1, params.rows + 1) for j in xrange(1, params.columns + 1))}
+% for x in range(1, 5):
+uniform ${params.vec_type}${params.columns} c ${" ".join(str(i + x) for i in range(1, params.columns + 1))}
+uniform ${params.vec_type}${params.rows} r ${" ".join(str(i + x + params.columns) for i in range(1, params.rows + 1))}
+uniform mat${params.rows}x${params.columns} expected ${" ".join(str((i + x + params.columns) * (j + x)) for i in range(1, params.rows + 1) for j in range(1, params.columns + 1))}
 draw rect ${20 * x - 10} 10 10 10
 probe rgb ${20 * x - 5} 15 0.0 1.0 0.0
 
-- 
2.3.0



More information about the Piglit mailing list