blob: 31e4b226f8962c857d5a2e04f966d1b805611402 [file] [log] [blame]
Steve Blockd0582a62009-12-15 09:54:21 +00001# 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):
Kristian Monsen80d68ea2010-09-08 11:05:35 +010039 super(SputnikTestCase, self).__init__(context, path, mode)
Steve Blockd0582a62009-12-15 09:54:21 +000040 self.case = case
Steve Blockd0582a62009-12-15 09:54:21 +000041 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
Kristian Monsen80d68ea2010-09-08 11:05:35 +010058 def AfterRun(self, result):
59 # Dispose the temporary file if everything looks okay.
60 if not result.HasPreciousOutput(): self.tmpfile.Dispose()
Steve Blockd0582a62009-12-15 09:54:21 +000061 self.tmpfile = None
62
63 def GetCommand(self):
Kristian Monsen80d68ea2010-09-08 11:05:35 +010064 result = self.context.GetVmCommand(self, self.mode)
Steve Blockd0582a62009-12-15 09:54:21 +000065 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
Ben Murdoche0cee9b2011-05-25 10:26:03 +010091 # Do not run strict mode tests yet. TODO(mmaly)
92 test_suite = sputnik.TestSuite(testroot, False)
Steve Blockd0582a62009-12-15 09:54:21 +000093 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 ['sample', 'sample=shell']
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
112def GetConfiguration(context, root):
113 return SputnikTestConfiguration(context, root)