OLD | NEW |
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 the instrumentation tests.""" | 5 """Dispatches the instrumentation tests.""" |
6 | 6 |
7 import logging | 7 import logging |
8 import os | 8 import os |
9 | 9 |
10 from pylib import android_commands | 10 from pylib import android_commands |
| 11 from pylib.base import shard |
11 from pylib.base import test_result | 12 from pylib.base import test_result |
12 | 13 |
13 import apk_info | 14 import apk_info |
14 import test_sharder | 15 import test_runner |
15 | 16 |
16 | 17 |
17 def Dispatch(options, apks): | 18 def Dispatch(options, apks): |
18 """Dispatches instrumentation tests onto connected device(s). | 19 """Dispatches instrumentation tests onto connected device(s). |
19 | 20 |
20 If possible, this method will attempt to shard the tests to | 21 If possible, this method will attempt to shard the tests to |
21 all connected devices. Otherwise, dispatch and run tests on one device. | 22 all connected devices. Otherwise, dispatch and run tests on one device. |
22 | 23 |
23 Args: | 24 Args: |
24 options: Command line options. | 25 options: Command line options. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 tests = [] | 65 tests = [] |
65 if options.test_filter: | 66 if options.test_filter: |
66 # |available_tests| are in adb instrument format: package.path.class#test. | 67 # |available_tests| are in adb instrument format: package.path.class#test. |
67 filter_without_hash = options.test_filter.replace('#', '.') | 68 filter_without_hash = options.test_filter.replace('#', '.') |
68 tests = [t for t in available_tests | 69 tests = [t for t in available_tests |
69 if filter_without_hash in t.replace('#', '.')] | 70 if filter_without_hash in t.replace('#', '.')] |
70 else: | 71 else: |
71 tests = available_tests | 72 tests = available_tests |
72 | 73 |
73 if not tests: | 74 if not tests: |
74 logging.warning('No Java tests to run with current args.') | 75 logging.warning('No instrumentation tests to run with current args.') |
75 return test_result.TestResults() | 76 return test_result.TestResults() |
76 | 77 |
77 tests *= options.number_of_runs | 78 tests *= options.number_of_runs |
78 | 79 |
79 attached_devices = android_commands.GetAttachedDevices() | 80 attached_devices = android_commands.GetAttachedDevices() |
80 test_results = test_result.TestResults() | |
81 | 81 |
82 if not attached_devices: | 82 if not attached_devices: |
83 raise Exception('You have no devices attached or visible!') | 83 raise Exception('There are no devices online.') |
84 if options.device: | 84 if options.device: |
85 attached_devices = [options.device] | 85 attached_devices = [options.device] |
86 | 86 |
87 logging.info('Will run: %s', str(tests)) | 87 logging.info('Will run: %s', str(tests)) |
88 | 88 |
89 if len(attached_devices) > 1 and (coverage or options.wait_for_debugger): | 89 if len(attached_devices) > 1 and (coverage or options.wait_for_debugger): |
90 logging.warning('Coverage / debugger can not be sharded, ' | 90 logging.warning('Coverage / debugger can not be sharded, ' |
91 'using first available device') | 91 'using first available device') |
92 attached_devices = attached_devices[:1] | 92 attached_devices = attached_devices[:1] |
93 sharder = test_sharder.TestSharder(attached_devices, options, tests, apks) | 93 |
94 test_results = sharder.RunShardedTests() | 94 def TestRunnerFactory(device, shard_index): |
95 return test_results | 95 return test_runner.TestRunner(options, device, shard_index, False, apks, []) |
| 96 |
| 97 return shard.ShardAndRunTests(TestRunnerFactory, attached_devices, tests, |
| 98 options.build_type) |
OLD | NEW |