Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / gpu / khronos_glcts_support / generate_khronos_glcts_tests.py
blob2b4705bb822c0b917d4943113ff2f8abd3bbe73d
1 #!/usr/bin/env python
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."""
8 import os
9 import re
10 import sys
11 import argparse
13 TEST_DEF_TEMPLATE = """
14 TEST(KhronosGLCTSTest, %(gname)s) {
15 EXPECT_TRUE(RunKhronosGLCTSTest("%(cname)s"));
17 """
19 RUN_FILE_SUITE_PREFIX = {
20 "mustpass_es20.run" : "ES2-CTS.gtf",
23 BUILT_IN_TESTS = {
24 "mustpass_es20.run" : [
25 "CTS-Configs.es2",
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):
36 """
37 Reads a file, yielding each non-blank line
38 and lines that don't begin with #
39 """
40 file = open(filename, "r")
41 lines = file.readlines()
42 file.close()
43 for line in lines:
44 line = line.strip()
45 if len(line) > 0 and not line.startswith("#"):
46 yield line
48 def ReadRunFile(run_file):
49 """
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
52 too.
53 """
54 tests = list()
55 base_dir = os.path.dirname(run_file)
56 for line in ReadFileAsLines(run_file):
57 root, ext = os.path.splitext(line)
58 if ext == ".test":
59 tests.append(os.path.join(base_dir, line))
60 elif ext == ".run":
61 tests += ReadRunFile(os.path.join(base_dir, line))
62 else:
63 raise ValueError, "Unexpected line '%s' in '%s'" % (line, run_file)
64 return tests
66 def GenerateTests(run_files, output):
67 """
68 Generates code for khronos_glcts_test test-cases that are
69 listed in the run_files.
70 """
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
82 % {
83 "gname": re.sub(r'[^A-Za-z0-9]', '_', test),
84 "cname": 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
92 % {
93 "gname": re.sub(r'[^A-Za-z0-9]', '_', name),
94 "cname": name,
96 output.write("\n");
98 def main():
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()
106 output = open(
107 os.path.join(args.outdir, "khronos_glcts_test_autogen.cc"), "wb")
109 try:
110 GenerateTests(args.run_files, output)
111 finally:
112 output.close()
114 return 0
116 if __name__ == '__main__':
117 sys.exit(main())