1 # Copyright 2009 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 os 30 from os.path import join, exists 31 import sys 32 import test 33 import time 34 35 36 class SputnikTestCase(test.TestCase): 37 38 def __init__(self, case, path, context, mode): 39 super(SputnikTestCase, self).__init__(context, path, mode) 40 self.case = case 41 self.tmpfile = None 42 self.source = None 43 44 def IsNegative(self): 45 return '@negative' in self.GetSource() 46 47 def IsFailureOutput(self, output): 48 if output.exit_code != 0: 49 return True 50 out = output.stdout 51 return "SputnikError" in out 52 53 def BeforeRun(self): 54 self.tmpfile = sputnik.TempFile(suffix='.js', prefix='sputnik-', text=True) 55 self.tmpfile.Write(self.GetSource()) 56 self.tmpfile.Close() 57 58 def AfterRun(self, result): 59 # Dispose the temporary file if everything looks okay. 60 if result is None or not result.HasPreciousOutput(): self.tmpfile.Dispose() 61 self.tmpfile = None 62 63 def GetCommand(self): 64 result = self.context.GetVmCommand(self, self.mode) 65 result.append(self.tmpfile.name) 66 return result 67 68 def GetLabel(self): 69 return "%s sputnik %s" % (self.mode, self.GetName()) 70 71 def GetName(self): 72 return self.path[-1] 73 74 def GetSource(self): 75 if not self.source: 76 self.source = self.case.GetSource() 77 return self.source 78 79 class SputnikTestConfiguration(test.TestConfiguration): 80 81 def __init__(self, context, root): 82 super(SputnikTestConfiguration, self).__init__(context, root) 83 84 def ListTests(self, current_path, path, mode, variant_flags): 85 # Import the sputnik test runner script as a module 86 testroot = join(self.root, 'sputniktests') 87 modroot = join(testroot, 'tools') 88 sys.path.append(modroot) 89 import sputnik 90 globals()['sputnik'] = sputnik 91 # Do not run strict mode tests yet. TODO(mmaly) 92 test_suite = sputnik.TestSuite(testroot, False) 93 test_suite.Validate() 94 tests = test_suite.EnumerateTests([]) 95 result = [] 96 for test in tests: 97 full_path = current_path + [test.GetPath()[-1]] 98 if self.Contains(path, full_path): 99 case = SputnikTestCase(test, full_path, self.context, mode) 100 result.append(case) 101 return result 102 103 def GetBuildRequirements(self): 104 return ['d8'] 105 106 def GetTestStatus(self, sections, defs): 107 status_file = join(self.root, 'sputnik.status') 108 if exists(status_file): 109 test.ReadConfigurationInto(status_file, sections, defs) 110 111 112 def GetConfiguration(context, root): 113 return SputnikTestConfiguration(context, root) 114