gen_const_builtin_equal_tests.py 3.47 KB
Newer Older
1
# Copyright (c) 2010, 2014 Intel Corporation
2

3 4 5 6 7 8
# 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:
9

10 11
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
12

13 14 15 16 17 18 19
# 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.
20

21
""" Generate tests for builtin const equality tests """
22

23
from __future__ import print_function, division, absolute_import
24 25
import re
import os
26 27

from templates import template_file
28
from modules import utils
29 30 31

TEMPLATE = template_file(os.path.basename(os.path.splitext(__file__)[0]),
                         'template.shader_test.mako')
32

33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
TEST_VECTORS = [
    ["vec2(3.0, 3.14)",
     "vec2(-6.0, 7.88)",
     "bvec2(false, false)"
    ],
    ["vec3(13.4, -0.9, 12.55)",
     "vec3(13.4, 12.0, -55.3)",
     "bvec3(true, false, false)"
    ],
    ["vec4(-2.0, 0.0, 0.123, -1000.5)",
     "vec4(-2.4, 0.0, 0.456, 12.5)",
     "bvec4(false, true, false, false)"
    ],
    ["ivec2(-8, 12)",
     "ivec2(-19, 12)",
     "bvec2(false, true)"
    ],
    ["ivec3(0, 8, 89)",
     "ivec3(4, -7, 33)",
     "bvec3(false, false, false)"
    ],
    ["ivec4(11, 1000, 1, -18)",
     "ivec4(55, 1000, -21, -17)",
     "bvec4(false, true, false, false)"
    ],
    ["bvec2(true, false)",
     "bvec2(true, true)",
     "bvec2(true, false)"
    ],
    ["bvec3(false, true, false)",
     "bvec3(false, false, true)",
     "bvec3(true, false, false)"
    ],
    ["bvec4(true, false, false, true)",
     "bvec4(true, true, false, false)",
     "bvec4(true, false, true, false)"
    ],
]
71

72

73 74
def main():
    """ Main function """
75 76
    dirname = os.path.join('spec', 'glsl-1.20', 'execution',
                           'built-in-functions')
77
    utils.safe_makedirs(dirname)
78

79
    for test_id, x in enumerate(TEST_VECTORS, start=2):
80
        # make equal tests
81 82 83 84
        name = os.path.join(
            dirname,
            "glsl-const-builtin-equal-{0:02d}.shader_test".format(test_id))

85
        print(name)
86

87 88 89
        with open(name, 'w') as f:
            f.write(TEMPLATE.render_unicode(
                func='equal', input=x[0:2], expected=x[2]))
90

91
        # make notEqual tests
92 93 94
        name = os.path.join(
            dirname,
            "glsl-const-builtin-notEqual-{0:02d}.shader_test".format(test_id))
95

96 97 98 99 100
        # When generating the notEqual tests, each of the values in the
        # expected result vector need to be inverted
        expected = re.sub("true", "FALSE", x[2])
        expected = re.sub("false", "TRUE", expected)
        expected = expected.lower()
101

102
        print(name)
103

104 105 106
        with open(name, 'w') as f:
            f.write(TEMPLATE.render_unicode(
                func='notEqual', input=x[0:2], expected=expected))
107

108

109 110
if __name__ == "__main__":
    main()