Chromium Code Reviews| Index: gpu/khronos_conform_support/generate_khronos_conform_tests.py |
| diff --git a/gpu/khronos_conform_support/generate_khronos_conform_tests.py b/gpu/khronos_conform_support/generate_khronos_conform_tests.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..3ff7d995f4234fffed381872c887c484893f8999 |
| --- /dev/null |
| +++ b/gpu/khronos_conform_support/generate_khronos_conform_tests.py |
| @@ -0,0 +1,98 @@ |
| +#!/usr/bin/env python |
|
piman
2014/09/10 20:12:50
This file looks very similar to gpu/gles2_conform
U. Artie Eoff
2014/09/10 22:12:59
There are quite a few differences between the two
Ken Russell (switch to Gerrit)
2014/09/11 00:03:26
As unfortunate as code duplication in this area is
U. Artie Eoff
2014/09/11 01:09:20
Yes, this new suite *does* subsume the ES2 conform
Ken Russell (switch to Gerrit)
2014/09/11 01:25:17
That's very good. We would be highly interested in
U. Artie Eoff
2014/09/11 16:50:53
I haven't been able to get *pristine* Chromium to
Ken Russell (switch to Gerrit)
2014/09/11 17:40:04
You certainly have my support. Could you please up
U. Artie Eoff
2014/09/11 19:45:25
Excellent! The CL updates are on the way ;) Yes, I
|
| +# Copyright 2014 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +"""Code generator for khronos_conformance tests.""" |
| + |
| +import os |
| +import re |
| +import sys |
| +import argparse |
| + |
| +TEST_DEF_TEMPLATE = """ |
| +TEST(KhronosConformTest, %(gname)s) { |
| + EXPECT_TRUE(RunKhronosConformTest("%(cname)s")); |
| +} |
| +""" |
| + |
| +RUN_FILE_SUITE_PREFIX = { |
| + "mustpass_es20.run" : "ES2-CTS.gtf", |
| +} |
| + |
| +def ReadFileAsLines(filename): |
| + """ |
| + Reads a file, yielding each non-blank line |
| + and lines that don't begin with # |
| + """ |
| + file = open(filename, "r") |
| + lines = file.readlines() |
| + file.close() |
| + for line in lines: |
| + line = line.strip() |
| + if len(line) > 0 and not line.startswith("#"): |
| + yield line |
| + |
| +def ReadRunFile(run_file): |
| + """ |
| + Find all .test tests in a .run file and return their paths. |
| + If the .run file contains another .run file, then that is inspected |
| + too. |
| + """ |
| + tests = list() |
| + base_dir = os.path.dirname(run_file) |
| + for line in ReadFileAsLines(run_file): |
| + root, ext = os.path.splitext(line) |
| + if ext == ".test": |
| + tests.append(os.path.join(base_dir, line)) |
| + elif ext == ".run": |
| + tests += ReadRunFile(os.path.join(base_dir, line)) |
| + else: |
| + raise ValueError, "Unexpected line '%s' in '%s'" % (line, run_file) |
| + return tests |
| + |
| +def GenerateTests(run_files, output): |
| + """ |
| + Generates code for khronos_conform_test test-cases that are |
| + listed in the run_files. |
| + """ |
| + output.write('#include "gpu/khronos_conform_support/khronos_conform_test.h"\n') |
| + output.write('#include "testing/gtest/include/gtest/gtest.h"\n\n') |
| + |
| + for run_file in run_files: |
| + run_file_name = os.path.basename(run_file) |
| + run_file_dir = os.path.dirname(run_file) |
| + suite_prefix = RUN_FILE_SUITE_PREFIX[run_file_name] |
| + output.write("// " + run_file_name + "\n") |
| + for test in ReadRunFile(run_file): |
| + rel_path = os.path.relpath(test, run_file_dir) |
| + root, ext = os.path.splitext(rel_path) |
| + name = root.replace('.', '_') |
| + name = "%s.%s" % (suite_prefix, name.replace(os.path.sep, '.')) |
| + output.write(TEST_DEF_TEMPLATE |
| + % { |
| + "gname": re.sub(r'[^A-Za-z0-9]', '_', name), |
| + "cname": name, |
| + }) |
| + output.write("\n"); |
| + |
| +def main(): |
| + """This is the main function.""" |
| + parser = argparse.ArgumentParser() |
| + parser.add_argument("--outdir", default = ".") |
| + parser.add_argument("run_files", nargs = "+") |
| + |
| + args = parser.parse_args() |
| + |
| + output = open( |
| + os.path.join(args.outdir, "khronos_conform_test_autogen.cc"), "wb") |
| + |
| + try: |
| + GenerateTests(args.run_files, output) |
| + finally: |
| + output.close() |
| + |
| + return 0 |
| + |
| +if __name__ == '__main__': |
| + sys.exit(main()) |