OLD | NEW |
1 # Copyright 2012 the V8 project authors. All rights reserved. | 1 # Copyright 2012 the V8 project authors. All rights reserved. |
2 # Redistribution and use in source and binary forms, with or without | 2 # Redistribution and use in source and binary forms, with or without |
3 # modification, are permitted provided that the following conditions are | 3 # modification, are permitted provided that the following conditions are |
4 # met: | 4 # met: |
5 # | 5 # |
6 # * Redistributions of source code must retain the above copyright | 6 # * Redistributions of source code must retain the above copyright |
7 # notice, this list of conditions and the following disclaimer. | 7 # notice, this list of conditions and the following disclaimer. |
8 # * Redistributions in binary form must reproduce the above | 8 # * Redistributions in binary form must reproduce the above |
9 # copyright notice, this list of conditions and the following | 9 # copyright notice, this list of conditions and the following |
10 # disclaimer in the documentation and/or other materials provided | 10 # disclaimer in the documentation and/or other materials provided |
11 # with the distribution. | 11 # with the distribution. |
12 # * Neither the name of Google Inc. nor the names of its | 12 # * Neither the name of Google Inc. nor the names of its |
13 # contributors may be used to endorse or promote products derived | 13 # contributors may be used to endorse or promote products derived |
14 # from this software without specific prior written permission. | 14 # from this software without specific prior written permission. |
15 # | 15 # |
16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 | 28 |
| 29 import test |
| 30 import os |
| 31 from os.path import join, exists |
| 32 import urllib |
29 import hashlib | 33 import hashlib |
30 import os | |
31 import sys | 34 import sys |
32 import tarfile | 35 import tarfile |
33 import urllib | |
34 | |
35 from testrunner.local import testsuite | |
36 from testrunner.objects import testcase | |
37 | 36 |
38 | 37 |
39 TEST_262_ARCHIVE_REVISION = "fb327c439e20" # This is the r334 revision. | 38 TEST_262_ARCHIVE_REVISION = 'fb327c439e20' # This is the r334 revision. |
40 TEST_262_ARCHIVE_MD5 = "307acd166ec34629592f240dc12d57ed" | 39 TEST_262_ARCHIVE_MD5 = '307acd166ec34629592f240dc12d57ed' |
41 TEST_262_URL = "http://hg.ecmascript.org/tests/test262/archive/%s.tar.bz2" | 40 TEST_262_URL = 'http://hg.ecmascript.org/tests/test262/archive/%s.tar.bz2' |
42 TEST_262_HARNESS = ["sta.js"] | 41 TEST_262_HARNESS = ['sta.js'] |
43 | |
44 | |
45 class Test262TestSuite(testsuite.TestSuite): | |
46 | |
47 def __init__(self, name, root): | |
48 super(Test262TestSuite, self).__init__(name, root) | |
49 self.testroot = os.path.join(root, "data", "test", "suite") | |
50 self.harness = [os.path.join(self.root, "data", "test", "harness", f) | |
51 for f in TEST_262_HARNESS] | |
52 self.harness += [os.path.join(self.root, "harness-adapt.js")] | |
53 | |
54 def CommonTestName(self, testcase): | |
55 return testcase.path.split(os.path.sep)[-1] | |
56 | |
57 def ListTests(self, context): | |
58 tests = [] | |
59 for dirname, dirs, files in os.walk(self.testroot): | |
60 for dotted in [x for x in dirs if x.startswith(".")]: | |
61 dirs.remove(dotted) | |
62 dirs.sort() | |
63 files.sort() | |
64 for filename in files: | |
65 if filename.endswith(".js"): | |
66 testname = os.path.join(dirname[len(self.testroot) + 1:], | |
67 filename[:-3]) | |
68 case = testcase.TestCase(self, testname) | |
69 tests.append(case) | |
70 return tests | |
71 | |
72 def GetFlagsForTestCase(self, testcase, context): | |
73 return (testcase.flags + context.mode_flags + self.harness + | |
74 [os.path.join(self.testroot, testcase.path + ".js")]) | |
75 | |
76 def GetSourceForTest(self, testcase): | |
77 filename = os.path.join(self.testroot, testcase.path + ".js") | |
78 with open(filename) as f: | |
79 return f.read() | |
80 | |
81 def IsNegativeTest(self, testcase): | |
82 return "@negative" in self.GetSourceForTest(testcase) | |
83 | |
84 def IsFailureOutput(self, output, testpath): | |
85 if output.exit_code != 0: | |
86 return True | |
87 return "FAILED!" in output.stdout | |
88 | |
89 def DownloadData(self): | |
90 revision = TEST_262_ARCHIVE_REVISION | |
91 archive_url = TEST_262_URL % revision | |
92 archive_name = os.path.join(self.root, "test262-%s.tar.bz2" % revision) | |
93 directory_name = os.path.join(self.root, "data") | |
94 directory_old_name = os.path.join(self.root, "data.old") | |
95 if not os.path.exists(archive_name): | |
96 print "Downloading test data from %s ..." % archive_url | |
97 urllib.urlretrieve(archive_url, archive_name) | |
98 if os.path.exists(directory_name): | |
99 os.rename(directory_name, directory_old_name) | |
100 if not os.path.exists(directory_name): | |
101 print "Extracting test262-%s.tar.bz2 ..." % revision | |
102 md5 = hashlib.md5() | |
103 with open(archive_name, "rb") as f: | |
104 for chunk in iter(lambda: f.read(8192), ""): | |
105 md5.update(chunk) | |
106 if md5.hexdigest() != TEST_262_ARCHIVE_MD5: | |
107 os.remove(archive_name) | |
108 raise Exception("Hash mismatch of test data file") | |
109 archive = tarfile.open(archive_name, "r:bz2") | |
110 if sys.platform in ("win32", "cygwin"): | |
111 # Magic incantation to allow longer path names on Windows. | |
112 archive.extractall(u"\\\\?\\%s" % self.root) | |
113 else: | |
114 archive.extractall(self.root) | |
115 os.rename(os.path.join(self.root, "test262-%s" % revision), | |
116 directory_name) | |
117 | |
118 | |
119 def GetSuite(name, root): | |
120 return Test262TestSuite(name, root) | |
121 | |
122 | |
123 # Deprecated definitions below. | |
124 # TODO(jkummerow): Remove when SCons is no longer supported. | |
125 | |
126 | |
127 from os.path import exists | |
128 from os.path import join | |
129 import test | |
130 | 42 |
131 | 43 |
132 class Test262TestCase(test.TestCase): | 44 class Test262TestCase(test.TestCase): |
133 | 45 |
134 def __init__(self, filename, path, context, root, mode, framework): | 46 def __init__(self, filename, path, context, root, mode, framework): |
135 super(Test262TestCase, self).__init__(context, path, mode) | 47 super(Test262TestCase, self).__init__(context, path, mode) |
136 self.filename = filename | 48 self.filename = filename |
137 self.framework = framework | 49 self.framework = framework |
138 self.root = root | 50 self.root = root |
139 | 51 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 return ['d8'] | 133 return ['d8'] |
222 | 134 |
223 def GetTestStatus(self, sections, defs): | 135 def GetTestStatus(self, sections, defs): |
224 status_file = join(self.root, 'test262.status') | 136 status_file = join(self.root, 'test262.status') |
225 if exists(status_file): | 137 if exists(status_file): |
226 test.ReadConfigurationInto(status_file, sections, defs) | 138 test.ReadConfigurationInto(status_file, sections, defs) |
227 | 139 |
228 | 140 |
229 def GetConfiguration(context, root): | 141 def GetConfiguration(context, root): |
230 return Test262TestConfiguration(context, root) | 142 return Test262TestConfiguration(context, root) |
OLD | NEW |