[Piglit] [PATCH 1/4] gen_const_builtin_equal_tests.py: Use mako

Ilia Mirkin imirkin at alum.mit.edu
Mon May 19 14:47:47 PDT 2014


On Mon, May 19, 2014 at 5:43 PM, Dylan Baker <baker.dylan.c at gmail.com> wrote:
> This uses mako to render tests. It's faster than the previous method,
> and is much easier to understand.
>
> Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
> ---
>  generated_tests/gen_const_builtin_equal_tests.py | 87 ++++++++++++++----------
>  1 file changed, 50 insertions(+), 37 deletions(-)
>
> diff --git a/generated_tests/gen_const_builtin_equal_tests.py b/generated_tests/gen_const_builtin_equal_tests.py
> index 77fcedf..583f90e 100644
> --- a/generated_tests/gen_const_builtin_equal_tests.py
> +++ b/generated_tests/gen_const_builtin_equal_tests.py
> @@ -1,39 +1,52 @@
> -from __future__ import print_function
> -import re
> -import os
> -
> -def emit_test(f, func, input1, input2, expected):
> -    # Determine the expected return type of the equal function by looking at
> -    # the string of the expected return value.
> -    s = expected.split("(")
> +# Copyright (c) 2010, 2014 Intel Corporation
>
> -    spaces = re.sub("[^ ]", " ", func+s[0])
> +# 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:
>
> -    test = """
> -[require]
> -GLSL >= 1.20
> +# The above copyright notice and this permission notice shall be included in
> +# all copies or substantial portions of the Software.
>
> -[vertex shader]
> -void main()
> -{
> -  gl_Position = gl_Vertex;
> -}
> +# 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.
>
> -[fragment shader]
> -void main()
> -{
> -  const %s res = %s(%s,
> -                %s%s);
> -  gl_FragColor = (res == %s)
> -    ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0);
> -}
> -
> -[test]
> -draw rect -1 -1 2 2
> -probe all rgb 0.0 1.0 0.0
> -""" % (s[0], func, input1, spaces, input2, expected)
> -    f.write(test)
> +""" Generate tests for builtin const equality tests """
>
> +from __future__ import print_function
> +import re
> +import os
> +import textwrap
> +import mako.template
> +
> +TEMPLATE = mako.template.Template(textwrap.dedent("""
> +    [require]
> +    GLSL >= 1.20
> +
> +    [vertex shader]
> +    void main()
> +    {
> +      gl_Position = gl_Vertex;
> +    }
> +
> +    [fragment shader]
> +    void main()
> +    {
> +      const ${expected.split('(')[0]} res = ${func}(${input[0]}, ${input[1]});
> +      gl_FragColor = (res == ${expected})
> +        ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0);
> +    }
> +
> +    [test]
> +    draw rect -1 -1 2 2
> +    probe all rgb 0.0 1.0 0.0"""))
>
>  test_vectors = [
>      [
> @@ -96,9 +109,9 @@ for x in test_vectors:
>
>      print(name)
>
> -    f = open(name, "w")
> -    emit_test(f, "equal", x[0], x[1], x[2])
> -    f.close()
> +    with open(name, 'w+') as f:
> +        f.write(TEMPLATE.render_unicode(
> +            func='equal', input=x[0:2], expected=x[2]))
>
>
>  test_id = 2
> @@ -115,6 +128,6 @@ for x in test_vectors:
>
>      print(name)
>
> -    f = open(name, "w")
> -    emit_test(f, "notEqual", x[0], x[1], expected)
> -    f.close()
> +    with open(name, 'w+') as f:

Why w+?

> +        f.write(TEMPLATE.render_unicode(
> +            func='notEqual', input=x[0:2], expected=expected))
> --
> 2.0.0.rc2
>
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/piglit


More information about the Piglit mailing list