OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 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 """Generates test runner factory and tests for instrumentation tests.""" | 5 """Generates test runner factory and tests for instrumentation tests.""" |
6 | 6 |
7 import logging | 7 import logging |
8 import os | 8 import os |
9 | 9 |
| 10 from pylib import constants |
| 11 from pylib import valgrind_tools |
| 12 |
| 13 from pylib.base import base_setup |
| 14 from pylib.device import device_utils |
10 from pylib.instrumentation import test_package | 15 from pylib.instrumentation import test_package |
11 from pylib.instrumentation import test_runner | 16 from pylib.instrumentation import test_runner |
12 | 17 |
| 18 DEVICE_DATA_DIR = 'chrome/test/data' |
13 | 19 |
14 def Setup(test_options): | 20 ISOLATE_FILE_PATHS = { |
| 21 'AndroidWebViewTest': 'android_webview/android_webview_test_apk.isolate', |
| 22 'ChromeShellTest': 'chrome/chrome_shell_test_apk.isolate', |
| 23 'ContentShellTest': 'content/content_shell_test_apk.isolate', |
| 24 } |
| 25 |
| 26 DEPS_EXCLUSION_LIST = [] |
| 27 |
| 28 # TODO(mikecase): Remove this function and the constant DEVICE_DATA_DIR |
| 29 # once all data deps are pushed to the same location on the device. |
| 30 def _PushExtraSuiteDataDeps(device, test_apk): |
| 31 """Pushes some extra data files/dirs needed by some test suite. |
| 32 |
| 33 Args: |
| 34 test_apk: The test suite basename for which to return file paths. |
| 35 """ |
| 36 if test_apk in ['ChromeTest', 'ContentShellTest']: |
| 37 test_files = 'net/data/ssl/certificates' |
| 38 host_device_file_tuple = [ |
| 39 (os.path.join(constants.DIR_SOURCE_ROOT, test_files), |
| 40 os.path.join(device.GetExternalStoragePath(), test_files))] |
| 41 device.PushChangedFiles(host_device_file_tuple) |
| 42 |
| 43 |
| 44 # TODO(mikecase): Remove this function once everything uses |
| 45 # base_setup.PushDataDeps to push data deps to the device. |
| 46 def _PushDataDeps(device, test_options): |
| 47 valgrind_tools.PushFilesForTool(test_options.tool, device) |
| 48 |
| 49 host_device_file_tuples = [] |
| 50 for dest_host_pair in test_options.test_data: |
| 51 dst_src = dest_host_pair.split(':', 1) |
| 52 dst_layer = dst_src[0] |
| 53 host_src = dst_src[1] |
| 54 host_test_files_path = os.path.join(constants.DIR_SOURCE_ROOT, host_src) |
| 55 if os.path.exists(host_test_files_path): |
| 56 host_device_file_tuples += [( |
| 57 host_test_files_path, |
| 58 '%s/%s/%s' % ( |
| 59 device.GetExternalStoragePath(), |
| 60 DEVICE_DATA_DIR, |
| 61 dst_layer))] |
| 62 if host_device_file_tuples: |
| 63 device.PushChangedFiles(host_device_file_tuples) |
| 64 |
| 65 |
| 66 def Setup(test_options, devices): |
15 """Create and return the test runner factory and tests. | 67 """Create and return the test runner factory and tests. |
16 | 68 |
17 Args: | 69 Args: |
18 test_options: An InstrumentationOptions object. | 70 test_options: An InstrumentationOptions object. |
19 | 71 |
20 Returns: | 72 Returns: |
21 A tuple of (TestRunnerFactory, tests). | 73 A tuple of (TestRunnerFactory, tests). |
22 """ | 74 """ |
23 if (test_options.coverage_dir and not | 75 if (test_options.coverage_dir and not |
24 os.path.exists(test_options.coverage_dir)): | 76 os.path.exists(test_options.coverage_dir)): |
25 os.makedirs(test_options.coverage_dir) | 77 os.makedirs(test_options.coverage_dir) |
26 | 78 |
27 test_pkg = test_package.TestPackage(test_options.test_apk_path, | 79 test_pkg = test_package.TestPackage(test_options.test_apk_path, |
28 test_options.test_apk_jar_path, | 80 test_options.test_apk_jar_path, |
29 test_options.test_support_apk_path) | 81 test_options.test_support_apk_path) |
30 tests = test_pkg.GetAllMatchingTests( | 82 tests = test_pkg.GetAllMatchingTests( |
31 test_options.annotations, | 83 test_options.annotations, |
32 test_options.exclude_annotations, | 84 test_options.exclude_annotations, |
33 test_options.test_filter) | 85 test_options.test_filter) |
34 if not tests: | 86 if not tests: |
35 logging.error('No instrumentation tests to run with current args.') | 87 logging.error('No instrumentation tests to run with current args.') |
36 | 88 |
| 89 if test_options.test_data: |
| 90 device_utils.DeviceUtils.parallel(devices).pMap( |
| 91 _PushDataDeps, test_options) |
| 92 else: |
| 93 base_setup.GenerateDepsDirUsingIsolate(test_options.test_apk, |
| 94 test_options.isolate_file_path, |
| 95 ISOLATE_FILE_PATHS, |
| 96 DEPS_EXCLUSION_LIST) |
| 97 def push_data_deps_to_device_dir(device): |
| 98 device_dir = os.path.join(device.GetExternalStoragePath(), |
| 99 DEVICE_DATA_DIR) |
| 100 base_setup.PushDataDeps(device, device_dir, test_options) |
| 101 device_utils.DeviceUtils.parallel(devices).pMap( |
| 102 push_data_deps_to_device_dir) |
| 103 |
| 104 device_utils.DeviceUtils.parallel(devices).pMap( |
| 105 _PushExtraSuiteDataDeps, test_options.test_apk) |
| 106 |
37 def TestRunnerFactory(device, shard_index): | 107 def TestRunnerFactory(device, shard_index): |
38 return test_runner.TestRunner(test_options, device, shard_index, | 108 return test_runner.TestRunner(test_options, device, shard_index, |
39 test_pkg) | 109 test_pkg) |
40 | 110 |
41 return (TestRunnerFactory, tests) | 111 return (TestRunnerFactory, tests) |
OLD | NEW |