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

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

Issue 23440009: [android] Fail if all devices drop offline while running tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | build/android/pylib/base/test_dispatcher_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 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 """Dispatches tests, either sharding or replicating them. 5 """Dispatches tests, either sharding or replicating them.
6 6
7 Performs the following steps: 7 Performs the following steps:
8 * Create a test collection factory, using the given tests 8 * Create a test collection factory, using the given tests
9 - If sharding: test collection factory returns the same shared test collection 9 - If sharding: test collection factory returns the same shared test collection
10 to all test runners 10 to all test runners
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 self._item_avaliable_or_all_done.set() 119 self._item_avaliable_or_all_done.set()
120 120
121 def __iter__(self): 121 def __iter__(self):
122 """Iterate through tests in the collection until all have been handled.""" 122 """Iterate through tests in the collection until all have been handled."""
123 while True: 123 while True:
124 r = self._pop() 124 r = self._pop()
125 if r is None: 125 if r is None:
126 break 126 break
127 yield r 127 yield r
128 128
129 def __len__(self):
130 """Return the number of tests currently in the collection."""
131 return len(self._tests)
132
129 133
130 def _RunTestsFromQueue(runner, test_collection, out_results, watcher, 134 def _RunTestsFromQueue(runner, test_collection, out_results, watcher,
131 num_retries, tag_results_with_device=False): 135 num_retries, tag_results_with_device=False):
132 """Runs tests from the test_collection until empty using the given runner. 136 """Runs tests from the test_collection until empty using the given runner.
133 137
134 Adds TestRunResults objects to the out_results list and may add tests to the 138 Adds TestRunResults objects to the out_results list and may add tests to the
135 out_retry list. 139 out_retry list.
136 140
137 Args: 141 Args:
138 runner: A TestRunner object used to run the tests. 142 runner: A TestRunner object used to run the tests.
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 the test was run to the test name. Used when replicating to identify 232 the test was run to the test name. Used when replicating to identify
229 which device ran each copy of the test, and to ensure each copy of the 233 which device ran each copy of the test, and to ensure each copy of the
230 test is recorded separately. 234 test is recorded separately.
231 235
232 Returns: 236 Returns:
233 A tuple of (TestRunResults object, exit code) 237 A tuple of (TestRunResults object, exit code)
234 """ 238 """
235 logging.warning('Running tests with %s test runners.' % (len(runners))) 239 logging.warning('Running tests with %s test runners.' % (len(runners)))
236 results = [] 240 results = []
237 exit_code = 0 241 exit_code = 0
242 run_results = base_test_result.TestRunResults()
238 watcher = watchdog_timer.WatchdogTimer(timeout) 243 watcher = watchdog_timer.WatchdogTimer(timeout)
244 test_collections = [test_collection_factory() for _ in runners]
239 245
240 workers = reraiser_thread.ReraiserThreadGroup( 246 threads = [
241 [reraiser_thread.ReraiserThread( 247 reraiser_thread.ReraiserThread(
242 _RunTestsFromQueue, 248 _RunTestsFromQueue,
243 [r, test_collection_factory(), results, watcher, num_retries, 249 [r, tc, results, watcher, num_retries, tag_results_with_device],
244 tag_results_with_device],
245 name=r.device[-4:]) 250 name=r.device[-4:])
246 for r in runners]) 251 for r, tc in zip(runners, test_collections)]
247 run_results = base_test_result.TestRunResults() 252
253 workers = reraiser_thread.ReraiserThreadGroup(threads)
248 workers.StartAll() 254 workers.StartAll()
249 255
250 # Catch DeviceUnresponsiveErrors and set a warning exit code 256 # Catch DeviceUnresponsiveErrors and set a warning exit code
251 try: 257 try:
252 workers.JoinAll(watcher) 258 workers.JoinAll(watcher)
253 except android_commands.errors.DeviceUnresponsiveError as e: 259 except android_commands.errors.DeviceUnresponsiveError as e:
254 logging.error(e) 260 logging.error(e)
255 exit_code = constants.WARNING_EXIT_CODE 261 exit_code = constants.WARNING_EXIT_CODE
256 262
263 assert all([len(tc) == 0 for tc in test_collections]), (
264 'Some tests were not run, all devices are likely offline (ran %d tests)' %
265 len(run_results.GetAll()))
266
257 for r in results: 267 for r in results:
258 run_results.AddTestRunResults(r) 268 run_results.AddTestRunResults(r)
259 if not run_results.DidRunPass(): 269 if not run_results.DidRunPass():
260 exit_code = constants.ERROR_EXIT_CODE 270 exit_code = constants.ERROR_EXIT_CODE
261 return (run_results, exit_code) 271 return (run_results, exit_code)
262 272
263 273
264 def _CreateRunners(runner_factory, devices, timeout=None): 274 def _CreateRunners(runner_factory, devices, timeout=None):
265 """Creates a test runner for each device and calls SetUp() in parallel. 275 """Creates a test runner for each device and calls SetUp() in parallel.
266 276
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 logging.info('Will run %d tests (%s): %s', len(tests), log_string, str(tests)) 357 logging.info('Will run %d tests (%s): %s', len(tests), log_string, str(tests))
348 runners = _CreateRunners(runner_factory, devices, setup_timeout) 358 runners = _CreateRunners(runner_factory, devices, setup_timeout)
349 try: 359 try:
350 return _RunAllTests(runners, test_collection_factory, 360 return _RunAllTests(runners, test_collection_factory,
351 num_retries, test_timeout, tag_results_with_device) 361 num_retries, test_timeout, tag_results_with_device)
352 finally: 362 finally:
353 try: 363 try:
354 _TearDownRunners(runners, setup_timeout) 364 _TearDownRunners(runners, setup_timeout)
355 except android_commands.errors.DeviceUnresponsiveError as e: 365 except android_commands.errors.DeviceUnresponsiveError as e:
356 logging.warning('Device unresponsive during TearDown: [%s]', e) 366 logging.warning('Device unresponsive during TearDown: [%s]', e)
OLDNEW
« no previous file with comments | « no previous file | build/android/pylib/base/test_dispatcher_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698