blob: b5ad30949d8c3ae337128bfb17f47180fc34a8d0 [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001# Copyright 2012 the V8 project authors. All rights reserved.
Steve Block44f0eee2011-05-26 01:26:41 +01002# 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 Murdoch3ef787d2012-04-12 10:51:47 +010029import hashlib
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000030import imp
Ben Murdochb8a8cc12014-11-26 15:28:44 +000031import os
32import shutil
33import sys
Ben Murdoch3ef787d2012-04-12 10:51:47 +010034import tarfile
Steve Block44f0eee2011-05-26 01:26:41 +010035
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000036
37from testrunner.local import statusfile
Ben Murdochb8a8cc12014-11-26 15:28:44 +000038from testrunner.local import testsuite
39from testrunner.local import utils
40from testrunner.objects import testcase
Steve Block44f0eee2011-05-26 01:26:41 +010041
Ben Murdoch097c5b22016-05-18 11:27:45 +010042ARCHIVE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "data.tar")
43
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000044TEST_262_HARNESS_FILES = ["sta.js", "assert.js"]
Steve Block44f0eee2011-05-26 01:26:41 +010045
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000046TEST_262_SUITE_PATH = ["data", "test"]
47TEST_262_HARNESS_PATH = ["data", "harness"]
48TEST_262_TOOLS_PATH = ["data", "tools", "packaging"]
49
50ALL_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
55FAST_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
60ALL_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
66FAST_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
72ALL_VARIANTS = {
73 'nostrict': testsuite.ALL_VARIANT_FLAGS,
74 'strict': ALL_VARIANT_FLAGS_STRICT,
75 'both': ALL_VARIANT_FLAGS_BOTH,
76}
77
78FAST_VARIANTS = {
79 'nostrict': testsuite.FAST_VARIANT_FLAGS,
80 'strict': FAST_VARIANT_FLAGS_STRICT,
81 'both': FAST_VARIANT_FLAGS_BOTH,
82}
83
84class 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 Block44f0eee2011-05-26 01:26:41 +010097
Steve Block44f0eee2011-05-26 01:26:41 +010098
Ben Murdochb8a8cc12014-11-26 15:28:44 +000099class Test262TestSuite(testsuite.TestSuite):
Steve Block44f0eee2011-05-26 01:26:41 +0100100
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000101 def __init__(self, name, root):
102 super(Test262TestSuite, self).__init__(name, root)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000103 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 Murdochb8a8cc12014-11-26 15:28:44 +0000107 self.harness += [os.path.join(self.root, "harness-adapt.js")]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000108 self.ParseTestRecord = None
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000109
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 Murdoch4a90d5f2016-03-22 12:00:34 +0000121 fullpath = os.path.join(dirname, filename)
122 relpath = fullpath[len(self.testroot) + 1 : -3]
123 testname = relpath.replace(os.path.sep, "/")
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000124 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 Murdoch4a90d5f2016-03-22 12:00:34 +0000130 self.GetIncludesForTest(testcase) + ["--harmony"] +
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000131 [os.path.join(self.testroot, testcase.path + ".js")])
132
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000133 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 Murdochb8a8cc12014-11-26 15:28:44 +0000168 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 Murdoch4a90d5f2016-03-22 12:00:34 +0000174 test_record = self.GetTestRecord(testcase)
175 return "negative" in test_record
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000176
177 def IsFailureOutput(self, output, testpath):
Steve Block44f0eee2011-05-26 01:26:41 +0100178 if output.exit_code != 0:
179 return True
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000180 return "FAILED!" in output.stdout
Ben Murdoch5d4cdbf2012-04-11 10:23:59 +0100181
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000182 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 Murdoch3ef787d2012-04-12 10:51:47 +0100189 def DownloadData(self):
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000190 print "Test262 download is deprecated. It's part of DEPS."
191
192 # Clean up old directories and archive files.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000193 directory_old_name = os.path.join(self.root, "data.old")
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000194 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 Block44f0eee2011-05-26 01:26:41 +0100203
Ben Murdoch097c5b22016-05-18 11:27:45 +0100204 print "Extracting archive..."
205 tar = tarfile.open(ARCHIVE)
206 tar.extractall(path=os.path.dirname(ARCHIVE))
207 tar.close()
208
Steve Block44f0eee2011-05-26 01:26:41 +0100209
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000210def GetSuite(name, root):
211 return Test262TestSuite(name, root)