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 28import test 29import os 30import re 31from functools import reduce 32from io import open 33 34 35FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)") 36LS_RE = re.compile(r'^test-.*\.m?js$') 37 38class SimpleTestCase(test.TestCase): 39 40 def __init__(self, path, file, arch, mode, context, config, additional=None): 41 super(SimpleTestCase, self).__init__(context, path, arch, mode) 42 self.file = file 43 self.config = config 44 self.arch = arch 45 self.mode = mode 46 if additional is not None: 47 self.additional_flags = additional 48 else: 49 self.additional_flags = [] 50 51 52 def GetLabel(self): 53 return "%s %s" % (self.mode, self.GetName()) 54 55 def GetName(self): 56 return self.path[-1] 57 58 def GetCommand(self): 59 result = [self.config.context.GetVm(self.arch, self.mode)] 60 source = open(self.file, encoding='utf8').read() 61 flags_match = FLAGS_PATTERN.search(source) 62 if flags_match: 63 flags = flags_match.group(1).strip().split() 64 # The following block reads config.gypi to extract the v8_enable_inspector 65 # value. This is done to check if the inspector is disabled in which case 66 # the '--inspect' flag cannot be passed to the node process as it will 67 # cause node to exit and report the test as failed. The use case 68 # is currently when Node is configured --without-ssl and the tests should 69 # still be runnable but skip any tests that require ssl (which includes the 70 # inspector related tests). Also, if there is no ssl support the options 71 # '--use-bundled-ca' and '--use-openssl-ca' will also cause a similar 72 # failure so such tests are also skipped. 73 if (any(flag.startswith('--inspect') for flag in flags) and 74 not self.context.v8_enable_inspector): 75 print(': Skipping as node was compiled without inspector support') 76 elif (('--use-bundled-ca' in flags or 77 '--use-openssl-ca' in flags or 78 '--tls-v1.0' in flags or 79 '--tls-v1.1' in flags) and 80 not self.context.node_has_crypto): 81 print(': Skipping as node was compiled without crypto support') 82 else: 83 result += flags 84 85 if self.additional_flags: 86 result += self.additional_flags 87 88 result += [self.file] 89 90 return result 91 92 def GetSource(self): 93 return open(self.file).read() 94 95 96class SimpleTestConfiguration(test.TestConfiguration): 97 def __init__(self, context, root, section, additional=None): 98 super(SimpleTestConfiguration, self).__init__(context, root, section) 99 if additional is not None: 100 self.additional_flags = additional 101 else: 102 self.additional_flags = [] 103 104 def Ls(self, path): 105 return [f for f in os.listdir(path) if LS_RE.match(f)] 106 107 def ListTests(self, current_path, path, arch, mode): 108 all_tests = [current_path + [t] for t in self.Ls(os.path.join(self.root))] 109 result = [] 110 for tst in all_tests: 111 if self.Contains(path, tst): 112 file_path = os.path.join(self.root, reduce(os.path.join, tst[1:], "")) 113 test_name = tst[:-1] + [os.path.splitext(tst[-1])[0]] 114 result.append(SimpleTestCase(test_name, file_path, arch, mode, 115 self.context, self, self.additional_flags)) 116 return result 117 118 def GetBuildRequirements(self): 119 return ['sample', 'sample=shell'] 120 121class ParallelTestConfiguration(SimpleTestConfiguration): 122 def __init__(self, context, root, section, additional=None): 123 super(ParallelTestConfiguration, self).__init__(context, root, section, 124 additional) 125 126 def ListTests(self, current_path, path, arch, mode): 127 result = super(ParallelTestConfiguration, self).ListTests( 128 current_path, path, arch, mode) 129 for tst in result: 130 tst.parallel = True 131 return result 132 133class AddonTestConfiguration(SimpleTestConfiguration): 134 def __init__(self, context, root, section, additional=None): 135 super(AddonTestConfiguration, self).__init__(context, root, section, additional) 136 137 def Ls(self, path): 138 def SelectTest(name): 139 return name.endswith('.js') 140 141 result = [] 142 for subpath in os.listdir(path): 143 if os.path.isdir(os.path.join(path, subpath)): 144 for f in os.listdir(os.path.join(path, subpath)): 145 if SelectTest(f): 146 result.append([subpath, f[:-3]]) 147 return result 148 149 def ListTests(self, current_path, path, arch, mode): 150 all_tests = [current_path + t for t in self.Ls(os.path.join(self.root))] 151 result = [] 152 for tst in all_tests: 153 if self.Contains(path, tst): 154 file_path = os.path.join(self.root, reduce(os.path.join, tst[1:], "") + ".js") 155 result.append( 156 SimpleTestCase(tst, file_path, arch, mode, self.context, self, self.additional_flags)) 157 return result 158 159class AbortTestConfiguration(SimpleTestConfiguration): 160 def __init__(self, context, root, section, additional=None): 161 super(AbortTestConfiguration, self).__init__(context, root, section, 162 additional) 163 164 def ListTests(self, current_path, path, arch, mode): 165 result = super(AbortTestConfiguration, self).ListTests( 166 current_path, path, arch, mode) 167 for tst in result: 168 tst.disable_core_files = True 169 return result 170