ext_transform_feedback: document missing mode in usage
[piglit.git] / tests / serializer.py
blob5ee9a15786987118cfaa1459e6b5c02ebdeeffaf
1 # encoding=utf-8
2 # Copyright © 2018 Intel Corporation
4 # Permission is hereby granted, free of charge, to any person obtaining a copy
5 # of this software and associated documentation files (the "Software"), to deal
6 # in the Software without restriction, including without limitation the rights
7 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 # copies of the Software, and to permit persons to whom the Software is
9 # furnished to do so, subject to the following conditions:
11 # The above copyright notice and this permission notice shall be included in
12 # all copies or substantial portions of the Software.
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 # SOFTWARE.
22 """Script for taking profiles in python format and serializing them to XML."""
24 import argparse
25 import gzip
26 import os
27 import sys
28 import xml.etree.ElementTree as et
30 sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))
32 from framework.test.piglit_test import (
33 PiglitGLTest, PiglitCLTest, ASMParserTest, BuiltInConstantsTest,
34 CLProgramTester, VkRunnerTest
36 from framework.test.shader_test import ShaderTest, MultiShaderTest
37 from framework.test.glsl_parser_test import GLSLParserTest
38 from framework.profile import load_test_profile
39 from framework.options import OPTIONS
42 def parser():
43 """Parse command line arguments."""
44 parser = argparse.ArgumentParser()
45 parser.add_argument('name')
46 parser.add_argument('input')
47 parser.add_argument('output')
48 parser.add_argument('--no-process-isolation', action='store_true')
49 parser.add_argument('--glsl-arb-compat', action='store_true')
50 args = parser.parse_args()
51 return args
54 def _serialize_skips(test, elem):
55 elems = [
56 ('require_shader', 'shader_version'),
57 ('require_api', 'api'),
58 ('require_version', 'api_version'),
59 ('require_extensions', 'extensions'),
61 for e, f in elems:
62 value = getattr(test, e, None)
64 # For most tests (except MultiShader, we use the test value 'e', but
65 # for MultiShader what's exposed is a FastSkip object, and the methods
66 # are 'f'
67 if not value:
68 value = getattr(test, f, None)
69 if value:
70 et.SubElement(elem, 'option', name=f, value=repr(value))
73 def serializer(name, profile, outfile):
74 """Take each test in the profile and write it out into the xml."""
75 # TODO: This is going to take a lot of memory
76 root = et.Element('PiglitTestList', count=str(len(profile)),
77 name=name)
78 for name, test in profile.itertests():
79 if isinstance(test, PiglitGLTest):
80 elem = et.SubElement(root, 'Test', type='gl', name=name)
81 if test.require_platforms:
82 et.SubElement(elem, 'option', name='require_platforms',
83 value=repr(test.require_platforms))
84 if test.exclude_platforms:
85 et.SubElement(elem, 'option', name='exclude_platforms',
86 value=repr(test.exclude_platforms))
87 _serialize_skips(test, elem)
88 elif isinstance(test, BuiltInConstantsTest):
89 elem = et.SubElement(root, 'Test', type='gl_builtin', name=name)
90 elif isinstance(test, GLSLParserTest):
91 elem = et.SubElement(root, 'Test', type='glsl_parser', name=name)
92 _serialize_skips(test, elem)
93 elif isinstance(test, ASMParserTest):
94 elem = et.SubElement(root, 'Test', type='asm_parser', name=name)
95 et.SubElement(elem, 'option', name='type_',
96 value=repr(test.command[1]))
97 et.SubElement(elem, 'option', name='filename',
98 value=repr(test.filename))
99 continue
100 elif isinstance(test, ShaderTest):
101 elem = et.SubElement(root, 'Test', type='shader', name=name)
102 _serialize_skips(test, elem)
103 elif isinstance(test, MultiShaderTest):
104 elem = et.SubElement(root, 'Test', type='multi_shader', name=name)
105 et.SubElement(elem, 'option', name='prog', value=repr(test.prog))
106 et.SubElement(elem, 'option', name='files', value=repr(test.files))
107 et.SubElement(elem, 'option', name='subtests', value=repr(test.subtests))
108 skips = et.SubElement(elem, 'Skips')
109 for s in test.skips:
110 skip = et.SubElement(skips, 'Skip')
111 _serialize_skips(s, skip)
112 continue
113 elif isinstance(test, CLProgramTester):
114 elem = et.SubElement(root, 'Test', type='cl_prog', name=name)
115 et.SubElement(elem, 'option', name='filename',
116 value=repr(test.filename))
117 continue
118 elif isinstance(test, PiglitCLTest):
119 elem = et.SubElement(root, 'Test', type='cl', name=name)
120 et.SubElement(elem, 'option', name='command', value=repr(test._command))
121 continue
122 elif isinstance(test, VkRunnerTest):
123 elem = et.SubElement(root, 'Test', type='vkrunner', name=name)
124 et.SubElement(elem, 'option', name='filename',
125 value=repr(test.filename))
126 continue
127 else:
128 continue
130 et.SubElement(elem, 'option', name='command', value=repr(test._command))
131 et.SubElement(elem, 'option', name='run_concurrent',
132 value=repr(test.run_concurrent))
133 if test.cwd:
134 et.SubElement(elem, 'option', name='cwd', value=test.cwd)
135 if test.env:
136 env = et.SubElement(elem, 'environment')
137 for k, v in test.env.items():
138 et.SubElement(env, 'env', name=k, value=v)
140 tree = et.ElementTree(root)
141 reproducible_mtime = None
142 if 'SOURCE_DATE_EPOCH' in os.environ:
143 reproducible_mtime=os.environ['SOURCE_DATE_EPOCH']
144 with gzip.GzipFile(outfile, 'wb', mtime=reproducible_mtime) as f:
145 tree.write(f, encoding='utf-8', xml_declaration=True)
148 def main():
149 args = parser()
150 OPTIONS.process_isolation = not args.no_process_isolation
151 if args.glsl_arb_compat:
152 os.environ['PIGLIT_FORCE_GLSLPARSER_DESKTOP'] = 'true'
153 profile = load_test_profile(args.input, python=True)
154 serializer(args.name, profile, args.output)
157 if __name__ == '__main__':
158 main()