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 base_test_result |
11 from pylib.base import shard | 12 from pylib.base import shard |
12 from pylib.base import test_result | |
13 from pylib.uiautomator import test_package as uiautomator_package | 13 from pylib.uiautomator import test_package as uiautomator_package |
14 | 14 |
15 import test_package | 15 import test_package |
16 import test_runner | 16 import test_runner |
17 | 17 |
18 | 18 |
19 def Dispatch(options): | 19 def Dispatch(options): |
20 """Dispatches instrumentation tests onto connected device(s). | 20 """Dispatches instrumentation tests onto connected device(s). |
21 | 21 |
22 If possible, this method will attempt to shard the tests to | 22 If possible, this method will attempt to shard the tests to |
23 all connected devices. Otherwise, dispatch and run tests on one device. | 23 all connected devices. Otherwise, dispatch and run tests on one device. |
24 | 24 |
25 Args: | 25 Args: |
26 options: Command line options. | 26 options: Command line options. |
27 | 27 |
28 Returns: | 28 Returns: |
29 A TestResults object holding the results of the Java tests. | 29 A TestRunResults object holding the results of the Java tests. |
30 | 30 |
31 Raises: | 31 Raises: |
32 Exception: when there are no attached devices. | 32 Exception: when there are no attached devices. |
33 """ | 33 """ |
34 is_uiautomator_test = False | 34 is_uiautomator_test = False |
35 if hasattr(options, 'uiautomator_jar'): | 35 if hasattr(options, 'uiautomator_jar'): |
36 test_pkg = uiautomator_package.TestPackage( | 36 test_pkg = uiautomator_package.TestPackage( |
37 options.uiautomator_jar, options.uiautomator_info_jar) | 37 options.uiautomator_jar, options.uiautomator_info_jar) |
38 is_uiautomator_test = True | 38 is_uiautomator_test = True |
39 else: | 39 else: |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 if options.test_filter: | 73 if options.test_filter: |
74 # |available_tests| are in adb instrument format: package.path.class#test. | 74 # |available_tests| are in adb instrument format: package.path.class#test. |
75 filter_without_hash = options.test_filter.replace('#', '.') | 75 filter_without_hash = options.test_filter.replace('#', '.') |
76 tests = [t for t in available_tests | 76 tests = [t for t in available_tests |
77 if filter_without_hash in t.replace('#', '.')] | 77 if filter_without_hash in t.replace('#', '.')] |
78 else: | 78 else: |
79 tests = available_tests | 79 tests = available_tests |
80 | 80 |
81 if not tests: | 81 if not tests: |
82 logging.warning('No instrumentation tests to run with current args.') | 82 logging.warning('No instrumentation tests to run with current args.') |
83 return test_result.TestResults() | 83 return base_test_result.TestRunResults() |
84 | 84 |
85 tests *= options.number_of_runs | 85 tests *= options.number_of_runs |
86 | 86 |
87 attached_devices = android_commands.GetAttachedDevices() | 87 attached_devices = android_commands.GetAttachedDevices() |
88 | 88 |
89 if not attached_devices: | 89 if not attached_devices: |
90 raise Exception('There are no devices online.') | 90 raise Exception('There are no devices online.') |
91 if options.device: | 91 if options.device: |
92 attached_devices = [options.device] | 92 attached_devices = [options.device] |
93 | 93 |
94 logging.info('Will run: %s', str(tests)) | 94 logging.info('Will run: %s', str(tests)) |
95 | 95 |
96 if len(attached_devices) > 1 and (coverage or options.wait_for_debugger): | 96 if len(attached_devices) > 1 and (coverage or options.wait_for_debugger): |
97 logging.warning('Coverage / debugger can not be sharded, ' | 97 logging.warning('Coverage / debugger can not be sharded, ' |
98 'using first available device') | 98 'using first available device') |
99 attached_devices = attached_devices[:1] | 99 attached_devices = attached_devices[:1] |
100 | 100 |
101 def TestRunnerFactory(device, shard_index): | 101 def TestRunnerFactory(device, shard_index): |
102 return test_runner.TestRunner( | 102 return test_runner.TestRunner( |
103 options, device, shard_index, False, test_pkg, [], is_uiautomator_test) | 103 options, device, shard_index, False, test_pkg, [], is_uiautomator_test) |
104 | 104 |
105 return shard.ShardAndRunTests(TestRunnerFactory, attached_devices, tests, | 105 return shard.ShardAndRunTests(TestRunnerFactory, attached_devices, tests, |
106 options.build_type) | 106 options.build_type) |
OLD | NEW |