blob: 70a7ac663cde287e87f73808dd1fed2d96f41139 [file] [log] [blame]
Steve Blocka7e24c12009-10-30 11:49:00 +00001# Copyright 2008 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
Steve Blocka7e24c12009-10-30 11:49:00 +000029import os
Ben Murdochb8a8cc12014-11-26 15:28:44 +000030import shutil
31import subprocess
32import tarfile
33
34from testrunner.local import testsuite
35from testrunner.objects import testcase
Steve Blocka7e24c12009-10-30 11:49:00 +000036
37
Ben Murdochb8a8cc12014-11-26 15:28:44 +000038MOZILLA_VERSION = "2010-06-29"
39
40
41EXCLUDED = ["CVS"]
Steve Blocka7e24c12009-10-30 11:49:00 +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
Ben Murdochb8a8cc12014-11-26 15:28:44 +000064class MozillaTestSuite(testsuite.TestSuite):
Steve Blocka7e24c12009-10-30 11:49:00 +000065
Ben Murdochb8a8cc12014-11-26 15:28:44 +000066 def __init__(self, name, root):
67 super(MozillaTestSuite, self).__init__(name, root)
68 self.testroot = os.path.join(root, "data")
Steve Blocka7e24c12009-10-30 11:49:00 +000069
Ben Murdochb8a8cc12014-11-26 15:28:44 +000070 def ListTests(self, context):
Steve Blocka7e24c12009-10-30 11:49:00 +000071 tests = []
Ben Murdochb8a8cc12014-11-26 15:28:44 +000072 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(".")]:
Steve Blocka7e24c12009-10-30 11:49:00 +000076 dirs.remove(dotted)
77 for excluded in EXCLUDED:
78 if excluded in dirs:
79 dirs.remove(excluded)
Steve Blockd0582a62009-12-15 09:54:21 +000080 dirs.sort()
Steve Blockd0582a62009-12-15 09:54:21 +000081 files.sort()
Ben Murdochb8a8cc12014-11-26 15:28:44 +000082 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)
Steve Blocka7e24c12009-10-30 11:49:00 +000088 return tests
89
Ben Murdochb8a8cc12014-11-26 15:28:44 +000090 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
Steve Blocka7e24c12009-10-30 11:49:00 +0000105
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000106 def GetSourceForTest(self, testcase):
107 filename = os.path.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 directory_name_old = "data.old"
136 if os.path.exists(directory_name):
137 if os.path.exists(directory_name_old):
138 shutil.rmtree(directory_name_old)
139 os.rename(directory_name, directory_name_old)
140 archive_file = "downloaded_%s.tar.gz" % MOZILLA_VERSION
141 if os.path.exists(archive_file):
142 with tarfile.open(archive_file, "r:gz") as tar:
143 tar.extractall()
144 with open(versionfile, "w") as f:
145 f.write(MOZILLA_VERSION)
146 os.chdir(old_cwd)
147 return
148
149 # No cached copy. Check out via CVS, and pack as .tar.gz for later use.
150 command = ("cvs -d :pserver:anonymous@cvs-mirror.mozilla.org:/cvsroot"
151 " co -D %s mozilla/js/tests" % MOZILLA_VERSION)
152 code = subprocess.call(command, shell=True)
153 if code != 0:
154 os.chdir(old_cwd)
155 raise Exception("Error checking out Mozilla test suite!")
156 os.rename(os.path.join("mozilla", "js", "tests"), directory_name)
157 shutil.rmtree("mozilla")
158 with tarfile.open(archive_file, "w:gz") as tar:
159 tar.add("data")
160 with open(versionfile, "w") as f:
161 f.write(MOZILLA_VERSION)
162 os.chdir(old_cwd)
Steve Blocka7e24c12009-10-30 11:49:00 +0000163
164
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000165def GetSuite(name, root):
166 return MozillaTestSuite(name, root)