1a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block# Copyright 2008 the V8 project authors. All rights reserved. 2a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block# Redistribution and use in source and binary forms, with or without 3a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block# modification, are permitted provided that the following conditions are 4a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block# met: 5a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block# 6a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block# * Redistributions of source code must retain the above copyright 7a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block# notice, this list of conditions and the following disclaimer. 8a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block# * Redistributions in binary form must reproduce the above 9a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block# copyright notice, this list of conditions and the following 10a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block# disclaimer in the documentation and/or other materials provided 11a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block# with the distribution. 12a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block# * Neither the name of Google Inc. nor the names of its 13a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block# contributors may be used to endorse or promote products derived 14a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block# from this software without specific prior written permission. 15a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block# 16a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 28a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockimport test 29a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockimport os 30a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockfrom os.path import join, dirname, exists 31a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockimport re 32a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockimport tempfile 33a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 34a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockFLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)") 35a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockFILES_PATTERN = re.compile(r"//\s+Files:(.*)") 36a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockSELF_SCRIPT_PATTERN = re.compile(r"//\s+Env: TEST_FILE_NAME") 37a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 38a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 39a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass MjsunitTestCase(test.TestCase): 40a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 4144f0eee88ff00398ff7f715fab053374d808c90dSteve Block def __init__(self, path, file, mode, context, config, isolates): 4280d68eab642096c1a48b6474d6ec33064b0ad1f5Kristian Monsen super(MjsunitTestCase, self).__init__(context, path, mode) 43a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block self.file = file 44a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block self.config = config 45a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block self.self_script = False 4644f0eee88ff00398ff7f715fab053374d808c90dSteve Block self.isolates = isolates 47a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 48a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block def GetLabel(self): 49a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return "%s %s" % (self.mode, self.GetName()) 50a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 51a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block def GetName(self): 5244f0eee88ff00398ff7f715fab053374d808c90dSteve Block return self.path[-1] + ["", "-isolates"][self.isolates] 53a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 5444f0eee88ff00398ff7f715fab053374d808c90dSteve Block def TestsIsolates(self): 5544f0eee88ff00398ff7f715fab053374d808c90dSteve Block return self.isolates 5644f0eee88ff00398ff7f715fab053374d808c90dSteve Block 5744f0eee88ff00398ff7f715fab053374d808c90dSteve Block def GetVmCommand(self, source): 5880d68eab642096c1a48b6474d6ec33064b0ad1f5Kristian Monsen result = self.config.context.GetVmCommand(self, self.mode) 59a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block flags_match = FLAGS_PATTERN.search(source) 60a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block if flags_match: 61a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block result += flags_match.group(1).strip().split() 6244f0eee88ff00398ff7f715fab053374d808c90dSteve Block return result 6344f0eee88ff00398ff7f715fab053374d808c90dSteve Block 6444f0eee88ff00398ff7f715fab053374d808c90dSteve Block def GetVmArguments(self, source): 6544f0eee88ff00398ff7f715fab053374d808c90dSteve Block result = [] 66a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block additional_files = [] 67a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block files_match = FILES_PATTERN.search(source); 68a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block # Accept several lines of 'Files:' 69a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block while True: 70a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block if files_match: 71a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block additional_files += files_match.group(1).strip().split() 72a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block files_match = FILES_PATTERN.search(source, files_match.end()) 73a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block else: 74a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block break 75a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block for a_file in additional_files: 76a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block result.append(join(dirname(self.config.root), '..', a_file)) 77a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block framework = join(dirname(self.config.root), 'mjsunit', 'mjsunit.js') 78a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block if SELF_SCRIPT_PATTERN.search(source): 79a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block result.append(self.CreateSelfScript()) 80a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block result += [framework, self.file] 81a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return result 82a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 8344f0eee88ff00398ff7f715fab053374d808c90dSteve Block def GetCommand(self): 8444f0eee88ff00398ff7f715fab053374d808c90dSteve Block source = open(self.file).read() 8544f0eee88ff00398ff7f715fab053374d808c90dSteve Block result = self.GetVmCommand(source) 8644f0eee88ff00398ff7f715fab053374d808c90dSteve Block result += self.GetVmArguments(source) 8744f0eee88ff00398ff7f715fab053374d808c90dSteve Block if self.isolates: 8844f0eee88ff00398ff7f715fab053374d808c90dSteve Block result.append("--isolate") 8944f0eee88ff00398ff7f715fab053374d808c90dSteve Block result += self.GetVmArguments(source) 9044f0eee88ff00398ff7f715fab053374d808c90dSteve Block return result 9144f0eee88ff00398ff7f715fab053374d808c90dSteve Block 92a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block def GetSource(self): 93a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return open(self.file).read() 94a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 95a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block def CreateSelfScript(self): 96a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block (fd_self_script, self_script) = tempfile.mkstemp(suffix=".js") 97a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block def MakeJsConst(name, value): 98a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return "var %(name)s=\'%(value)s\';\n" % \ 99a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block {'name': name, \ 100a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 'value': value.replace('\\', '\\\\').replace('\'', '\\\'') } 101a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block try: 102a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block os.write(fd_self_script, MakeJsConst('TEST_FILE_NAME', self.file)) 103a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block except IOError, e: 104a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block test.PrintError("write() " + str(e)) 105a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block os.close(fd_self_script) 106a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block self.self_script = self_script 107a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return self_script 108a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 10980d68eab642096c1a48b6474d6ec33064b0ad1f5Kristian Monsen def AfterRun(self, result): 110257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch if self.self_script and (not result or (not result.HasPreciousOutput())): 111a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block test.CheckedUnlink(self.self_script) 112a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 113a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass MjsunitTestConfiguration(test.TestConfiguration): 114a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 115a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block def __init__(self, context, root): 116a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block super(MjsunitTestConfiguration, self).__init__(context, root) 117a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 118a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block def Ls(self, path): 119a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block def SelectTest(name): 120a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return name.endswith('.js') and name != 'mjsunit.js' 121a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return [f[:-3] for f in os.listdir(path) if SelectTest(f)] 122a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 12344f0eee88ff00398ff7f715fab053374d808c90dSteve Block def ListTests(self, current_path, path, mode, variant_flags): 124a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block mjsunit = [current_path + [t] for t in self.Ls(self.root)] 125a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block regress = [current_path + ['regress', t] for t in self.Ls(join(self.root, 'regress'))] 126a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block bugs = [current_path + ['bugs', t] for t in self.Ls(join(self.root, 'bugs'))] 127a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block third_party = [current_path + ['third_party', t] for t in self.Ls(join(self.root, 'third_party'))] 128a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block tools = [current_path + ['tools', t] for t in self.Ls(join(self.root, 'tools'))] 1293ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block compiler = [current_path + ['compiler', t] for t in self.Ls(join(self.root, 'compiler'))] 1303fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch harmony = [current_path + ['harmony', t] for t in self.Ls(join(self.root, 'harmony'))] 131b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch mjsunit.sort() 132b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch regress.sort() 133b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch bugs.sort() 134b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch third_party.sort() 135b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch tools.sort() 136b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch compiler.sort() 1373fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch harmony.sort() 1383fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch all_tests = mjsunit + regress + bugs + third_party + tools + compiler + harmony 139a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block result = [] 140a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block for test in all_tests: 141a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block if self.Contains(path, test): 142a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block file_path = join(self.root, reduce(join, test[1:], "") + ".js") 14344f0eee88ff00398ff7f715fab053374d808c90dSteve Block result.append(MjsunitTestCase(test, file_path, mode, self.context, self, False)) 14444f0eee88ff00398ff7f715fab053374d808c90dSteve Block result.append(MjsunitTestCase(test, file_path, mode, self.context, self, True)) 145a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return result 146a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 147a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block def GetBuildRequirements(self): 14869a99ed0b2b2ef69d393c371b03db3a98aaf880eBen Murdoch return ['d8'] 149a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 150a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block def GetTestStatus(self, sections, defs): 151a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block status_file = join(self.root, 'mjsunit.status') 152a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block if exists(status_file): 153a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block test.ReadConfigurationInto(status_file, sections, defs) 154a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 155a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 156a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 157a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockdef GetConfiguration(context, root): 158a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return MjsunitTestConfiguration(context, root) 159