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 29 import test 30 import os 31 from os.path import join, exists 32 33 34 EXCLUDED = ['CVS'] 35 36 37 FRAMEWORK = """ 38 browser.js 39 shell.js 40 jsref.js 41 template.js 42 """.split() 43 44 45 TEST_DIRS = """ 46 ecma 47 ecma_2 48 ecma_3 49 js1_1 50 js1_2 51 js1_3 52 js1_4 53 js1_5 54 """.split() 55 56 57 class MozillaTestCase(test.TestCase): 58 59 def __init__(self, filename, path, context, root, mode, framework): 60 super(MozillaTestCase, self).__init__(context, path, mode) 61 self.filename = filename 62 self.framework = framework 63 self.root = root 64 65 def IsNegative(self): 66 return self.filename.endswith('-n.js') 67 68 def GetLabel(self): 69 return "%s mozilla %s" % (self.mode, self.GetName()) 70 71 def IsFailureOutput(self, output): 72 if output.exit_code != 0: 73 return True 74 return 'FAILED!' in output.stdout 75 76 def GetCommand(self): 77 result = self.context.GetVmCommand(self, self.mode) + \ 78 [ '--expose-gc', join(self.root, 'mozilla-shell-emulation.js') ] 79 result += self.framework 80 result.append(self.filename) 81 return result 82 83 def GetName(self): 84 return self.path[-1] 85 86 def GetSource(self): 87 return open(self.filename).read() 88 89 90 class MozillaTestConfiguration(test.TestConfiguration): 91 92 def __init__(self, context, root): 93 super(MozillaTestConfiguration, self).__init__(context, root) 94 95 def ListTests(self, current_path, path, mode, variant_flags): 96 tests = [] 97 for test_dir in TEST_DIRS: 98 current_root = join(self.root, 'data', test_dir) 99 for root, dirs, files in os.walk(current_root): 100 for dotted in [x for x in dirs if x.startswith('.')]: 101 dirs.remove(dotted) 102 for excluded in EXCLUDED: 103 if excluded in dirs: 104 dirs.remove(excluded) 105 dirs.sort() 106 root_path = root[len(self.root):].split(os.path.sep) 107 root_path = current_path + [x for x in root_path if x] 108 framework = [] 109 for i in xrange(len(root_path)): 110 if i == 0: dir = root_path[1:] 111 else: dir = root_path[1:-i] 112 script = join(self.root, reduce(join, dir, ''), 'shell.js') 113 if exists(script): 114 framework.append(script) 115 framework.reverse() 116 files.sort() 117 for file in files: 118 if (not file in FRAMEWORK) and file.endswith('.js'): 119 full_path = root_path + [file[:-3]] 120 full_path = [x for x in full_path if x != 'data'] 121 if self.Contains(path, full_path): 122 test = MozillaTestCase(join(root, file), full_path, self.context, 123 self.root, mode, framework) 124 tests.append(test) 125 return tests 126 127 def GetBuildRequirements(self): 128 return ['d8'] 129 130 def GetTestStatus(self, sections, defs): 131 status_file = join(self.root, 'mozilla.status') 132 if exists(status_file): 133 test.ReadConfigurationInto(status_file, sections, defs) 134 135 136 def GetConfiguration(context, root): 137 return MozillaTestConfiguration(context, root) 138