1# 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 29import test 30import os 31from os.path import join, exists 32 33 34HARNESS_FILES = ['sth.js'] 35 36 37class ES5ConformTestCase(test.TestCase): 38 39 def __init__(self, filename, path, context, root, mode, framework): 40 super(ES5ConformTestCase, self).__init__(context, path, mode) 41 self.filename = filename 42 self.framework = framework 43 self.root = root 44 45 def IsNegative(self): 46 return self.filename.endswith('-n.js') 47 48 def GetLabel(self): 49 return "%s es5conform %s" % (self.mode, self.GetName()) 50 51 def IsFailureOutput(self, output): 52 if output.exit_code != 0: 53 return True 54 return 'FAILED!' in output.stdout 55 56 def GetCommand(self): 57 result = self.context.GetVmCommand(self, self.mode) 58 result += ['-e', 'var window = this'] 59 result += self.framework 60 result.append(self.filename) 61 result += ['-e', 'ES5Harness.startTesting()'] 62 return result 63 64 def GetName(self): 65 return self.path[-1] 66 67 def GetSource(self): 68 return open(self.filename).read() 69 70 71class ES5ConformTestConfiguration(test.TestConfiguration): 72 73 def __init__(self, context, root): 74 super(ES5ConformTestConfiguration, self).__init__(context, root) 75 76 def ListTests(self, current_path, path, mode, variant_flags): 77 tests = [] 78 current_root = join(self.root, 'data', 'TestCases') 79 harness = [] 80 harness += [join(self.root, 'data', 'SimpleTestHarness', f) for f in HARNESS_FILES] 81 harness += [join(self.root, 'harness-adapt.js')] 82 for root, dirs, files in os.walk(current_root): 83 for dotted in [x for x in dirs if x.startswith('.')]: 84 dirs.remove(dotted) 85 dirs.sort() 86 root_path = root[len(self.root):].split(os.path.sep) 87 root_path = current_path + [x for x in root_path if x] 88 files.sort() 89 for file in files: 90 if file.endswith('.js'): 91 full_path = root_path + [file[:-3]] 92 full_path = [x for x in full_path if not (x in ['data', 'TestCases'])] 93 if self.Contains(path, full_path): 94 test = ES5ConformTestCase(join(root, file), full_path, self.context, 95 self.root, mode, harness) 96 tests.append(test) 97 return tests 98 99 def GetBuildRequirements(self): 100 return ['d8'] 101 102 def GetTestStatus(self, sections, defs): 103 status_file = join(self.root, 'es5conform.status') 104 if exists(status_file): 105 test.ReadConfigurationInto(status_file, sections, defs) 106 107 108def GetConfiguration(context, root): 109 return ES5ConformTestConfiguration(context, root) 110