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 29import os 30from os.path import join, exists 31import sys 32import test 33import time 34 35 36class SputnikTestCase(test.TestCase): 37 38 def __init__(self, case, path, context, mode): 39 super(SputnikTestCase, self).__init__(context, path) 40 self.case = case 41 self.mode = mode 42 self.tmpfile = None 43 self.source = None 44 45 def IsNegative(self): 46 return '@negative' in self.GetSource() 47 48 def IsFailureOutput(self, output): 49 if output.exit_code != 0: 50 return True 51 out = output.stdout 52 return "SputnikError" in out 53 54 def BeforeRun(self): 55 self.tmpfile = sputnik.TempFile(suffix='.js', prefix='sputnik-', text=True) 56 self.tmpfile.Write(self.GetSource()) 57 self.tmpfile.Close() 58 59 def AfterRun(self): 60 self.tmpfile.Dispose() 61 self.tmpfile = None 62 63 def GetCommand(self): 64 result = [self.context.GetVm(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 79class 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): 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 test_suite = sputnik.TestSuite(testroot) 92 test_suite.Validate() 93 tests = test_suite.EnumerateTests([]) 94 result = [] 95 for test in tests: 96 full_path = current_path + [test.GetPath()[-1]] 97 if self.Contains(path, full_path): 98 case = SputnikTestCase(test, full_path, self.context, mode) 99 result.append(case) 100 return result 101 102 def GetBuildRequirements(self): 103 return ['sample', 'sample=shell'] 104 105 def GetTestStatus(self, sections, defs): 106 status_file = join(self.root, 'sputnik.status') 107 if exists(status_file): 108 test.ReadConfigurationInto(status_file, sections, defs) 109 110 111def GetConfiguration(context, root): 112 return SputnikTestConfiguration(context, root) 113