OLD | NEW |
---|---|
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 import fnmatch | 5 import fnmatch |
6 import functools | 6 import functools |
7 import imp | 7 import imp |
8 import logging | 8 import logging |
9 | 9 |
10 from devil import base_error | 10 from devil import base_error |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
106 tests.add(test) | 106 tests.add(test) |
107 raise | 107 raise |
108 finally: | 108 finally: |
109 if isinstance(tests, test_collection.TestCollection): | 109 if isinstance(tests, test_collection.TestCollection): |
110 tests.test_completed() | 110 tests.test_completed() |
111 | 111 |
112 | 112 |
113 logging.info('Finished running tests on this device.') | 113 logging.info('Finished running tests on this device.') |
114 | 114 |
115 tries = 0 | 115 tries = 0 |
116 results = base_test_result.TestRunResults() | 116 results = [] |
117 all_fail_results = {} | |
118 while tries < self._env.max_tries and tests: | 117 while tries < self._env.max_tries and tests: |
119 logging.info('STARTING TRY #%d/%d', tries + 1, self._env.max_tries) | 118 logging.info('STARTING TRY #%d/%d', tries + 1, self._env.max_tries) |
120 logging.info('Will run %d tests on %d devices: %s', | 119 logging.info('Will run %d tests on %d devices: %s', |
121 len(tests), len(self._env.devices), | 120 len(tests), len(self._env.devices), |
122 ', '.join(str(d) for d in self._env.devices)) | 121 ', '.join(str(d) for d in self._env.devices)) |
123 for t in tests: | 122 for t in tests: |
124 logging.debug(' %s', t) | 123 logging.debug(' %s', t) |
125 | 124 |
126 try_results = base_test_result.TestRunResults() | 125 try_results = base_test_result.TestRunResults() |
127 if self._ShouldShard(): | 126 if self._ShouldShard(): |
128 tc = test_collection.TestCollection(self._CreateShards(tests)) | 127 tc = test_collection.TestCollection(self._CreateShards(tests)) |
129 self._env.parallel_devices.pMap( | 128 self._env.parallel_devices.pMap( |
130 run_tests_on_device, tc, try_results).pGet(None) | 129 run_tests_on_device, tc, try_results).pGet(None) |
131 else: | 130 else: |
132 self._env.parallel_devices.pMap( | 131 self._env.parallel_devices.pMap( |
133 run_tests_on_device, tests, try_results).pGet(None) | 132 run_tests_on_device, tests, try_results).pGet(None) |
134 | 133 |
135 for result in try_results.GetAll(): | 134 results.append(try_results) |
mikecase (-- gone --)
2016/05/13 17:32:13
Should this be results.extend(try_results)? Im kin
jbudorick
2016/05/13 17:37:05
No, try_results is a single instance of base_test_
| |
136 if result.GetType() in (base_test_result.ResultType.PASS, | 135 tries += 1 |
137 base_test_result.ResultType.SKIP): | 136 tests = self._GetTestsToRetry(tests, try_results) |
138 results.AddResult(result) | |
139 else: | |
140 all_fail_results[result.GetName()] = result | |
141 | 137 |
142 results_names = set(r.GetName() for r in results.GetAll()) | |
143 | |
144 def has_test_result(name): | |
145 # When specifying a test filter, names can contain trailing wildcards. | |
146 # See local_device_gtest_run._ExtractTestsFromFilter() | |
147 if name.endswith('*'): | |
148 return any(fnmatch.fnmatch(n, name) for n in results_names) | |
149 return name in results_names | |
150 | |
151 tests = [t for t in tests if not has_test_result(self._GetTestName(t))] | |
152 tries += 1 | |
153 logging.info('FINISHED TRY #%d/%d', tries, self._env.max_tries) | 138 logging.info('FINISHED TRY #%d/%d', tries, self._env.max_tries) |
154 if tests: | 139 if tests: |
155 logging.info('%d failed tests remain.', len(tests)) | 140 logging.info('%d failed tests remain.', len(tests)) |
156 else: | 141 else: |
157 logging.info('All tests completed.') | 142 logging.info('All tests completed.') |
158 | 143 |
159 all_unknown_test_names = set(self._GetTestName(t) for t in tests) | 144 return results |
160 all_failed_test_names = set(all_fail_results.iterkeys()) | |
161 | 145 |
162 unknown_tests = all_unknown_test_names.difference(all_failed_test_names) | 146 def _GetTestsToRetry(self, tests, try_results): |
163 failed_tests = all_failed_test_names.intersection(all_unknown_test_names) | 147 failed_test_names = set( |
148 r.GetName() for r in try_results.GetAll() | |
149 if r.GetType() not in (base_test_result.ResultType.PASS, | |
150 base_test_result.ResultType.SKIP)) | |
164 | 151 |
165 if unknown_tests: | 152 all_test_names = set(r.GetName() for r in try_results.GetAll()) |
166 results.AddResults( | |
167 base_test_result.BaseTestResult( | |
168 u, base_test_result.ResultType.UNKNOWN) | |
169 for u in unknown_tests) | |
170 if failed_tests: | |
171 results.AddResults(all_fail_results[f] for f in failed_tests) | |
172 | 153 |
173 return results | 154 def has_test_result(name): |
155 # When specifying a test filter, names can contain trailing wildcards. | |
156 # See local_device_gtest_run._ExtractTestsFromFilter() | |
157 if name.endswith('*'): | |
158 return any(fnmatch.fnmatch(n, name) for n in all_test_names) | |
159 return name in all_test_names | |
160 | |
161 unknown_test_names = set( | |
162 t for t in tests if not has_test_result(self._GetTestName(t))) | |
163 | |
164 return failed_test_names.union(unknown_test_names) | |
174 | 165 |
175 def GetTool(self, device): | 166 def GetTool(self, device): |
176 if not str(device) in self._tools: | 167 if not str(device) in self._tools: |
177 self._tools[str(device)] = valgrind_tools.CreateTool( | 168 self._tools[str(device)] = valgrind_tools.CreateTool( |
178 self._env.tool, device) | 169 self._env.tool, device) |
179 return self._tools[str(device)] | 170 return self._tools[str(device)] |
180 | 171 |
181 def _CreateShards(self, tests): | 172 def _CreateShards(self, tests): |
182 raise NotImplementedError | 173 raise NotImplementedError |
183 | 174 |
184 # pylint: disable=no-self-use | 175 # pylint: disable=no-self-use |
185 def _GetTestName(self, test): | 176 def _GetTestName(self, test): |
186 return test | 177 return test |
187 | 178 |
188 def _GetTests(self): | 179 def _GetTests(self): |
189 raise NotImplementedError | 180 raise NotImplementedError |
190 | 181 |
191 def _RunTest(self, device, test): | 182 def _RunTest(self, device, test): |
192 raise NotImplementedError | 183 raise NotImplementedError |
193 | 184 |
194 def _ShouldShard(self): | 185 def _ShouldShard(self): |
195 raise NotImplementedError | 186 raise NotImplementedError |
OLD | NEW |