Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1 | # Copyright 2012 the V8 project authors. All rights reserved. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 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 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 29 | import hashlib |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 30 | import imp |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 31 | import os |
| 32 | import shutil |
| 33 | import sys |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 34 | import tarfile |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 35 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 36 | |
| 37 | from testrunner.local import statusfile |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 38 | from testrunner.local import testsuite |
| 39 | from testrunner.local import utils |
| 40 | from testrunner.objects import testcase |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 41 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 42 | ARCHIVE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "data.tar") |
| 43 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 44 | TEST_262_HARNESS_FILES = ["sta.js", "assert.js"] |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 45 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 46 | TEST_262_SUITE_PATH = ["data", "test"] |
| 47 | TEST_262_HARNESS_PATH = ["data", "harness"] |
| 48 | TEST_262_TOOLS_PATH = ["data", "tools", "packaging"] |
| 49 | |
| 50 | ALL_VARIANT_FLAGS_STRICT = dict( |
| 51 | (v, [flags + ["--use-strict"] for flags in flag_sets]) |
| 52 | for v, flag_sets in testsuite.ALL_VARIANT_FLAGS.iteritems() |
| 53 | ) |
| 54 | |
| 55 | FAST_VARIANT_FLAGS_STRICT = dict( |
| 56 | (v, [flags + ["--use-strict"] for flags in flag_sets]) |
| 57 | for v, flag_sets in testsuite.FAST_VARIANT_FLAGS.iteritems() |
| 58 | ) |
| 59 | |
| 60 | ALL_VARIANT_FLAGS_BOTH = dict( |
| 61 | (v, [flags for flags in testsuite.ALL_VARIANT_FLAGS[v] + |
| 62 | ALL_VARIANT_FLAGS_STRICT[v]]) |
| 63 | for v in testsuite.ALL_VARIANT_FLAGS |
| 64 | ) |
| 65 | |
| 66 | FAST_VARIANT_FLAGS_BOTH = dict( |
| 67 | (v, [flags for flags in testsuite.FAST_VARIANT_FLAGS[v] + |
| 68 | FAST_VARIANT_FLAGS_STRICT[v]]) |
| 69 | for v in testsuite.FAST_VARIANT_FLAGS |
| 70 | ) |
| 71 | |
| 72 | ALL_VARIANTS = { |
| 73 | 'nostrict': testsuite.ALL_VARIANT_FLAGS, |
| 74 | 'strict': ALL_VARIANT_FLAGS_STRICT, |
| 75 | 'both': ALL_VARIANT_FLAGS_BOTH, |
| 76 | } |
| 77 | |
| 78 | FAST_VARIANTS = { |
| 79 | 'nostrict': testsuite.FAST_VARIANT_FLAGS, |
| 80 | 'strict': FAST_VARIANT_FLAGS_STRICT, |
| 81 | 'both': FAST_VARIANT_FLAGS_BOTH, |
| 82 | } |
| 83 | |
| 84 | class Test262VariantGenerator(testsuite.VariantGenerator): |
| 85 | def GetFlagSets(self, testcase, variant): |
| 86 | if testcase.outcomes and statusfile.OnlyFastVariants(testcase.outcomes): |
| 87 | variant_flags = FAST_VARIANTS |
| 88 | else: |
| 89 | variant_flags = ALL_VARIANTS |
| 90 | |
| 91 | test_record = self.suite.GetTestRecord(testcase) |
| 92 | if "noStrict" in test_record: |
| 93 | return variant_flags["nostrict"][variant] |
| 94 | if "onlyStrict" in test_record: |
| 95 | return variant_flags["strict"][variant] |
| 96 | return variant_flags["both"][variant] |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 97 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 98 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 99 | class Test262TestSuite(testsuite.TestSuite): |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 100 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 101 | def __init__(self, name, root): |
| 102 | super(Test262TestSuite, self).__init__(name, root) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 103 | self.testroot = os.path.join(self.root, *TEST_262_SUITE_PATH) |
| 104 | self.harnesspath = os.path.join(self.root, *TEST_262_HARNESS_PATH) |
| 105 | self.harness = [os.path.join(self.harnesspath, f) |
| 106 | for f in TEST_262_HARNESS_FILES] |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 107 | self.harness += [os.path.join(self.root, "harness-adapt.js")] |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 108 | self.ParseTestRecord = None |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 109 | |
| 110 | def ListTests(self, context): |
| 111 | tests = [] |
| 112 | for dirname, dirs, files in os.walk(self.testroot): |
| 113 | for dotted in [x for x in dirs if x.startswith(".")]: |
| 114 | dirs.remove(dotted) |
| 115 | if context.noi18n and "intl402" in dirs: |
| 116 | dirs.remove("intl402") |
| 117 | dirs.sort() |
| 118 | files.sort() |
| 119 | for filename in files: |
| 120 | if filename.endswith(".js"): |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 121 | fullpath = os.path.join(dirname, filename) |
| 122 | relpath = fullpath[len(self.testroot) + 1 : -3] |
| 123 | testname = relpath.replace(os.path.sep, "/") |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 124 | case = testcase.TestCase(self, testname) |
| 125 | tests.append(case) |
| 126 | return tests |
| 127 | |
| 128 | def GetFlagsForTestCase(self, testcase, context): |
| 129 | return (testcase.flags + context.mode_flags + self.harness + |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 130 | self.GetIncludesForTest(testcase) + ["--harmony"] + |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 131 | [os.path.join(self.testroot, testcase.path + ".js")]) |
| 132 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 133 | def _VariantGeneratorFactory(self): |
| 134 | return Test262VariantGenerator |
| 135 | |
| 136 | def LoadParseTestRecord(self): |
| 137 | if not self.ParseTestRecord: |
| 138 | root = os.path.join(self.root, *TEST_262_TOOLS_PATH) |
| 139 | f = None |
| 140 | try: |
| 141 | (f, pathname, description) = imp.find_module("parseTestRecord", [root]) |
| 142 | module = imp.load_module("parseTestRecord", f, pathname, description) |
| 143 | self.ParseTestRecord = module.parseTestRecord |
| 144 | except: |
| 145 | raise ImportError("Cannot load parseTestRecord; you may need to " |
| 146 | "--download-data for test262") |
| 147 | finally: |
| 148 | if f: |
| 149 | f.close() |
| 150 | return self.ParseTestRecord |
| 151 | |
| 152 | def GetTestRecord(self, testcase): |
| 153 | if not hasattr(testcase, "test_record"): |
| 154 | ParseTestRecord = self.LoadParseTestRecord() |
| 155 | testcase.test_record = ParseTestRecord(self.GetSourceForTest(testcase), |
| 156 | testcase.path) |
| 157 | return testcase.test_record |
| 158 | |
| 159 | def GetIncludesForTest(self, testcase): |
| 160 | test_record = self.GetTestRecord(testcase) |
| 161 | if "includes" in test_record: |
| 162 | includes = [os.path.join(self.harnesspath, f) |
| 163 | for f in test_record["includes"]] |
| 164 | else: |
| 165 | includes = [] |
| 166 | return includes |
| 167 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 168 | def GetSourceForTest(self, testcase): |
| 169 | filename = os.path.join(self.testroot, testcase.path + ".js") |
| 170 | with open(filename) as f: |
| 171 | return f.read() |
| 172 | |
| 173 | def IsNegativeTest(self, testcase): |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 174 | test_record = self.GetTestRecord(testcase) |
| 175 | return "negative" in test_record |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 176 | |
| 177 | def IsFailureOutput(self, output, testpath): |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 178 | if output.exit_code != 0: |
| 179 | return True |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 180 | return "FAILED!" in output.stdout |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame] | 181 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 182 | def HasUnexpectedOutput(self, testcase): |
| 183 | outcome = self.GetOutcome(testcase) |
| 184 | if (statusfile.FAIL_SLOPPY in testcase.outcomes and |
| 185 | "--use-strict" not in testcase.flags): |
| 186 | return outcome != statusfile.FAIL |
| 187 | return not outcome in (testcase.outcomes or [statusfile.PASS]) |
| 188 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 189 | def DownloadData(self): |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 190 | print "Test262 download is deprecated. It's part of DEPS." |
| 191 | |
| 192 | # Clean up old directories and archive files. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 193 | directory_old_name = os.path.join(self.root, "data.old") |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 194 | if os.path.exists(directory_old_name): |
| 195 | shutil.rmtree(directory_old_name) |
| 196 | |
| 197 | archive_files = [f for f in os.listdir(self.root) |
| 198 | if f.startswith("tc39-test262-")] |
| 199 | if len(archive_files) > 0: |
| 200 | print "Clobber outdated test archives ..." |
| 201 | for f in archive_files: |
| 202 | os.remove(os.path.join(self.root, f)) |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 203 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 204 | print "Extracting archive..." |
| 205 | tar = tarfile.open(ARCHIVE) |
| 206 | tar.extractall(path=os.path.dirname(ARCHIVE)) |
| 207 | tar.close() |
| 208 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 209 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 210 | def GetSuite(name, root): |
| 211 | return Test262TestSuite(name, root) |