| OLD | NEW |
| 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 Loading... |
| 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| 238 watcher = watchdog_timer.WatchdogTimer(timeout) | 242 watcher = watchdog_timer.WatchdogTimer(timeout) |
| 243 test_collections = [test_collection_factory() for _ in runners] |
| 239 | 244 |
| 240 workers = reraiser_thread.ReraiserThreadGroup( | 245 workers = reraiser_thread.ReraiserThreadGroup( |
| 241 [reraiser_thread.ReraiserThread( | 246 [reraiser_thread.ReraiserThread( |
| 242 _RunTestsFromQueue, | 247 _RunTestsFromQueue, |
| 243 [r, test_collection_factory(), results, watcher, num_retries, | 248 [r, tc, results, watcher, num_retries, tag_results_with_device], |
| 244 tag_results_with_device], | |
| 245 name=r.device[-4:]) | 249 name=r.device[-4:]) |
| 246 for r in runners]) | 250 for r, tc in zip(runners, test_collections)]) |
| 247 run_results = base_test_result.TestRunResults() | 251 run_results = base_test_result.TestRunResults() |
| 248 workers.StartAll() | 252 workers.StartAll() |
| 249 | 253 |
| 250 # Catch DeviceUnresponsiveErrors and set a warning exit code | 254 # Catch DeviceUnresponsiveErrors and set a warning exit code |
| 251 try: | 255 try: |
| 252 workers.JoinAll(watcher) | 256 workers.JoinAll(watcher) |
| 253 except android_commands.errors.DeviceUnresponsiveError as e: | 257 except android_commands.errors.DeviceUnresponsiveError as e: |
| 254 logging.error(e) | 258 logging.error(e) |
| 255 exit_code = constants.WARNING_EXIT_CODE | 259 exit_code = constants.WARNING_EXIT_CODE |
| 256 | 260 |
| 261 assert all([len(tc) == 0 for tc in test_collections]), ( |
| 262 'Some tests were not run, all devices are likely offline (ran %d tests)' % |
| 263 len(run_results.GetAll())) |
| 264 |
| 257 for r in results: | 265 for r in results: |
| 258 run_results.AddTestRunResults(r) | 266 run_results.AddTestRunResults(r) |
| 259 if not run_results.DidRunPass(): | 267 if not run_results.DidRunPass(): |
| 260 exit_code = constants.ERROR_EXIT_CODE | 268 exit_code = constants.ERROR_EXIT_CODE |
| 261 return (run_results, exit_code) | 269 return (run_results, exit_code) |
| 262 | 270 |
| 263 | 271 |
| 264 def _CreateRunners(runner_factory, devices, timeout=None): | 272 def _CreateRunners(runner_factory, devices, timeout=None): |
| 265 """Creates a test runner for each device and calls SetUp() in parallel. | 273 """Creates a test runner for each device and calls SetUp() in parallel. |
| 266 | 274 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 logging.info('Will run %d tests (%s): %s', len(tests), log_string, str(tests)) | 355 logging.info('Will run %d tests (%s): %s', len(tests), log_string, str(tests)) |
| 348 runners = _CreateRunners(runner_factory, devices, setup_timeout) | 356 runners = _CreateRunners(runner_factory, devices, setup_timeout) |
| 349 try: | 357 try: |
| 350 return _RunAllTests(runners, test_collection_factory, | 358 return _RunAllTests(runners, test_collection_factory, |
| 351 num_retries, test_timeout, tag_results_with_device) | 359 num_retries, test_timeout, tag_results_with_device) |
| 352 finally: | 360 finally: |
| 353 try: | 361 try: |
| 354 _TearDownRunners(runners, setup_timeout) | 362 _TearDownRunners(runners, setup_timeout) |
| 355 except android_commands.errors.DeviceUnresponsiveError as e: | 363 except android_commands.errors.DeviceUnresponsiveError as e: |
| 356 logging.warning('Device unresponsive during TearDown: [%s]', e) | 364 logging.warning('Device unresponsive during TearDown: [%s]', e) |
| OLD | NEW |