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 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
325 """ | 325 """ |
326 threads = reraiser_thread.ReraiserThreadGroup( | 326 threads = reraiser_thread.ReraiserThreadGroup( |
327 [reraiser_thread.ReraiserThread(r.TearDown, name=r.device_serial[-4:]) | 327 [reraiser_thread.ReraiserThread(r.TearDown, name=r.device_serial[-4:]) |
328 for r in runners]) | 328 for r in runners]) |
329 threads.StartAll() | 329 threads.StartAll() |
330 threads.JoinAll(watchdog_timer.WatchdogTimer(timeout)) | 330 threads.JoinAll(watchdog_timer.WatchdogTimer(timeout)) |
331 | 331 |
332 | 332 |
333 def RunTests(tests, runner_factory, devices, shard=True, | 333 def RunTests(tests, runner_factory, devices, shard=True, |
334 test_timeout=DEFAULT_TIMEOUT, setup_timeout=DEFAULT_TIMEOUT, | 334 test_timeout=DEFAULT_TIMEOUT, setup_timeout=DEFAULT_TIMEOUT, |
335 num_retries=2): | 335 num_retries=2, max_per_run=256): |
336 """Run all tests on attached devices, retrying tests that don't pass. | 336 """Run all tests on attached devices, retrying tests that don't pass. |
337 | 337 |
338 Args: | 338 Args: |
339 tests: List of tests to run. | 339 tests: List of tests to run. |
340 runner_factory: Callable that takes a device and index and returns a | 340 runner_factory: Callable that takes a device and index and returns a |
341 TestRunner object. | 341 TestRunner object. |
342 devices: List of attached devices. | 342 devices: List of attached devices. |
343 shard: True if we should shard, False if we should replicate tests. | 343 shard: True if we should shard, False if we should replicate tests. |
344 - Sharding tests will distribute tests across all test runners through a | 344 - Sharding tests will distribute tests across all test runners through a |
345 shared test collection. | 345 shared test collection. |
346 - Replicating tests will copy all tests to each test runner through a | 346 - Replicating tests will copy all tests to each test runner through a |
347 unique test collection for each test runner. | 347 unique test collection for each test runner. |
348 test_timeout: Watchdog timeout in seconds for running tests. | 348 test_timeout: Watchdog timeout in seconds for running tests. |
349 setup_timeout: Watchdog timeout in seconds for creating and cleaning up | 349 setup_timeout: Watchdog timeout in seconds for creating and cleaning up |
350 test runners. | 350 test runners. |
351 num_retries: Number of retries for a test. | 351 num_retries: Number of retries for a test. |
352 max_per_run: Maxium number of tests to run in any group. | |
Sami
2014/08/08 12:51:23
s/Maxium/Maximum/
| |
352 | 353 |
353 Returns: | 354 Returns: |
354 A tuple of (base_test_result.TestRunResults object, exit code). | 355 A tuple of (base_test_result.TestRunResults object, exit code). |
355 """ | 356 """ |
356 if not tests: | 357 if not tests: |
357 logging.critical('No tests to run.') | 358 logging.critical('No tests to run.') |
358 return (base_test_result.TestRunResults(), constants.ERROR_EXIT_CODE) | 359 return (base_test_result.TestRunResults(), constants.ERROR_EXIT_CODE) |
359 | 360 |
361 # Rearrange the tests so that no group contains more than max_per_run tests. | |
362 tests_expanded = [] | |
363 for test_group in tests: | |
364 test_split = test_group.split(':') | |
365 for i in range(0, len(test_split), max_per_run): | |
366 tests_expanded.append(':'.join(test_split[i:i+max_per_run])) | |
367 | |
360 if shard: | 368 if shard: |
361 # Generate a shared _TestCollection object for all test runners, so they | 369 # Generate a shared _TestCollection object for all test runners, so they |
362 # draw from a common pool of tests. | 370 # draw from a common pool of tests. |
363 shared_test_collection = _TestCollection([_Test(t) for t in tests]) | 371 shared_test_collection = _TestCollection([_Test(t) for t in tests_expanded]) |
364 test_collection_factory = lambda: shared_test_collection | 372 test_collection_factory = lambda: shared_test_collection |
365 tag_results_with_device = False | 373 tag_results_with_device = False |
366 log_string = 'sharded across devices' | 374 log_string = 'sharded across devices' |
367 else: | 375 else: |
368 # Generate a unique _TestCollection object for each test runner, but use | 376 # Generate a unique _TestCollection object for each test runner, but use |
369 # the same set of tests. | 377 # the same set of tests. |
370 test_collection_factory = lambda: _TestCollection([_Test(t) for t in tests]) | 378 test_collection_factory = lambda: _TestCollection( |
379 [_Test(t) for t in tests_expanded]) | |
371 tag_results_with_device = True | 380 tag_results_with_device = True |
372 log_string = 'replicated on each device' | 381 log_string = 'replicated on each device' |
373 | 382 |
374 logging.info('Will run %d tests (%s): %s', len(tests), log_string, str(tests)) | 383 logging.info('Will run %d tests (%s): %s', |
384 len(tests_expanded), log_string, str(tests_expanded)) | |
375 runners = _CreateRunners(runner_factory, devices, setup_timeout) | 385 runners = _CreateRunners(runner_factory, devices, setup_timeout) |
376 try: | 386 try: |
377 return _RunAllTests(runners, test_collection_factory, | 387 return _RunAllTests(runners, test_collection_factory, |
378 num_retries, test_timeout, tag_results_with_device) | 388 num_retries, test_timeout, tag_results_with_device) |
379 finally: | 389 finally: |
380 try: | 390 try: |
381 _TearDownRunners(runners, setup_timeout) | 391 _TearDownRunners(runners, setup_timeout) |
382 except (device_errors.DeviceUnreachableError, | 392 except (device_errors.DeviceUnreachableError, |
383 # TODO(jbudorick) Remove this once the underlying implementations | 393 # TODO(jbudorick) Remove this once the underlying implementations |
384 # for the above are switched or wrapped. | 394 # for the above are switched or wrapped. |
385 android_commands.errors.DeviceUnresponsiveError) as e: | 395 android_commands.errors.DeviceUnresponsiveError) as e: |
386 logging.warning('Device unresponsive during TearDown: [%s]', e) | 396 logging.warning('Device unresponsive during TearDown: [%s]', e) |
387 except Exception as e: | 397 except Exception as e: |
388 logging.error('Unexpected exception caught during TearDown: %s' % str(e)) | 398 logging.error('Unexpected exception caught during TearDown: %s' % str(e)) |
OLD | NEW |