5 class ResultCode(object):
6 """Test result codes."""
8 # We override __new__ and __getnewargs__ to ensure that pickling still
9 # provides unique ResultCode objects in any particular instance.
11 def __new__(cls, name, isFailure):
12 res = cls._instances.get(name)
14 cls._instances[name] = res = super(ResultCode, cls).__new__(cls)
16 def __getnewargs__(self):
17 return (self.name, self.isFailure)
19 def __init__(self, name, isFailure):
21 self.isFailure = isFailure
24 return '%s%r' % (self.__class__.__name__,
25 (self.name, self.isFailure))
27 PASS = ResultCode('PASS', False)
28 XFAIL = ResultCode('XFAIL', False)
29 FAIL = ResultCode('FAIL', True)
30 XPASS = ResultCode('XPASS', True)
31 UNRESOLVED = ResultCode('UNRESOLVED', True)
32 UNSUPPORTED = ResultCode('UNSUPPORTED', False)
36 class MetricValue(object):
41 Convert this metric to a string suitable for displaying as part of the
44 raise RuntimeError("abstract method")
48 todata() -> json-serializable data
50 Convert this metric to content suitable for serializing in the JSON test
53 raise RuntimeError("abstract method")
55 class IntMetricValue(MetricValue):
56 def __init__(self, value):
60 return str(self.value)
65 class RealMetricValue(MetricValue):
66 def __init__(self, value):
70 return '%.4f' % self.value
78 """Wrapper for the results of executing an individual test."""
80 def __init__(self, code, output='', elapsed=None):
85 # The wall timing to execute the test, if timing.
86 self.elapsed = elapsed
87 # The metrics reported by this test.
90 def addMetric(self, name, value):
92 addMetric(name, value)
94 Attach a test metric to the test result, with the given name and list of
95 values. It is an error to attempt to attach the metrics with the same
98 Each value must be an instance of a MetricValue subclass.
100 if name in self.metrics:
101 raise ValueError("result already includes metrics for %r" % (
103 if not isinstance(value, MetricValue):
104 raise TypeError("unexpected metric value: %r" % (value,))
105 self.metrics[name] = value
110 """TestSuite - Information on a group of tests.
112 A test suite groups together a set of logically related tests.
115 def __init__(self, name, source_root, exec_root, config):
117 self.source_root = source_root
118 self.exec_root = exec_root
119 # The test suite configuration.
122 def getSourcePath(self, components):
123 return os.path.join(self.source_root, *components)
125 def getExecPath(self, components):
126 return os.path.join(self.exec_root, *components)
129 """Test - Information on a single test instance."""
131 def __init__(self, suite, path_in_suite, config):
133 self.path_in_suite = path_in_suite
135 # A list of conditions under which this test is expected to fail. These
136 # can optionally be provided by test format handlers, and will be
137 # honored when the test result is supplied.
139 # The test result, once complete.
142 def setResult(self, result):
143 if self.result is not None:
144 raise ArgumentError("test result already set")
145 if not isinstance(result, Result):
146 raise ArgumentError("unexpected result type")
150 # Apply the XFAIL handling to resolve the result exit code.
151 if self.isExpectedToFail():
152 if self.result.code == PASS:
153 self.result.code = XPASS
154 elif self.result.code == FAIL:
155 self.result.code = XFAIL
157 def getFullName(self):
158 return self.suite.config.name + ' :: ' + '/'.join(self.path_in_suite)
160 def getSourcePath(self):
161 return self.suite.getSourcePath(self.path_in_suite)
163 def getExecPath(self):
164 return self.suite.getExecPath(self.path_in_suite)
166 def isExpectedToFail(self):
168 isExpectedToFail() -> bool
170 Check whether this test is expected to fail in the current
171 configuration. This check relies on the test xfails property which by
172 some test formats may not be computed until the test has first been
176 # Check if any of the xfails match an available feature or the target.
177 for item in self.xfails:
178 # If this is the wildcard, it always fails.
182 # If this is an exact match for one of the features, it fails.
183 if item in self.config.available_features:
186 # If this is a part of the target triple, it fails.
187 if item in self.suite.config.target_triple: