Bug 797526 - some assertions in nsDOMClassInfo should be fatal in debug builds -...
[gecko.git] / media / webrtc / trunk / build / android / test_result.py
blob0c564368a133f7f4d383f4df6cb6c0e1445f7217
1 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
6 import logging
9 # Language values match constants in Sponge protocol buffer (sponge.proto).
10 JAVA = 5
11 PYTHON = 7
14 class BaseTestResult(object):
15 """A single result from a unit test."""
17 def __init__(self, name, log):
18 self.name = name
19 self.log = log
22 class SingleTestResult(BaseTestResult):
23 """Result information for a single test.
25 Args:
26 full_name: Full name of the test.
27 start_date: Date in milliseconds when the test began running.
28 dur: Duration of the test run in milliseconds.
29 lang: Language of the test (JAVA or PYTHON).
30 log: An optional string listing any errors.
31 error: A tuple of a short error message and a longer version used by Sponge
32 if test resulted in a fail or error. An empty tuple implies a pass.
33 """
35 def __init__(self, full_name, start_date, dur, lang, log='', error=()):
36 BaseTestResult.__init__(self, full_name, log)
37 name_pieces = full_name.rsplit('#')
38 if len(name_pieces) > 0:
39 self.test_name = name_pieces[1]
40 self.class_name = name_pieces[0]
41 else:
42 self.class_name = full_name
43 self.test_name = full_name
44 self.start_date = start_date
45 self.dur = dur
46 self.error = error
47 self.lang = lang
50 class TestResults(object):
51 """Results of a test run."""
53 def __init__(self):
54 self.ok = []
55 self.failed = []
56 self.crashed = []
57 self.unknown = []
58 self.disabled = []
59 self.unexpected_pass = []
60 self.timed_out = False
62 @staticmethod
63 def FromOkAndFailed(ok, failed, timed_out=False):
64 ret = TestResults()
65 ret.ok = ok
66 ret.failed = failed
67 ret.timed_out = timed_out
68 return ret
70 @staticmethod
71 def FromTestResults(results):
72 """Combines a list of results in a single TestResults object."""
73 ret = TestResults()
74 for t in results:
75 ret.ok += t.ok
76 ret.failed += t.failed
77 ret.crashed += t.crashed
78 ret.unknown += t.unknown
79 ret.disabled += t.disabled
80 ret.unexpected_pass += t.unexpected_pass
81 if t.timed_out:
82 ret.timed_out = True
83 return ret
85 def _Log(self, sorted_list):
86 for t in sorted_list:
87 logging.critical(t.name)
88 if t.log:
89 logging.critical(t.log)
91 def GetAllBroken(self):
92 """Returns the all broken tests including failed, crashed, unknown."""
93 return self.failed + self.crashed + self.unknown
95 def LogFull(self):
96 """Output all broken tests or 'passed' if none broken"""
97 logging.critical('*' * 80)
98 logging.critical('Final result')
99 if self.failed:
100 logging.critical('Failed:')
101 self._Log(sorted(self.failed))
102 if self.crashed:
103 logging.critical('Crashed:')
104 self._Log(sorted(self.crashed))
105 if self.unknown:
106 logging.critical('Unknown:')
107 self._Log(sorted(self.unknown))
108 if not self.GetAllBroken():
109 logging.critical('Passed')
110 logging.critical('*' * 80)