OLD | NEW |
---|---|
(Empty) | |
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 | |
5 """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
| |
6 | |
7 import logging | |
8 | |
9 from pylib import android_commands | |
10 from pylib.base import shard | |
11 | |
12 | |
13 VALID_SHARDING_OPTIONS = ['shard', 'replicate'] | |
14 | |
15 | |
16 def Dispatch(options, tests, test_runner_factory, distribution='shard', | |
17 setup_timeout=None): | |
18 """Dispatches a particular set of tests. | |
19 | |
20 This is a common function used by all test dispatchers. | |
21 | |
22 Args: | |
23 options: command line options. | |
24 tests: a list of tests. | |
25 test_runner_factory: a function which accepts (device, shard_index) and | |
26 returns the test runner that the sharder uses to run tests. | |
27 distribution: a string to indicate whether we should distribute all tests as | |
28 a common pool to draw from, or duplicate all tests onto every test | |
29 runner. Must be either 'shard' or 'replicate' | |
30 setup_timeout: timeout for setup. | |
31 | |
32 Returns: | |
33 A tuple of (base_test_result.TestRunResults object, exit code) | |
34 """ | |
35 | |
36 # Validation | |
37 if sharding not in VALID_SHARDING_OPTIONS: | |
38 raise ValueError('Invalid value for sharding. Options are: %s' | |
39 % ', '.join(VALID_SHARDING_OPTIONS)) | |
40 | |
41 # Device setup | |
42 attached_devices = [] | |
43 | |
44 attached_devices = android_commands.GetAttachedDevices() | |
45 if options.test_device: | |
46 assert options.test_device in attached_devices | |
47 attached_devices = [options.test_device] | |
48 | |
49 options.ensure_value('wait_for_debugger', False) | |
50 if len(attached_devices) > 1 and options.wait_for_debugger: | |
51 logging.warning('Debugger can not be sharded, using first available device') | |
52 attached_devices = attached_devices[:1] | |
53 | |
54 if distribution == 'shard': | |
55 test_results, exit_code = shard.ShardAndRunTests( | |
56 test_runner_factory, attached_devices, tests, options.build_type, | |
57 test_timeout=None, num_retries=options.num_retries, | |
58 setup_timeout=(setup_timeout or shard.DEFAULT_TIMEOUT)) | |
59 else: # Replicate | |
60 test_results, exit_code = shard.ReplicateAndRunTests( | |
61 test_runner_factory, attached_devices, tests, options.build_type, | |
62 test_timeout=None, num_retries=options.num_retries, | |
63 setup_timeout=(setup_timeout or shard.DEFAULT_TIMEOUT)) | |
64 | |
65 return (test_results, exit_code) | |
OLD | NEW |