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 os 29a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockimport re 30b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 31b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfrom testrunner.local import testsuite 32b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfrom testrunner.objects import testcase 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 39b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochclass MjsunitTestSuite(testsuite.TestSuite): 40b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 41b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch def __init__(self, name, root): 42b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch super(MjsunitTestSuite, self).__init__(name, root) 43b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 44b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch def ListTests(self, context): 45b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch tests = [] 46b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch for dirname, dirs, files in os.walk(self.root): 47b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch for dotted in [x for x in dirs if x.startswith('.')]: 48b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch dirs.remove(dotted) 49b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch dirs.sort() 50b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch files.sort() 51b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch for filename in files: 52b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch if filename.endswith(".js") and filename != "mjsunit.js": 53b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch testname = os.path.join(dirname[len(self.root) + 1:], filename[:-3]) 54b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch test = testcase.TestCase(self, testname) 55b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch tests.append(test) 56b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch return tests 57b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 58b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch def GetFlagsForTestCase(self, testcase, context): 59b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch source = self.GetSourceForTest(testcase) 60b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch flags = [] + context.mode_flags 61b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch flags_match = re.findall(FLAGS_PATTERN, source) 62b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch for match in flags_match: 63b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch flags += match.strip().split() 64b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 65b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch files_list = [] # List of file names to append to command arguments. 66a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block files_match = FILES_PATTERN.search(source); 67b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch # Accept several lines of 'Files:'. 68a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block while True: 69a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block if files_match: 70b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch files_list += files_match.group(1).strip().split() 71a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block files_match = FILES_PATTERN.search(source, files_match.end()) 72a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block else: 73a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block break 74b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch files = [ os.path.normpath(os.path.join(self.root, '..', '..', f)) 75b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch for f in files_list ] 76b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch testfilename = os.path.join(self.root, testcase.path + self.suffix()) 77a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block if SELF_SCRIPT_PATTERN.search(source): 78b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch env = ["-e", "TEST_FILE_NAME=\"%s\"" % testfilename.replace("\\", "\\\\")] 79b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch files = env + files 80b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch files.append(os.path.join(self.root, "mjsunit.js")) 81b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch files.append(testfilename) 82a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 83b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch flags += files 84b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch if context.isolates: 85b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch flags.append("--isolate") 86b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch flags += files 87a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 88b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch return testcase.flags + flags 89a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 90b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch def GetSourceForTest(self, testcase): 91b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch filename = os.path.join(self.root, testcase.path + self.suffix()) 92b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch with open(filename) as f: 93b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch return f.read() 94a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 95a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 96b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochdef GetSuite(name, root): 97b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch return MjsunitTestSuite(name, root) 98