blob: d8fe24d37aaebf5a9c146b6d21ab303b86febcaa [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
41 def __init__(self, path, file, mode, context, config):
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
46
47 def GetLabel(self):
48 return "%s %s" % (self.mode, self.GetName())
49
50 def GetName(self):
51 return self.path[-1]
52
53 def GetCommand(self):
Kristian Monsen80d68ea2010-09-08 11:05:35 +010054 result = self.config.context.GetVmCommand(self, self.mode)
Steve Blocka7e24c12009-10-30 11:49:00 +000055 source = open(self.file).read()
56 flags_match = FLAGS_PATTERN.search(source)
57 if flags_match:
58 result += flags_match.group(1).strip().split()
Steve Blocka7e24c12009-10-30 11:49:00 +000059 additional_files = []
60 files_match = FILES_PATTERN.search(source);
61 # Accept several lines of 'Files:'
62 while True:
63 if files_match:
64 additional_files += files_match.group(1).strip().split()
65 files_match = FILES_PATTERN.search(source, files_match.end())
66 else:
67 break
68 for a_file in additional_files:
69 result.append(join(dirname(self.config.root), '..', a_file))
70 framework = join(dirname(self.config.root), 'mjsunit', 'mjsunit.js')
71 if SELF_SCRIPT_PATTERN.search(source):
72 result.append(self.CreateSelfScript())
73 result += [framework, self.file]
74 return result
75
76 def GetSource(self):
77 return open(self.file).read()
78
79 def CreateSelfScript(self):
80 (fd_self_script, self_script) = tempfile.mkstemp(suffix=".js")
81 def MakeJsConst(name, value):
82 return "var %(name)s=\'%(value)s\';\n" % \
83 {'name': name, \
84 'value': value.replace('\\', '\\\\').replace('\'', '\\\'') }
85 try:
86 os.write(fd_self_script, MakeJsConst('TEST_FILE_NAME', self.file))
87 except IOError, e:
88 test.PrintError("write() " + str(e))
89 os.close(fd_self_script)
90 self.self_script = self_script
91 return self_script
92
Kristian Monsen80d68ea2010-09-08 11:05:35 +010093 def AfterRun(self, result):
94 if self.self_script and (not result.HasPreciousOutput()):
Steve Blocka7e24c12009-10-30 11:49:00 +000095 test.CheckedUnlink(self.self_script)
96
97class MjsunitTestConfiguration(test.TestConfiguration):
98
99 def __init__(self, context, root):
100 super(MjsunitTestConfiguration, self).__init__(context, root)
101
102 def Ls(self, path):
103 def SelectTest(name):
104 return name.endswith('.js') and name != 'mjsunit.js'
105 return [f[:-3] for f in os.listdir(path) if SelectTest(f)]
106
107 def ListTests(self, current_path, path, mode):
108 mjsunit = [current_path + [t] for t in self.Ls(self.root)]
109 regress = [current_path + ['regress', t] for t in self.Ls(join(self.root, 'regress'))]
110 bugs = [current_path + ['bugs', t] for t in self.Ls(join(self.root, 'bugs'))]
111 third_party = [current_path + ['third_party', t] for t in self.Ls(join(self.root, 'third_party'))]
112 tools = [current_path + ['tools', t] for t in self.Ls(join(self.root, 'tools'))]
Steve Block3ce2e202009-11-05 08:53:23 +0000113 compiler = [current_path + ['compiler', t] for t in self.Ls(join(self.root, 'compiler'))]
114 all_tests = mjsunit + regress + bugs + third_party + tools + compiler
Steve Blocka7e24c12009-10-30 11:49:00 +0000115 result = []
116 for test in all_tests:
117 if self.Contains(path, test):
118 file_path = join(self.root, reduce(join, test[1:], "") + ".js")
119 result.append(MjsunitTestCase(test, file_path, mode, self.context, self))
120 return result
121
122 def GetBuildRequirements(self):
123 return ['sample', 'sample=shell']
124
125 def GetTestStatus(self, sections, defs):
126 status_file = join(self.root, 'mjsunit.status')
127 if exists(status_file):
128 test.ReadConfigurationInto(status_file, sections, defs)
129
130
131
132def GetConfiguration(context, root):
133 return MjsunitTestConfiguration(context, root)