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