Chromium Code Reviews| Index: build/android/pylib/base/shard.py |
| diff --git a/build/android/pylib/base/shard.py b/build/android/pylib/base/shard.py |
| index 8c429f7d3d01a9df148d25089260e9f085f50724..c1a1842ad872c8332e4e63ce40479cb5a8676744 100644 |
| --- a/build/android/pylib/base/shard.py |
| +++ b/build/android/pylib/base/shard.py |
| @@ -17,6 +17,7 @@ import base_test_result |
| DEFAULT_TIMEOUT = 7 * 60 # seven minutes |
| +VALID_SHARDING_OPTIONS = ['distribute', 'duplicate'] |
| class _ThreadSafeCounter(object): |
| @@ -184,7 +185,7 @@ def _SetUp(runner_factory, device, out_runners, threadsafe_counter): |
| logging.warning('Failed to create shard for %s: [%s]', device, e) |
| -def _RunAllTests(runners, tests, num_retries, timeout=None): |
| +def _RunAllTests(runners, tests, sharding, num_retries, timeout=None): |
| """Run all tests using the given TestRunners. |
| Args: |
| @@ -192,20 +193,33 @@ def _RunAllTests(runners, tests, num_retries, timeout=None): |
| tests: a list of Tests to run using the given TestRunners. |
| num_retries: number of retries for a test. |
| timeout: watchdog timeout in seconds, defaults to the default timeout. |
| + sharding: a string to indicate whether we should distribute all tests as a |
| + common pool to draw from, or duplicate all tests onto every test runner. |
| + Must be either 'distribute' or 'duplicate' |
| Returns: |
| A tuple of (TestRunResults object, exit code) |
| """ |
| logging.warning('Running %s tests with %s test runners.' % |
| (len(tests), len(runners))) |
| - tests_collection = _TestCollection([_Test(t) for t in tests]) |
| results = [] |
| exit_code = 0 |
| watcher = watchdog_timer.WatchdogTimer(timeout) |
| + |
| + if sharding == 'distribute': |
| + shared_test_collection = _TestCollection([_Test(t) for t in tests]) |
| + GenerateTestCollection = lambda: shared_test_collection |
| + elif sharding == 'duplicate': |
| + GenerateTestCollection = lambda: _TestCollection([_Test(t) for t in tests]) |
| + else: |
| + raise ValueError('Unknown sharding option %s. Options are: %s' |
| + % (sharding, VALID_SHARDING_OPTIONS)) |
| + |
| + # Use a lambda to get the test collection for each runner for cleanliness |
| workers = reraiser_thread.ReraiserThreadGroup( |
| [reraiser_thread.ReraiserThread( |
| _RunTestsFromQueue, |
| - [r, tests_collection, results, watcher, num_retries], |
| + [r, GenerateTestCollection(), results, watcher, num_retries], |
| name=r.device[-4:]) |
| for r in runners]) |
| run_results = base_test_result.TestRunResults() |
| @@ -270,7 +284,8 @@ def _TearDownRunners(runners, timeout=None): |
| def ShardAndRunTests(runner_factory, devices, tests, build_type='Debug', |
| test_timeout=DEFAULT_TIMEOUT, |
| setup_timeout=DEFAULT_TIMEOUT, |
| - num_retries=2): |
| + num_retries=2, |
| + sharding='distribute'): |
|
craigdh
2013/07/12 18:14:15
The behavior is quite different, I think it would
gkanwar
2013/07/12 18:22:41
I was discussing this with Frank in the gdoc, and
frankf
2013/07/12 18:49:19
I still think the semantics is confusing. Sharding
gkanwar
2013/07/12 18:52:04
That sounds reasonable to me. Craig, does that sou
craigdh
2013/07/12 19:03:36
I like the method names, but test_allocator.py is
gkanwar
2013/07/12 19:22:32
We already have a 'dispatch.py' under pylib now (t
|
| """Run all tests on attached devices, retrying tests that don't pass. |
| Args: |
| @@ -284,10 +299,14 @@ def ShardAndRunTests(runner_factory, devices, tests, build_type='Debug', |
| setup_timeout: watchdog timeout in seconds for creating and cleaning up |
| test runners, defaults to the default timeout. |
| num_retries: number of retries for a test. |
| + sharding: a string to indicate whether we should distribute all tests as a |
| + common pool to draw from, or duplicate all tests onto every test runner. |
| + Must be either 'distribute' or 'duplicate' |
| Returns: |
| A tuple of (base_test_result.TestRunResults object, exit code). |
| """ |
| + |
|
craigdh
2013/07/12 18:14:15
remove this new blank line
gkanwar
2013/07/12 18:22:41
Will do.
|
| if not tests: |
| logging.error('No tests to run.') |
| return (base_test_result.TestRunResults(), constants.ERROR_EXIT_CODE) |
| @@ -296,7 +315,7 @@ def ShardAndRunTests(runner_factory, devices, tests, build_type='Debug', |
| forwarder.Forwarder.KillHost(build_type) |
| runners = _CreateRunners(runner_factory, devices, setup_timeout) |
| try: |
| - return _RunAllTests(runners, tests, num_retries, test_timeout) |
| + return _RunAllTests(runners, tests, sharding, num_retries, test_timeout) |
| finally: |
| try: |
| _TearDownRunners(runners, setup_timeout) |