Save errno for logging before potentially overwriting it.
[chromium-blink-merge.git] / content / browser / gpu / generate_webgl_conformance_test_list.py
blob8d5854ab52d8b63003409446758a427cd30b9e43
1 #!/usr/bin/env python
2 # Copyright (c) 2012 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 """Auto-generates the WebGL conformance test list header file.
8 Parses the WebGL conformance test *.txt file, which contains a list of URLs
9 for individual conformance tests (each on a new line). It recursively parses
10 *.txt files. For each test URL, the matching gtest call is created and
11 sent to the C++ header file.
12 """
14 import getopt
15 import os
16 import re
17 import sys
19 COPYRIGHT = """\
20 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
21 // Use of this source code is governed by a BSD-style license that can be
22 // found in the LICENSE file.
24 """
25 WARNING = """\
26 // DO NOT EDIT! This file is auto-generated by
27 // generate_webgl_conformance_test_list.py
28 // It is included by webgl_conformance_test.cc
30 """
31 HEADER_GUARD = """\
32 #ifndef CONTENT_TEST_GPU_WEBGL_CONFORMANCE_TEST_LIST_AUTOGEN_H_
33 #define CONTENT_TEST_GPU_WEBGL_CONFORMANCE_TEST_LIST_AUTOGEN_H_
35 """
36 HEADER_GUARD_END = """
37 #endif // CONTENT_TEST_GPU_WEBGL_CONFORMANCE_TEST_LIST_AUTOGEN_H_
39 """
41 # Assume this script is run from the src/content/test/gpu directory.
42 INPUT_DIR = "../../../third_party/webgl_conformance"
43 INPUT_FILE = "00_test_list.txt"
44 OUTPUT_FILE = "webgl_conformance_test_list_autogen.h"
46 def main(argv):
47 """Main function for the WebGL conformance test list generator.
48 """
49 if not os.path.exists(os.path.join(INPUT_DIR, INPUT_FILE)):
50 print >> sys.stderr, "ERROR: WebGL conformance tests do not exist."
51 print >> sys.stderr, "Run the script from the directory containing it."
52 return 1
54 output = open(OUTPUT_FILE, "w")
55 output.write(COPYRIGHT)
56 output.write(WARNING)
57 output.write(HEADER_GUARD)
59 test_prefix = {}
61 unparsed_files = [INPUT_FILE]
62 while unparsed_files:
63 filename = unparsed_files.pop(0)
64 try:
65 input = open(os.path.join(INPUT_DIR, filename))
66 except IOError:
67 print >> sys.stderr, "WARNING: %s does not exist (skipped)." % filename
68 continue
70 for url in input:
71 url = re.sub("//.*", "", url)
72 url = re.sub("#.*", "", url)
73 url = url.strip()
74 # Some filename has options before them, for example,
75 # --min-version 1.0.2 testname.html
76 pos = url.rfind(" ")
77 if pos != -1:
78 url = url[pos+1:]
80 if not url:
81 continue
83 # Cannot use os.path.join() because Windows with use "\\" but this path
84 # is sent through javascript.
85 if os.path.dirname(filename):
86 url = "%s/%s" % (os.path.dirname(filename), url)
88 # Queue all text files for parsing, because test list URLs are nested
89 # through .txt files.
90 if re.match(".+\.txt\s*$", url):
91 unparsed_files.append(url)
93 # Convert the filename to a valid test name and output the gtest code.
94 else:
95 name = os.path.splitext(url)[0]
96 name = re.sub("\W+", "_", name)
97 if os.path.exists(os.path.join(INPUT_DIR, url)):
98 output.write('CONFORMANCE_TEST(%s,\n "%s");\n' % (name, url))
99 else:
100 print >> sys.stderr, "WARNING: %s does not exist (skipped)." % url
101 input.close()
103 output.write(HEADER_GUARD_END)
104 output.close()
105 return 0
107 if __name__ == "__main__":
108 sys.exit(main(sys.argv[1:]))