Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Side by Side Diff: build/android/pylib/base/base_test_result.py

Issue 18323020: Updates the test runner script exit codes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes exit_code tracking to a singleton paradigm Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | build/android/pylib/base/shard.py » ('j') | build/android/test_runner.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Module containing base test results classes.""" 5 """Module containing base test results classes."""
6 6
7 from pylib import constants
8 from pylib import exit_code
7 9
8 class ResultType(object): 10 class ResultType(object):
9 """Class enumerating test types.""" 11 """Class enumerating test types."""
10 PASS = 'PASS' 12 PASS = 'PASS'
11 FAIL = 'FAIL' 13 FAIL = 'FAIL'
12 CRASH = 'CRASH' 14 CRASH = 'CRASH'
13 TIMEOUT = 'TIMEOUT' 15 TIMEOUT = 'TIMEOUT'
14 UNKNOWN = 'UNKNOWN' 16 UNKNOWN = 'UNKNOWN'
15 17
16 @staticmethod 18 @staticmethod
17 def GetTypes(): 19 def GetTypes():
18 """Get a list of all test types.""" 20 """Get a list of all test types."""
19 return [ResultType.PASS, ResultType.FAIL, ResultType.CRASH, 21 return [ResultType.PASS, ResultType.FAIL, ResultType.CRASH,
20 ResultType.TIMEOUT, ResultType.UNKNOWN] 22 ResultType.TIMEOUT, ResultType.UNKNOWN]
21 23
22 24
23 class BaseTestResult(object): 25 class BaseTestResult(object):
24 """Base class for a single test result.""" 26 """Base class for a single test result."""
27
25 def __init__(self, name, test_type, log=''): 28 def __init__(self, name, test_type, log=''):
26 """Construct a BaseTestResult. 29 """Construct a BaseTestResult.
27 30
28 Args: 31 Args:
29 name: Name of the test which defines uniqueness. 32 name: Name of the test which defines uniqueness.
30 test_type: Type of the test result as defined in ResultType. 33 test_type: Type of the test result as defined in ResultType.
31 log: An optional string listing any errors. 34 log: An optional string listing any errors.
32 """ 35 """
33 assert name 36 assert name
34 assert test_type in ResultType.GetTypes() 37 assert test_type in ResultType.GetTypes()
(...skipping 22 matching lines...) Expand all
57 """Get the test result type.""" 60 """Get the test result type."""
58 return self._test_type 61 return self._test_type
59 62
60 def GetLog(self): 63 def GetLog(self):
61 """Get the test log.""" 64 """Get the test log."""
62 return self._log 65 return self._log
63 66
64 67
65 class TestRunResults(object): 68 class TestRunResults(object):
66 """Set of results for a test run.""" 69 """Set of results for a test run."""
70
67 def __init__(self): 71 def __init__(self):
68 self._results = set() 72 self._results = set()
69 73
70 def GetLogs(self): 74 def GetLogs(self):
71 """Get the string representation of all test logs.""" 75 """Get the string representation of all test logs."""
72 s = [] 76 s = []
73 for test_type in ResultType.GetTypes(): 77 for test_type in ResultType.GetTypes():
74 if test_type != ResultType.PASS: 78 if test_type != ResultType.PASS:
75 for t in sorted(self._GetType(test_type)): 79 for t in sorted(self._GetType(test_type)):
76 log = t.GetLog() 80 log = t.GetLog()
(...skipping 26 matching lines...) Expand all
103 return self.GetLongForm() 107 return self.GetLongForm()
104 108
105 def AddResult(self, result): 109 def AddResult(self, result):
106 """Add |result| to the set. 110 """Add |result| to the set.
107 111
108 Args: 112 Args:
109 result: An instance of BaseTestResult. 113 result: An instance of BaseTestResult.
110 """ 114 """
111 assert isinstance(result, BaseTestResult) 115 assert isinstance(result, BaseTestResult)
112 self._results.add(result) 116 self._results.add(result)
117 if result.GetType() not in [ResultType.PASS, ResultType.UNKNOWN]:
118 exit_code.UpdateExitCode(constants.ERROR_EXIT_CODE)
113 119
114 def AddResults(self, results): 120 def AddResults(self, results):
115 """Add |results| to the set. 121 """Add |results| to the set.
116 122
117 Args: 123 Args:
118 results: An iterable of BaseTestResult objects. 124 results: An iterable of BaseTestResult objects.
119 """ 125 """
120 for t in results: 126 for t in results:
121 self.AddResult(t) 127 self.AddResult(t)
122 128
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 """Get the set of all unknown test results.""" 164 """Get the set of all unknown test results."""
159 return self._GetType(ResultType.UNKNOWN) 165 return self._GetType(ResultType.UNKNOWN)
160 166
161 def GetNotPass(self): 167 def GetNotPass(self):
162 """Get the set of all non-passed test results.""" 168 """Get the set of all non-passed test results."""
163 return self.GetAll() - self.GetPass() 169 return self.GetAll() - self.GetPass()
164 170
165 def DidRunPass(self): 171 def DidRunPass(self):
166 """Return whether the test run was successful.""" 172 """Return whether the test run was successful."""
167 return not self.GetNotPass() 173 return not self.GetNotPass()
OLDNEW
« no previous file with comments | « no previous file | build/android/pylib/base/shard.py » ('j') | build/android/test_runner.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698