blob: f7b6d4da3e45b93cb9db21e5fca02691d3316cd7 [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
28import test
29import os
30from os.path import join, dirname, exists
31import re
32import tempfile
33
Steve Blocka7e24c12009-10-30 11:49:00 +000034FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)")
35FILES_PATTERN = re.compile(r"//\s+Files:(.*)")
36SELF_SCRIPT_PATTERN = re.compile(r"//\s+Env: TEST_FILE_NAME")
37
38
39class MjsunitTestCase(test.TestCase):
40
Steve Block44f0eee2011-05-26 01:26:41 +010041 def __init__(self, path, file, mode, context, config, isolates):
Kristian Monsen80d68ea2010-09-08 11:05:35 +010042 super(MjsunitTestCase, self).__init__(context, path, mode)
Steve Blocka7e24c12009-10-30 11:49:00 +000043 self.file = file
44 self.config = config
Steve Blocka7e24c12009-10-30 11:49:00 +000045 self.self_script = False
Steve Block44f0eee2011-05-26 01:26:41 +010046 self.isolates = isolates
Steve Blocka7e24c12009-10-30 11:49:00 +000047
48 def GetLabel(self):
49 return "%s %s" % (self.mode, self.GetName())
50
51 def GetName(self):
Steve Block44f0eee2011-05-26 01:26:41 +010052 return self.path[-1] + ["", "-isolates"][self.isolates]
Steve Blocka7e24c12009-10-30 11:49:00 +000053
Steve Block44f0eee2011-05-26 01:26:41 +010054 def TestsIsolates(self):
55 return self.isolates
56
57 def GetVmCommand(self, source):
Kristian Monsen80d68ea2010-09-08 11:05:35 +010058 result = self.config.context.GetVmCommand(self, self.mode)
Steve Blocka7e24c12009-10-30 11:49:00 +000059 flags_match = FLAGS_PATTERN.search(source)
60 if flags_match:
61 result += flags_match.group(1).strip().split()
Steve Block44f0eee2011-05-26 01:26:41 +010062 return result
63
64 def GetVmArguments(self, source):
65 result = []
Steve Blocka7e24c12009-10-30 11:49:00 +000066 additional_files = []
67 files_match = FILES_PATTERN.search(source);
68 # Accept several lines of 'Files:'
69 while True:
70 if files_match:
71 additional_files += files_match.group(1).strip().split()
72 files_match = FILES_PATTERN.search(source, files_match.end())
73 else:
74 break
75 for a_file in additional_files:
76 result.append(join(dirname(self.config.root), '..', a_file))
77 framework = join(dirname(self.config.root), 'mjsunit', 'mjsunit.js')
78 if SELF_SCRIPT_PATTERN.search(source):
79 result.append(self.CreateSelfScript())
80 result += [framework, self.file]
81 return result
82
Steve Block44f0eee2011-05-26 01:26:41 +010083 def GetCommand(self):
84 source = open(self.file).read()
85 result = self.GetVmCommand(source)
86 result += self.GetVmArguments(source)
87 if self.isolates:
88 result.append("--isolate")
89 result += self.GetVmArguments(source)
90 return result
91
Steve Blocka7e24c12009-10-30 11:49:00 +000092 def GetSource(self):
93 return open(self.file).read()
94
95 def CreateSelfScript(self):
96 (fd_self_script, self_script) = tempfile.mkstemp(suffix=".js")
97 def MakeJsConst(name, value):
98 return "var %(name)s=\'%(value)s\';\n" % \
99 {'name': name, \
100 'value': value.replace('\\', '\\\\').replace('\'', '\\\'') }
101 try:
102 os.write(fd_self_script, MakeJsConst('TEST_FILE_NAME', self.file))
103 except IOError, e:
104 test.PrintError("write() " + str(e))
105 os.close(fd_self_script)
106 self.self_script = self_script
107 return self_script
108
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100109 def AfterRun(self, result):
Ben Murdoch8b112d22011-06-08 16:22:53 +0100110 if self.self_script and (not result or (not result.HasPreciousOutput())):
Steve Blocka7e24c12009-10-30 11:49:00 +0000111 test.CheckedUnlink(self.self_script)
112
113class MjsunitTestConfiguration(test.TestConfiguration):
114
115 def __init__(self, context, root):
116 super(MjsunitTestConfiguration, self).__init__(context, root)
117
118 def Ls(self, path):
119 def SelectTest(name):
120 return name.endswith('.js') and name != 'mjsunit.js'
121 return [f[:-3] for f in os.listdir(path) if SelectTest(f)]
122
Steve Block44f0eee2011-05-26 01:26:41 +0100123 def ListTests(self, current_path, path, mode, variant_flags):
Steve Blocka7e24c12009-10-30 11:49:00 +0000124 mjsunit = [current_path + [t] for t in self.Ls(self.root)]
125 regress = [current_path + ['regress', t] for t in self.Ls(join(self.root, 'regress'))]
126 bugs = [current_path + ['bugs', t] for t in self.Ls(join(self.root, 'bugs'))]
127 third_party = [current_path + ['third_party', t] for t in self.Ls(join(self.root, 'third_party'))]
128 tools = [current_path + ['tools', t] for t in self.Ls(join(self.root, 'tools'))]
Steve Block3ce2e202009-11-05 08:53:23 +0000129 compiler = [current_path + ['compiler', t] for t in self.Ls(join(self.root, 'compiler'))]
Ben Murdochb8e0da22011-05-16 14:20:40 +0100130 mjsunit.sort()
131 regress.sort()
132 bugs.sort()
133 third_party.sort()
134 tools.sort()
135 compiler.sort()
Steve Block3ce2e202009-11-05 08:53:23 +0000136 all_tests = mjsunit + regress + bugs + third_party + tools + compiler
Steve Blocka7e24c12009-10-30 11:49:00 +0000137 result = []
138 for test in all_tests:
139 if self.Contains(path, test):
140 file_path = join(self.root, reduce(join, test[1:], "") + ".js")
Steve Block44f0eee2011-05-26 01:26:41 +0100141 result.append(MjsunitTestCase(test, file_path, mode, self.context, self, False))
142 result.append(MjsunitTestCase(test, file_path, mode, self.context, self, True))
Steve Blocka7e24c12009-10-30 11:49:00 +0000143 return result
144
145 def GetBuildRequirements(self):
146 return ['sample', 'sample=shell']
147
148 def GetTestStatus(self, sections, defs):
149 status_file = join(self.root, 'mjsunit.status')
150 if exists(status_file):
151 test.ReadConfigurationInto(status_file, sections, defs)
152
153
154
155def GetConfiguration(context, root):
156 return MjsunitTestConfiguration(context, root)