blob: 5aeac4cc67699c8dc73bc0e816fc2e3641d9b6d5 [file] [log] [blame]
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001# Copyright 2008 the V8 project authors. All rights reserved.
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00002# 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
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000029import os
verwaest@chromium.org33e09c82012-10-10 17:07:22 +000030import shutil
31import subprocess
32import tarfile
33
34from testrunner.local import testsuite
35from testrunner.objects import testcase
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000036
37
verwaest@chromium.org33e09c82012-10-10 17:07:22 +000038MOZILLA_VERSION = "2010-06-29"
39
40
41EXCLUDED = ["CVS"]
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000042
43
44FRAMEWORK = """
45 browser.js
46 shell.js
47 jsref.js
48 template.js
49""".split()
50
51
52TEST_DIRS = """
53 ecma
54 ecma_2
55 ecma_3
56 js1_1
57 js1_2
58 js1_3
59 js1_4
60 js1_5
61""".split()
62
63
verwaest@chromium.org33e09c82012-10-10 17:07:22 +000064class MozillaTestSuite(testsuite.TestSuite):
65
66 def __init__(self, name, root):
67 super(MozillaTestSuite, self).__init__(name, root)
68 self.testroot = os.path.join(root, "data")
69
70 def ListTests(self, context):
71 tests = []
72 for testdir in TEST_DIRS:
73 current_root = os.path.join(self.testroot, testdir)
74 for dirname, dirs, files in os.walk(current_root):
75 for dotted in [x for x in dirs if x.startswith(".")]:
76 dirs.remove(dotted)
77 for excluded in EXCLUDED:
78 if excluded in dirs:
79 dirs.remove(excluded)
80 dirs.sort()
81 files.sort()
82 for filename in files:
83 if filename.endswith(".js") and not filename in FRAMEWORK:
84 testname = os.path.join(dirname[len(self.testroot) + 1:],
85 filename[:-3])
86 case = testcase.TestCase(self, testname)
87 tests.append(case)
88 return tests
89
90 def GetFlagsForTestCase(self, testcase, context):
91 result = []
92 result += context.mode_flags
93 result += ["--expose-gc"]
94 result += [os.path.join(self.root, "mozilla-shell-emulation.js")]
95 testfilename = testcase.path + ".js"
96 testfilepath = testfilename.split(os.path.sep)
97 for i in xrange(len(testfilepath)):
98 script = os.path.join(self.testroot,
99 reduce(os.path.join, testfilepath[:i], ""),
100 "shell.js")
101 if os.path.exists(script):
102 result.append(script)
103 result.append(os.path.join(self.testroot, testfilename))
104 return testcase.flags + result
105
106 def GetSourceForTest(self, testcase):
107 filename = join(self.testroot, testcase.path + ".js")
108 with open(filename) as f:
109 return f.read()
110
111 def IsNegativeTest(self, testcase):
112 return testcase.path.endswith("-n")
113
114 def IsFailureOutput(self, output, testpath):
115 if output.exit_code != 0:
116 return True
117 return "FAILED!" in output.stdout
118
119 def DownloadData(self):
120 old_cwd = os.getcwd()
121 os.chdir(os.path.abspath(self.root))
122
123 # Maybe we're still up to date?
124 versionfile = "CHECKED_OUT_VERSION"
125 checked_out_version = None
126 if os.path.exists(versionfile):
127 with open(versionfile) as f:
128 checked_out_version = f.read()
129 if checked_out_version == MOZILLA_VERSION:
130 os.chdir(old_cwd)
131 return
132
133 # If we have a local archive file with the test data, extract it.
134 directory_name = "data"
135 if os.path.exists(directory_name):
136 os.rename(directory_name, "data.old")
137 archive_file = "downloaded_%s.tar.gz" % MOZILLA_VERSION
138 if os.path.exists(archive_file):
139 with tarfile.open(archive_file, "r:gz") as tar:
140 tar.extractall()
141 with open(versionfile, "w") as f:
142 f.write(MOZILLA_VERSION)
143 os.chdir(old_cwd)
144 return
145
146 # No cached copy. Check out via CVS, and pack as .tar.gz for later use.
147 command = ("cvs -d :pserver:anonymous@cvs-mirror.mozilla.org:/cvsroot"
148 " co -D %s mozilla/js/tests" % MOZILLA_VERSION)
149 code = subprocess.call(command, shell=True)
150 if code != 0:
151 os.chdir(old_cwd)
152 raise Exception("Error checking out Mozilla test suite!")
153 os.rename(join("mozilla", "js", "tests"), directory_name)
154 shutil.rmtree("mozilla")
155 with tarfile.open(archive_file, "w:gz") as tar:
156 tar.add("data")
157 with open(versionfile, "w") as f:
158 f.write(MOZILLA_VERSION)
159 os.chdir(old_cwd)
160
161
162def GetSuite(name, root):
163 return MozillaTestSuite(name, root)
164
165
166# Deprecated definitions below.
167# TODO(jkummerow): Remove when SCons is no longer supported.
168
169
170from os.path import exists
171from os.path import join
172import test
173
174
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000175class MozillaTestCase(test.TestCase):
176
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000177 def __init__(self, filename, path, context, root, mode, framework):
ricow@chromium.org65fae842010-08-25 15:26:24 +0000178 super(MozillaTestCase, self).__init__(context, path, mode)
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000179 self.filename = filename
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000180 self.framework = framework
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000181 self.root = root
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000182
183 def IsNegative(self):
184 return self.filename.endswith('-n.js')
185
186 def GetLabel(self):
187 return "%s mozilla %s" % (self.mode, self.GetName())
188
189 def IsFailureOutput(self, output):
190 if output.exit_code != 0:
191 return True
192 return 'FAILED!' in output.stdout
193
194 def GetCommand(self):
ricow@chromium.org65fae842010-08-25 15:26:24 +0000195 result = self.context.GetVmCommand(self, self.mode) + \
196 [ '--expose-gc', join(self.root, 'mozilla-shell-emulation.js') ]
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000197 result += [ '--es5_readonly' ] # Temporary hack until we can remove flag
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000198 result += self.framework
199 result.append(self.filename)
200 return result
201
202 def GetName(self):
203 return self.path[-1]
204
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000205 def GetSource(self):
206 return open(self.filename).read()
207
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000208
209class MozillaTestConfiguration(test.TestConfiguration):
210
211 def __init__(self, context, root):
212 super(MozillaTestConfiguration, self).__init__(context, root)
213
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000214 def ListTests(self, current_path, path, mode, variant_flags):
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000215 tests = []
216 for test_dir in TEST_DIRS:
217 current_root = join(self.root, 'data', test_dir)
218 for root, dirs, files in os.walk(current_root):
219 for dotted in [x for x in dirs if x.startswith('.')]:
220 dirs.remove(dotted)
221 for excluded in EXCLUDED:
222 if excluded in dirs:
223 dirs.remove(excluded)
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000224 dirs.sort()
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000225 root_path = root[len(self.root):].split(os.path.sep)
226 root_path = current_path + [x for x in root_path if x]
227 framework = []
228 for i in xrange(len(root_path)):
229 if i == 0: dir = root_path[1:]
230 else: dir = root_path[1:-i]
231 script = join(self.root, reduce(join, dir, ''), 'shell.js')
232 if exists(script):
233 framework.append(script)
234 framework.reverse()
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000235 files.sort()
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000236 for file in files:
237 if (not file in FRAMEWORK) and file.endswith('.js'):
238 full_path = root_path + [file[:-3]]
239 full_path = [x for x in full_path if x != 'data']
240 if self.Contains(path, full_path):
241 test = MozillaTestCase(join(root, file), full_path, self.context,
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000242 self.root, mode, framework)
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000243 tests.append(test)
244 return tests
245
246 def GetBuildRequirements(self):
ricow@chromium.org2c99e282011-07-28 09:15:17 +0000247 return ['d8']
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000248
249 def GetTestStatus(self, sections, defs):
250 status_file = join(self.root, 'mozilla.status')
251 if exists(status_file):
252 test.ReadConfigurationInto(status_file, sections, defs)
253
254
255def GetConfiguration(context, root):
256 return MozillaTestConfiguration(context, root)