| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/python | |
| 2 | |
| 3 # Copyright (C) 2007 Apple Inc. All rights reserved. | |
| 4 # Copyright (C) 2010 Mozilla Foundation | |
| 5 # | |
| 6 # Redistribution and use in source and binary forms, with or without | |
| 7 # modification, are permitted provided that the following conditions | |
| 8 # are met: | |
| 9 # 1. Redistributions of source code must retain the above copyright | |
| 10 # notice, this list of conditions and the following disclaimer. | |
| 11 # 2. Redistributions in binary form must reproduce the above copyright | |
| 12 # notice, this list of conditions and the following disclaimer in the | |
| 13 # documentation and/or other materials provided with the distribution. | |
| 14 # | |
| 15 # THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | |
| 16 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| 18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
| 19 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
| 20 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 21 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
| 22 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
| 23 # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 24 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 25 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 26 | |
| 27 from __future__ import with_statement | |
| 28 import os | |
| 29 import shutil | |
| 30 import sys | |
| 31 | |
| 32 suites = ["kraken-1.1"] | |
| 33 | |
| 34 def get_tests_path(path): | |
| 35 prefix = sys.argv[1] if len(sys.argv) > 1 else '.' | |
| 36 return os.path.join(prefix, path) | |
| 37 | |
| 38 def get_hosted_path(path): | |
| 39 prefix = sys.argv[2] if len(sys.argv) > 2 else '.' | |
| 40 return os.path.join(prefix, "hosted", path) | |
| 41 | |
| 42 def readTemplate(path): | |
| 43 with open(path, 'r') as f: | |
| 44 return f.read() | |
| 45 | |
| 46 template = readTemplate(get_tests_path("resources/TEMPLATE.html")) | |
| 47 driverTemplate = readTemplate(get_tests_path("resources/driver-TEMPLATE.html")) | |
| 48 resultsTemplate = readTemplate(get_tests_path("resources/results-TEMPLATE.html")
) | |
| 49 | |
| 50 def testListForSuite(suite): | |
| 51 tests = [] | |
| 52 with open(get_tests_path("tests/%s/LIST" % suite), "r") as f: | |
| 53 for line in f.readlines(): | |
| 54 tests.append(line.strip()) | |
| 55 return tests | |
| 56 | |
| 57 def categoriesFromTests(tests): | |
| 58 categories = set() | |
| 59 for test in tests: | |
| 60 categories.add(test[:test.find("-")]) | |
| 61 categories = list(categories) | |
| 62 categories.sort() | |
| 63 return categories | |
| 64 | |
| 65 def escapeTestContent(test,suite): | |
| 66 with open(get_tests_path("tests/" + suite + "/" + test + ".js")) as f: | |
| 67 script = f.read() | |
| 68 output = template | |
| 69 output = output.replace("@NAME@", test) | |
| 70 output = output.replace("@SCRIPT@", script) | |
| 71 dataPath = get_tests_path("tests/" + suite + "/" + test + "-data.js") | |
| 72 if (os.path.exists(dataPath)): | |
| 73 with open(dataPath) as f: | |
| 74 datascript = f.read() | |
| 75 output = output.replace("@DATASCRIPT@", datascript) | |
| 76 datascript = None | |
| 77 output = output.replace("\\", "\\\\") | |
| 78 output = output.replace('"', '\\"') | |
| 79 output = output.replace("\n", "\\n\\\n") | |
| 80 return output | |
| 81 | |
| 82 def testContentsFromTests(suite, tests): | |
| 83 testContents = []; | |
| 84 for test in tests: | |
| 85 testContents.append(escapeTestContent(test, suite)) | |
| 86 return testContents | |
| 87 | |
| 88 def writeTemplate(suite, template, fileName): | |
| 89 output = template.replace("@SUITE@", suite) | |
| 90 with open(get_hosted_path(suite + "/" + fileName), "w") as f: | |
| 91 f.write(output) | |
| 92 | |
| 93 for suite in suites: | |
| 94 suiteDir = get_hosted_path(suite) | |
| 95 if not os.path.exists(suiteDir): | |
| 96 os.makedirs(suiteDir) | |
| 97 tests = testListForSuite(suite) | |
| 98 categories = categoriesFromTests(tests) | |
| 99 testContents = testContentsFromTests(suite, tests) | |
| 100 writeTemplate(suite, driverTemplate, "driver.html") | |
| 101 writeTemplate(suite, resultsTemplate, "results.html") | |
| 102 | |
| 103 prefix = "var tests = [ " + ", ".join(['"%s"' % s for s in tests]) + " ];\n" | |
| 104 prefix += "var categories = [ " + ", ".join(['"%s"' % s for s in categories]
) + " ];\n" | |
| 105 with open(get_hosted_path(suite + "/test-prefix.js"), "w") as f: | |
| 106 f.write(prefix) | |
| 107 | |
| 108 contents = "var testContents = [ " + ", ".join(['"%s"' % s for s in testCont
ents]) + " ];\n" | |
| 109 with open(get_hosted_path(suite + "/test-contents.js"), "w") as f: | |
| 110 f.write(contents) | |
| 111 | |
| 112 shutil.copyfile(get_tests_path("resources/analyze-results.js"), | |
| 113 get_hosted_path("analyze-results.js")) | |
| 114 shutil.copyfile(get_tests_path("resources/compare-results.js"), | |
| 115 get_hosted_path("compare-results.js")) | |
| 116 shutil.copyfile(get_tests_path("hosted/json2.js"), | |
| 117 get_hosted_path("json2.js")) | |
| 118 shutil.copyfile(get_tests_path("hosted/kraken.css"), | |
| 119 get_hosted_path("kraken.css")) | |
| OLD | NEW |