| OLD | NEW |
| (Empty) |
| 1 # Copyright 2012 the V8 project authors. All rights reserved. | |
| 2 # Redistribution and use in source and binary forms, with or without | |
| 3 # modification, are permitted provided that the following conditions are | |
| 4 # met: | |
| 5 # | |
| 6 # * Redistributions of source code must retain the above copyright | |
| 7 # notice, this list of conditions and the following disclaimer. | |
| 8 # * Redistributions in binary form must reproduce the above | |
| 9 # copyright notice, this list of conditions and the following | |
| 10 # disclaimer in the documentation and/or other materials provided | |
| 11 # with the distribution. | |
| 12 # * Neither the name of Google Inc. nor the names of its | |
| 13 # contributors may be used to endorse or promote products derived | |
| 14 # from this software without specific prior written permission. | |
| 15 # | |
| 16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 17 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 18 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 19 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 20 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 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. | |
| 27 | |
| 28 | |
| 29 import hashlib | |
| 30 import os | |
| 31 import shutil | |
| 32 import sys | |
| 33 import tarfile | |
| 34 import imp | |
| 35 | |
| 36 from testrunner.local import statusfile | |
| 37 from testrunner.local import testsuite | |
| 38 from testrunner.local import utils | |
| 39 from testrunner.objects import testcase | |
| 40 | |
| 41 # The revision hash needs to be 7 characters? | |
| 42 TEST_262_ARCHIVE_REVISION = "6137f75" # This is the 2015-08-25 revision. | |
| 43 TEST_262_ARCHIVE_MD5 = "c1eaf890d46e73d6c7e05ab21f76e668" | |
| 44 TEST_262_URL = "https://github.com/tc39/test262/tarball/%s" | |
| 45 TEST_262_HARNESS_FILES = ["sta.js", "assert.js"] | |
| 46 | |
| 47 TEST_262_SUITE_PATH = ["data", "test"] | |
| 48 TEST_262_HARNESS_PATH = ["data", "harness"] | |
| 49 TEST_262_TOOLS_PATH = ["data", "tools", "packaging"] | |
| 50 | |
| 51 ALL_VARIANT_FLAGS_STRICT = dict( | |
| 52 (v, [flags + ["--use-strict"] for flags in flag_sets]) | |
| 53 for v, flag_sets in testsuite.ALL_VARIANT_FLAGS.iteritems() | |
| 54 ) | |
| 55 | |
| 56 FAST_VARIANT_FLAGS_STRICT = dict( | |
| 57 (v, [flags + ["--use-strict"] for flags in flag_sets]) | |
| 58 for v, flag_sets in testsuite.FAST_VARIANT_FLAGS.iteritems() | |
| 59 ) | |
| 60 | |
| 61 ALL_VARIANT_FLAGS_BOTH = dict( | |
| 62 (v, [flags for flags in testsuite.ALL_VARIANT_FLAGS[v] + | |
| 63 ALL_VARIANT_FLAGS_STRICT[v]]) | |
| 64 for v in testsuite.ALL_VARIANT_FLAGS | |
| 65 ) | |
| 66 | |
| 67 FAST_VARIANT_FLAGS_BOTH = dict( | |
| 68 (v, [flags for flags in testsuite.FAST_VARIANT_FLAGS[v] + | |
| 69 FAST_VARIANT_FLAGS_STRICT[v]]) | |
| 70 for v in testsuite.FAST_VARIANT_FLAGS | |
| 71 ) | |
| 72 | |
| 73 ALL_VARIANTS = { | |
| 74 'nostrict': testsuite.ALL_VARIANT_FLAGS, | |
| 75 'strict': ALL_VARIANT_FLAGS_STRICT, | |
| 76 'both': ALL_VARIANT_FLAGS_BOTH, | |
| 77 } | |
| 78 | |
| 79 FAST_VARIANTS = { | |
| 80 'nostrict': testsuite.FAST_VARIANT_FLAGS, | |
| 81 'strict': FAST_VARIANT_FLAGS_STRICT, | |
| 82 'both': FAST_VARIANT_FLAGS_BOTH, | |
| 83 } | |
| 84 | |
| 85 class Test262VariantGenerator(testsuite.VariantGenerator): | |
| 86 def GetFlagSets(self, testcase, variant): | |
| 87 if testcase.outcomes and statusfile.OnlyFastVariants(testcase.outcomes): | |
| 88 variant_flags = FAST_VARIANTS | |
| 89 else: | |
| 90 variant_flags = ALL_VARIANTS | |
| 91 | |
| 92 test_record = self.suite.GetTestRecord(testcase) | |
| 93 if "noStrict" in test_record: | |
| 94 return variant_flags["nostrict"][variant] | |
| 95 if "onlyStrict" in test_record: | |
| 96 return variant_flags["strict"][variant] | |
| 97 return variant_flags["both"][variant] | |
| 98 | |
| 99 | |
| 100 class Test262TestSuite(testsuite.TestSuite): | |
| 101 | |
| 102 def __init__(self, name, root): | |
| 103 super(Test262TestSuite, self).__init__(name, root) | |
| 104 self.testroot = os.path.join(self.root, *TEST_262_SUITE_PATH) | |
| 105 self.harnesspath = os.path.join(self.root, *TEST_262_HARNESS_PATH) | |
| 106 self.harness = [os.path.join(self.harnesspath, f) | |
| 107 for f in TEST_262_HARNESS_FILES] | |
| 108 self.harness += [os.path.join(self.root, "harness-adapt.js")] | |
| 109 self.ParseTestRecord = None | |
| 110 | |
| 111 def ListTests(self, context): | |
| 112 tests = [] | |
| 113 for dirname, dirs, files in os.walk(self.testroot): | |
| 114 for dotted in [x for x in dirs if x.startswith(".")]: | |
| 115 dirs.remove(dotted) | |
| 116 if context.noi18n and "intl402" in dirs: | |
| 117 dirs.remove("intl402") | |
| 118 dirs.sort() | |
| 119 files.sort() | |
| 120 for filename in files: | |
| 121 if filename.endswith(".js"): | |
| 122 fullpath = os.path.join(dirname, filename) | |
| 123 relpath = fullpath[len(self.testroot) + 1 : -3] | |
| 124 testname = relpath.replace(os.path.sep, "/") | |
| 125 case = testcase.TestCase(self, testname) | |
| 126 tests.append(case) | |
| 127 return tests | |
| 128 | |
| 129 def GetFlagsForTestCase(self, testcase, context): | |
| 130 return (testcase.flags + context.mode_flags + self.harness + | |
| 131 self.GetIncludesForTest(testcase) + ["--harmony"] + | |
| 132 [os.path.join(self.testroot, testcase.path + ".js")]) | |
| 133 | |
| 134 def _VariantGeneratorFactory(self): | |
| 135 return Test262VariantGenerator | |
| 136 | |
| 137 def LoadParseTestRecord(self): | |
| 138 if not self.ParseTestRecord: | |
| 139 root = os.path.join(self.root, *TEST_262_TOOLS_PATH) | |
| 140 f = None | |
| 141 try: | |
| 142 (f, pathname, description) = imp.find_module("parseTestRecord", [root]) | |
| 143 module = imp.load_module("parseTestRecord", f, pathname, description) | |
| 144 self.ParseTestRecord = module.parseTestRecord | |
| 145 except: | |
| 146 raise ImportError("Cannot load parseTestRecord; you may need to " | |
| 147 "--download-data for test262") | |
| 148 finally: | |
| 149 if f: | |
| 150 f.close() | |
| 151 return self.ParseTestRecord | |
| 152 | |
| 153 def GetTestRecord(self, testcase): | |
| 154 if not hasattr(testcase, "test_record"): | |
| 155 ParseTestRecord = self.LoadParseTestRecord() | |
| 156 testcase.test_record = ParseTestRecord(self.GetSourceForTest(testcase), | |
| 157 testcase.path) | |
| 158 return testcase.test_record | |
| 159 | |
| 160 def GetIncludesForTest(self, testcase): | |
| 161 test_record = self.GetTestRecord(testcase) | |
| 162 if "includes" in test_record: | |
| 163 includes = [os.path.join(self.harnesspath, f) | |
| 164 for f in test_record["includes"]] | |
| 165 else: | |
| 166 includes = [] | |
| 167 return includes | |
| 168 | |
| 169 def GetSourceForTest(self, testcase): | |
| 170 filename = os.path.join(self.testroot, testcase.path + ".js") | |
| 171 with open(filename) as f: | |
| 172 return f.read() | |
| 173 | |
| 174 def IsNegativeTest(self, testcase): | |
| 175 test_record = self.GetTestRecord(testcase) | |
| 176 return "negative" in test_record | |
| 177 | |
| 178 def IsFailureOutput(self, output, testpath): | |
| 179 if output.exit_code != 0: | |
| 180 return True | |
| 181 return "FAILED!" in output.stdout | |
| 182 | |
| 183 def HasUnexpectedOutput(self, testcase): | |
| 184 outcome = self.GetOutcome(testcase) | |
| 185 if (statusfile.FAIL_SLOPPY in testcase.outcomes and | |
| 186 "--use-strict" not in testcase.flags): | |
| 187 return outcome != statusfile.FAIL | |
| 188 return not outcome in (testcase.outcomes or [statusfile.PASS]) | |
| 189 | |
| 190 def DownloadData(self): | |
| 191 revision = TEST_262_ARCHIVE_REVISION | |
| 192 archive_url = TEST_262_URL % revision | |
| 193 archive_name = os.path.join(self.root, "tc39-test262-%s.tar.gz" % revision) | |
| 194 directory_name = os.path.join(self.root, "data") | |
| 195 directory_old_name = os.path.join(self.root, "data.old") | |
| 196 | |
| 197 # Clobber if the test is in an outdated state, i.e. if there are any other | |
| 198 # archive files present. | |
| 199 archive_files = [f for f in os.listdir(self.root) | |
| 200 if f.startswith("tc39-test262-")] | |
| 201 if (len(archive_files) > 1 or | |
| 202 os.path.basename(archive_name) not in archive_files): | |
| 203 print "Clobber outdated test archives ..." | |
| 204 for f in archive_files: | |
| 205 os.remove(os.path.join(self.root, f)) | |
| 206 | |
| 207 if not os.path.exists(archive_name): | |
| 208 print "Downloading test data from %s ..." % archive_url | |
| 209 utils.URLRetrieve(archive_url, archive_name) | |
| 210 if os.path.exists(directory_name): | |
| 211 if os.path.exists(directory_old_name): | |
| 212 shutil.rmtree(directory_old_name) | |
| 213 os.rename(directory_name, directory_old_name) | |
| 214 if not os.path.exists(directory_name): | |
| 215 print "Extracting test262-%s.tar.gz ..." % revision | |
| 216 md5 = hashlib.md5() | |
| 217 with open(archive_name, "rb") as f: | |
| 218 for chunk in iter(lambda: f.read(8192), ""): | |
| 219 md5.update(chunk) | |
| 220 print "MD5 hash is %s" % md5.hexdigest() | |
| 221 if md5.hexdigest() != TEST_262_ARCHIVE_MD5: | |
| 222 os.remove(archive_name) | |
| 223 print "MD5 expected %s" % TEST_262_ARCHIVE_MD5 | |
| 224 raise Exception("MD5 hash mismatch of test data file") | |
| 225 archive = tarfile.open(archive_name, "r:gz") | |
| 226 if sys.platform in ("win32", "cygwin"): | |
| 227 # Magic incantation to allow longer path names on Windows. | |
| 228 archive.extractall(u"\\\\?\\%s" % self.root) | |
| 229 else: | |
| 230 archive.extractall(self.root) | |
| 231 os.rename(os.path.join(self.root, "tc39-test262-%s" % revision), | |
| 232 directory_name) | |
| 233 | |
| 234 | |
| 235 def GetSuite(name, root): | |
| 236 return Test262TestSuite(name, root) | |
| OLD | NEW |