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 os 30import shutil 31import subprocess 32 33from testrunner.local import testsuite 34from testrunner.objects import testcase 35 36EXCLUDED = ["CVS", ".svn"] 37 38 39FRAMEWORK = """ 40 browser.js 41 shell.js 42 jsref.js 43 template.js 44""".split() 45 46 47TEST_DIRS = """ 48 ecma 49 ecma_2 50 ecma_3 51 js1_1 52 js1_2 53 js1_3 54 js1_4 55 js1_5 56""".split() 57 58 59class MozillaTestSuite(testsuite.TestSuite): 60 61 def __init__(self, name, root): 62 super(MozillaTestSuite, self).__init__(name, root) 63 self.testroot = os.path.join(root, "data") 64 65 def ListTests(self, context): 66 tests = [] 67 for testdir in TEST_DIRS: 68 current_root = os.path.join(self.testroot, testdir) 69 for dirname, dirs, files in os.walk(current_root): 70 for dotted in [x for x in dirs if x.startswith(".")]: 71 dirs.remove(dotted) 72 for excluded in EXCLUDED: 73 if excluded in dirs: 74 dirs.remove(excluded) 75 dirs.sort() 76 files.sort() 77 for filename in files: 78 if filename.endswith(".js") and not filename in FRAMEWORK: 79 fullpath = os.path.join(dirname, filename) 80 relpath = fullpath[len(self.testroot) + 1 : -3] 81 testname = relpath.replace(os.path.sep, "/") 82 case = testcase.TestCase(self, testname) 83 tests.append(case) 84 return tests 85 86 def GetFlagsForTestCase(self, testcase, context): 87 result = [] 88 result += context.mode_flags 89 result += ["--expose-gc"] 90 result += [os.path.join(self.root, "mozilla-shell-emulation.js")] 91 testfilename = testcase.path + ".js" 92 testfilepath = testfilename.split("/") 93 for i in xrange(len(testfilepath)): 94 script = os.path.join(self.testroot, 95 reduce(os.path.join, testfilepath[:i], ""), 96 "shell.js") 97 if os.path.exists(script): 98 result.append(script) 99 result.append(os.path.join(self.testroot, testfilename)) 100 return testcase.flags + result 101 102 def GetSourceForTest(self, testcase): 103 filename = os.path.join(self.testroot, testcase.path + ".js") 104 with open(filename) as f: 105 return f.read() 106 107 def IsNegativeTest(self, testcase): 108 return testcase.path.endswith("-n") 109 110 def IsFailureOutput(self, output, testpath): 111 if output.exit_code != 0: 112 return True 113 return "FAILED!" in output.stdout 114 115 def DownloadData(self): 116 print "Mozilla download is deprecated. It's part of DEPS." 117 118 # Clean up old directories and archive files. 119 directory_old_name = os.path.join(self.root, "data.old") 120 if os.path.exists(directory_old_name): 121 shutil.rmtree(directory_old_name) 122 123 archive_files = [f for f in os.listdir(self.root) 124 if f.startswith("downloaded_")] 125 if len(archive_files) > 0: 126 print "Clobber outdated test archives ..." 127 for f in archive_files: 128 os.remove(os.path.join(self.root, f)) 129 130 131def GetSuite(name, root): 132 return MozillaTestSuite(name, root) 133