Chromium Code Reviews| Index: build/android/pylib/dispatch.py |
| diff --git a/build/android/pylib/dispatch.py b/build/android/pylib/dispatch.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2a9879ab4d7a1ce26e986b9c990b0aa100b7b1da |
| --- /dev/null |
| +++ b/build/android/pylib/dispatch.py |
| @@ -0,0 +1,65 @@ |
| +# Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +"""Common dispatcher for all test types.""" |
|
frankf
2013/07/12 22:28:28
Let's just fold this into test_runner.py
gkanwar
2013/07/12 22:53:34
Some of the downstream scripts will be using this
|
| + |
| +import logging |
| + |
| +from pylib import android_commands |
| +from pylib.base import shard |
| + |
| + |
| +VALID_SHARDING_OPTIONS = ['shard', 'replicate'] |
| + |
| + |
| +def Dispatch(options, tests, test_runner_factory, distribution='shard', |
| + setup_timeout=None): |
| + """Dispatches a particular set of tests. |
| + |
| + This is a common function used by all test dispatchers. |
| + |
| + Args: |
| + options: command line options. |
| + tests: a list of tests. |
| + test_runner_factory: a function which accepts (device, shard_index) and |
| + returns the test runner that the sharder uses to run tests. |
| + distribution: 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 'shard' or 'replicate' |
| + setup_timeout: timeout for setup. |
| + |
| + Returns: |
| + A tuple of (base_test_result.TestRunResults object, exit code) |
| + """ |
| + |
| + # Validation |
| + if sharding not in VALID_SHARDING_OPTIONS: |
| + raise ValueError('Invalid value for sharding. Options are: %s' |
| + % ', '.join(VALID_SHARDING_OPTIONS)) |
| + |
| + # Device setup |
| + attached_devices = [] |
| + |
| + attached_devices = android_commands.GetAttachedDevices() |
| + if options.test_device: |
| + assert options.test_device in attached_devices |
| + attached_devices = [options.test_device] |
| + |
| + options.ensure_value('wait_for_debugger', False) |
| + if len(attached_devices) > 1 and options.wait_for_debugger: |
| + logging.warning('Debugger can not be sharded, using first available device') |
| + attached_devices = attached_devices[:1] |
| + |
| + if distribution == 'shard': |
| + test_results, exit_code = shard.ShardAndRunTests( |
| + test_runner_factory, attached_devices, tests, options.build_type, |
| + test_timeout=None, num_retries=options.num_retries, |
| + setup_timeout=(setup_timeout or shard.DEFAULT_TIMEOUT)) |
| + else: # Replicate |
| + test_results, exit_code = shard.ReplicateAndRunTests( |
| + test_runner_factory, attached_devices, tests, options.build_type, |
| + test_timeout=None, num_retries=options.num_retries, |
| + setup_timeout=(setup_timeout or shard.DEFAULT_TIMEOUT)) |
| + |
| + return (test_results, exit_code) |