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..03f15121b911c7166f00f84413cc7fc313ca0a3f |
--- /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.""" |
+ |
+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 distribution 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( |
+ tests, test_runner_factory, attached_devices, 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( |
+ tests, test_runner_factory, attached_devices, options.build_type, |
+ test_timeout=None, num_retries=options.num_retries, |
+ setup_timeout=(setup_timeout or shard.DEFAULT_TIMEOUT)) |
+ |
+ return (test_results, exit_code) |