Apply _RELATIVE relocations ahead of others.
[chromium-blink-merge.git] / gpu / khronos_glcts_support / generate_khronos_glcts_tests.py
blob31472865b116ad44665fdf9a38c7036ec37d18a2
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 def ReadFileAsLines(filename):
24 """
25 Reads a file, yielding each non-blank line
26 and lines that don't begin with #
27 """
28 file = open(filename, "r")
29 lines = file.readlines()
30 file.close()
31 for line in lines:
32 line = line.strip()
33 if len(line) > 0 and not line.startswith("#"):
34 yield line
36 def ReadRunFile(run_file):
37 """
38 Find all .test tests in a .run file and return their paths.
39 If the .run file contains another .run file, then that is inspected
40 too.
41 """
42 tests = list()
43 base_dir = os.path.dirname(run_file)
44 for line in ReadFileAsLines(run_file):
45 root, ext = os.path.splitext(line)
46 if ext == ".test":
47 tests.append(os.path.join(base_dir, line))
48 elif ext == ".run":
49 tests += ReadRunFile(os.path.join(base_dir, line))
50 else:
51 raise ValueError, "Unexpected line '%s' in '%s'" % (line, run_file)
52 return tests
54 def GenerateTests(run_files, output):
55 """
56 Generates code for khronos_glcts_test test-cases that are
57 listed in the run_files.
58 """
59 output.write('#include "gpu/khronos_glcts_support/khronos_glcts_test.h"\n')
60 output.write('#include "testing/gtest/include/gtest/gtest.h"\n\n')
62 for run_file in run_files:
63 run_file_name = os.path.basename(run_file)
64 run_file_dir = os.path.dirname(run_file)
65 suite_prefix = RUN_FILE_SUITE_PREFIX[run_file_name]
66 output.write("// " + run_file_name + "\n")
67 for test in ReadRunFile(run_file):
68 rel_path = os.path.relpath(test, run_file_dir)
69 root, ext = os.path.splitext(rel_path)
70 name = root.replace('.', '_')
71 name = "%s.%s" % (suite_prefix, name.replace(os.path.sep, '.'))
72 output.write(TEST_DEF_TEMPLATE
73 % {
74 "gname": re.sub(r'[^A-Za-z0-9]', '_', name),
75 "cname": name,
77 output.write("\n");
79 def main():
80 """This is the main function."""
81 parser = argparse.ArgumentParser()
82 parser.add_argument("--outdir", default = ".")
83 parser.add_argument("run_files", nargs = "+")
85 args = parser.parse_args()
87 output = open(
88 os.path.join(args.outdir, "khronos_glcts_test_autogen.cc"), "wb")
90 try:
91 GenerateTests(args.run_files, output)
92 finally:
93 output.close()
95 return 0
97 if __name__ == '__main__':
98 sys.exit(main())