2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """Code generator for khronos_glcts tests."""
13 TEST_DEF_TEMPLATE
= """
14 TEST(KhronosGLCTSTest, %(gname)s) {
15 EXPECT_TRUE(RunKhronosGLCTSTest("%(cname)s"));
19 RUN_FILE_SUITE_PREFIX
= {
20 "mustpass_es20.run" : "ES2-CTS.gtf",
24 "mustpass_es20.run" : [
26 "ES2-CTS.info.vendor",
27 "ES2-CTS.info.renderer",
28 "ES2-CTS.info.version",
29 "ES2-CTS.info.shading_language_version",
30 "ES2-CTS.info.extensions",
31 "ES2-CTS.info.render_target",
35 def ReadFileAsLines(filename
):
37 Reads a file, yielding each non-blank line
38 and lines that don't begin with #
40 file = open(filename
, "r")
41 lines
= file.readlines()
45 if len(line
) > 0 and not line
.startswith("#"):
48 def ReadRunFile(run_file
):
50 Find all .test tests in a .run file and return their paths.
51 If the .run file contains another .run file, then that is inspected
55 base_dir
= os
.path
.dirname(run_file
)
56 for line
in ReadFileAsLines(run_file
):
57 root
, ext
= os
.path
.splitext(line
)
59 tests
.append(os
.path
.join(base_dir
, line
))
61 tests
+= ReadRunFile(os
.path
.join(base_dir
, line
))
63 raise ValueError, "Unexpected line '%s' in '%s'" % (line
, run_file
)
66 def GenerateTests(run_files
, output
):
68 Generates code for khronos_glcts_test test-cases that are
69 listed in the run_files.
71 output
.write('#include "gpu/khronos_glcts_support/khronos_glcts_test.h"\n')
72 output
.write('#include "testing/gtest/include/gtest/gtest.h"\n\n')
74 for run_file
in run_files
:
75 run_file_name
= os
.path
.basename(run_file
)
76 run_file_dir
= os
.path
.dirname(run_file
)
77 suite_prefix
= RUN_FILE_SUITE_PREFIX
[run_file_name
]
78 output
.write("// " + run_file_name
+ "\n")
79 builtin_tests
= BUILT_IN_TESTS
[run_file_name
]
80 for test
in builtin_tests
:
81 output
.write(TEST_DEF_TEMPLATE
83 "gname": re
.sub(r
'[^A-Za-z0-9]', '_', test
),
86 for test
in ReadRunFile(run_file
):
87 rel_path
= os
.path
.relpath(test
, run_file_dir
)
88 root
, ext
= os
.path
.splitext(rel_path
)
89 name
= root
.replace('.', '_')
90 name
= "%s.%s" % (suite_prefix
, name
.replace(os
.path
.sep
, '.'))
91 output
.write(TEST_DEF_TEMPLATE
93 "gname": re
.sub(r
'[^A-Za-z0-9]', '_', name
),
99 """This is the main function."""
100 parser
= argparse
.ArgumentParser()
101 parser
.add_argument("--outdir", default
= ".")
102 parser
.add_argument("run_files", nargs
= "+")
104 args
= parser
.parse_args()
107 os
.path
.join(args
.outdir
, "khronos_glcts_test_autogen.cc"), "wb")
110 GenerateTests(args
.run_files
, output
)
116 if __name__
== '__main__':