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",
23 def ReadFileAsLines(filename
):
25 Reads a file, yielding each non-blank line
26 and lines that don't begin with #
28 file = open(filename
, "r")
29 lines
= file.readlines()
33 if len(line
) > 0 and not line
.startswith("#"):
36 def ReadRunFile(run_file
):
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
43 base_dir
= os
.path
.dirname(run_file
)
44 for line
in ReadFileAsLines(run_file
):
45 root
, ext
= os
.path
.splitext(line
)
47 tests
.append(os
.path
.join(base_dir
, line
))
49 tests
+= ReadRunFile(os
.path
.join(base_dir
, line
))
51 raise ValueError, "Unexpected line '%s' in '%s'" % (line
, run_file
)
54 def GenerateTests(run_files
, output
):
56 Generates code for khronos_glcts_test test-cases that are
57 listed in the run_files.
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
74 "gname": re
.sub(r
'[^A-Za-z0-9]', '_', name
),
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()
88 os
.path
.join(args
.outdir
, "khronos_glcts_test_autogen.cc"), "wb")
91 GenerateTests(args
.run_files
, output
)
97 if __name__
== '__main__':