cmake: move first batch of option() at the beggining of the file
[piglit.git] / generated_tests / gen_inout_fp64.py
blobd36a9a1d60defce4301391d4adfef6950a7751fe
1 # coding=utf-8
3 # Copyright © 2016 Intel Corporation
5 # Permission is hereby granted, free of charge, to any person obtaining a
6 # copy of this software and associated documentation files (the "Software"),
7 # to deal in the Software without restriction, including without limitation
8 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 # and/or sell copies of the Software, and to permit persons to whom the
10 # Software is furnished to do so, subject to the following conditions:
12 # The above copyright notice and this permission notice (including the next
13 # paragraph) shall be included in all copies or substantial portions of the
14 # Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 # DEALINGS IN THE SOFTWARE.
24 """Generate in/out fp64 compilation tests."""
26 import argparse
27 import os
28 import itertools
30 from templates import template_dir
31 from modules import utils
33 TEMPLATES = template_dir(os.path.basename(os.path.splitext(__file__)[0]))
35 def get_dir_name(ver, test_type):
36 """Returns the directory name to save tests given a GLSL version."""
38 assert isinstance(ver, str)
39 assert isinstance(test_type, str)
40 if ver == '150':
41 feature_dir = 'arb_gpu_shader_fp64'
42 else:
43 feature_dir = 'glsl-' + ver[0] + '.' + ver[1:]
45 return os.path.join('spec', feature_dir, test_type,
46 'inout')
49 def generate_compilation_tests(type_name, shader, ver, names_only):
50 """Generate in/out GLSL compilation tests."""
52 assert isinstance(type_name, str)
53 assert shader in ('vert', 'frag')
54 assert isinstance(ver, str)
55 assert isinstance(names_only, bool)
57 filename = os.path.join(
58 get_dir_name(ver, 'compiler'),
59 '{0}-{1}put-{2}.{3}'.format('fs' if shader == 'frag' else 'vs',
60 'out' if shader == 'frag' else 'in',
61 type_name, shader))
63 print(filename)
65 if not names_only:
66 with open(filename, 'w') as test_file:
67 test_file.write(TEMPLATES.get_template(
68 'template.{0}.mako'.format(shader)).render_unicode(
69 glsl_version='{}.{}'.format(ver[0], ver[1:]),
70 glsl_version_int=ver,
71 type_name=type_name,
72 extra_params=',0.0' if type_name in ['dvec2', 'dvec3'] else ''))
75 def all_compilation_tests(names_only):
76 """Creates all the combinations for in/out compilation tests."""
78 assert isinstance(names_only, bool)
79 type_names = ['double', 'dvec2', 'dvec3', 'dvec4',
80 'dmat2', 'dmat2x3', 'dmat2x4',
81 'dmat3x2', 'dmat3', 'dmat3x4',
82 'dmat4x2', 'dmat4x3', 'dmat4']
83 shaders = ['frag', 'vert']
84 glsl_ver = ['150', '400']
85 if not names_only:
86 for ver in glsl_ver:
87 utils.safe_makedirs(get_dir_name(ver, 'compiler'))
89 for t_name, shader, ver in itertools.product(type_names, shaders, glsl_ver):
90 yield t_name, shader, ver, names_only
93 def main():
94 """Main function."""
96 parser = argparse.ArgumentParser(
97 description="Generate in/out compilation tests for fp64")
98 parser.add_argument(
99 '--names-only',
100 dest='names_only',
101 action='store_true',
102 default=False,
103 help="Don't output files, just generate a list of filenames to stdout")
104 args = parser.parse_args()
106 for test_args in all_compilation_tests(args.names_only):
107 generate_compilation_tests(*test_args)
110 if __name__ == '__main__':
111 main()