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 |
| 31 suites = ["kraken-1.1", "kraken-1.0", "sunspider-0.9.1"] |
| 32 |
| 33 def readTemplate(path): |
| 34 with open(path, 'r') as f: |
| 35 return f.read() |
| 36 |
| 37 template = readTemplate("resources/TEMPLATE.html") |
| 38 driverTemplate = readTemplate("resources/driver-TEMPLATE.html") |
| 39 resultsTemplate = readTemplate("resources/results-TEMPLATE.html") |
| 40 |
| 41 def testListForSuite(suite): |
| 42 tests = [] |
| 43 with open("./tests/%s/LIST" % suite, "r") as f: |
| 44 for line in f.readlines(): |
| 45 tests.append(line.strip()) |
| 46 return tests |
| 47 |
| 48 def categoriesFromTests(tests): |
| 49 categories = set() |
| 50 for test in tests: |
| 51 categories.add(test[:test.find("-")]) |
| 52 categories = list(categories) |
| 53 categories.sort() |
| 54 return categories |
| 55 |
| 56 def escapeTestContent(test,suite): |
| 57 with open("tests/" + suite + "/" + test + ".js") as f: |
| 58 script = f.read() |
| 59 output = template |
| 60 output = output.replace("@NAME@", test) |
| 61 output = output.replace("@SCRIPT@", script) |
| 62 dataPath = "tests/" + suite + "/" + test + "-data.js" |
| 63 if (os.path.exists(dataPath)): |
| 64 with open(dataPath) as f: |
| 65 datascript = f.read() |
| 66 output = output.replace("@DATASCRIPT@", datascript) |
| 67 datascript = None |
| 68 output = output.replace("\\", "\\\\") |
| 69 output = output.replace('"', '\\"') |
| 70 output = output.replace("\n", "\\n\\\n") |
| 71 return output |
| 72 |
| 73 def testContentsFromTests(suite, tests): |
| 74 testContents = []; |
| 75 for test in tests: |
| 76 testContents.append(escapeTestContent(test, suite)) |
| 77 return testContents |
| 78 |
| 79 def writeTemplate(suite, template, fileName): |
| 80 output = template.replace("@SUITE@", suite) |
| 81 with open("hosted/" + suite + "/" + fileName, "w") as f: |
| 82 f.write(output) |
| 83 |
| 84 for suite in suites: |
| 85 suiteDir = os.path.join("hosted", suite) |
| 86 if not os.path.exists(suiteDir): |
| 87 os.mkdir(suiteDir) |
| 88 tests = testListForSuite(suite) |
| 89 categories = categoriesFromTests(tests) |
| 90 testContents = testContentsFromTests(suite, tests) |
| 91 writeTemplate(suite, driverTemplate, "driver.html") |
| 92 writeTemplate(suite, resultsTemplate, "results.html") |
| 93 |
| 94 prefix = "var tests = [ " + ", ".join(['"%s"' % s for s in tests]) + " ];\n" |
| 95 prefix += "var categories = [ " + ", ".join(['"%s"' % s for s in categories]
) + " ];\n" |
| 96 with open("hosted/" + suite + "/test-prefix.js", "w") as f: |
| 97 f.write(prefix) |
| 98 |
| 99 contents = "var testContents = [ " + ", ".join(['"%s"' % s for s in testCont
ents]) + " ];\n" |
| 100 with open("hosted/" + suite + "/test-contents.js", "w") as f: |
| 101 f.write(contents) |
| 102 |
| 103 shutil.copyfile("resources/analyze-results.js", "hosted/analyze-results.js") |
| 104 shutil.copyfile("resources/compare-results.js", "hosted/compare-results.js") |
| 105 |
| 106 print("You're awesome!") |
OLD | NEW |