Chromium Code Reviews| 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.device import device_utils | |
| 10 from pylib.instrumentation import test_package | 14 from pylib.instrumentation import test_package |
| 11 from pylib.instrumentation import test_runner | 15 from pylib.instrumentation import test_runner |
| 16 from pylib.utils import isolator | |
| 17 | |
| 18 _DEVICE_DATA_DIR = 'chrome/test/data' | |
| 19 | |
| 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 'MojoTest': 'mojo/mojo_test_apk.isolate', | |
| 25 } | |
| 26 | |
| 27 def _GenerateDepsDirUsingIsolate(suite_name, isolate_file_path=None): | |
| 28 """Generate the dependency dir for the test suite using isolate. | |
| 29 | |
| 30 Args: | |
| 31 suite_name: Name of the test suite (e.g. base_unittests). | |
| 32 isolate_file_path: .isolate file path to use. If there is a default .isolate | |
| 33 file path for the suite_name, this will override it. | |
| 34 """ | |
| 35 if isolate_file_path: | |
| 36 if os.path.isabs(isolate_file_path): | |
| 37 isolate_abs_path = isolate_file_path | |
| 38 else: | |
| 39 isolate_abs_path = os.path.join(constants.DIR_SOURCE_ROOT, | |
| 40 isolate_file_path) | |
| 41 else: | |
| 42 isolate_rel_path = _ISOLATE_FILE_PATHS.get(suite_name) | |
| 43 if not isolate_rel_path: | |
| 44 logging.info('Did not find an isolate file for the test suite.') | |
| 45 return | |
| 46 isolate_abs_path = os.path.join(constants.DIR_SOURCE_ROOT, isolate_rel_path) | |
| 47 | |
| 48 isolated_abs_path = os.path.join( | |
| 49 constants.GetOutDirectory(), '%s.isolated' % suite_name) | |
| 50 assert os.path.exists(isolate_abs_path), 'Cannot find %s' % isolate_abs_path | |
| 51 | |
| 52 i = isolator.Isolator(constants.ISOLATE_DEPS_DIR) | |
| 53 i.Clear() | |
| 54 i.Remap(isolate_abs_path, isolated_abs_path) | |
| 55 # We're relying on the fact that timestamps are preserved | |
| 56 # by the remap command (hardlinked). Otherwise, all the data | |
| 57 # will be pushed to the device once we move to using time diff | |
| 58 # instead of md5sum. Perform a sanity check here. | |
| 59 i.VerifyHardlinks() | |
| 60 i.MoveOutputDeps() | |
| 12 | 61 |
| 13 | 62 |
|
mikecase (-- gone --)
2014/11/01 06:11:06
Wondering if you have a good solution to this. I w
| |
| 14 def Setup(test_options): | 63 def _PushExtraSuiteDataDeps(device, test_apk): |
| 64 """Pushes some extra data files/dirs needed by some test suite. | |
| 65 | |
| 66 Args: | |
| 67 test_apk: The test suite basename for which to return file paths. | |
| 68 """ | |
| 69 if test_apk in ['ChromeTest', 'ContentShellTest']: | |
| 70 test_files = 'net/data/ssl/certificates' | |
| 71 host_device_file_tuple = [ | |
| 72 (os.path.join(constants.DIR_SOURCE_ROOT, test_files), | |
| 73 os.path.join(device.GetExternalStoragePath(), test_files))] | |
| 74 device.PushChangedFiles(host_device_file_tuple) | |
| 75 | |
| 76 | |
| 77 def _PushDataDepsWithIsolate(device, test_options): | |
| 78 valgrind_tools.PushFilesForTool(test_options.tool, device) | |
| 79 _PushExtraSuiteDataDeps(device, test_options.test_apk) | |
| 80 | |
| 81 if os.path.exists(constants.ISOLATE_DEPS_DIR): | |
| 82 device_dir = os.path.join(device.GetExternalStoragePath(), | |
| 83 _DEVICE_DATA_DIR) | |
| 84 device.PushChangedFiles([ | |
| 85 (os.path.join(constants.ISOLATE_DEPS_DIR, p), | |
| 86 os.path.join(device_dir, p)) | |
| 87 for p in os.listdir(constants.ISOLATE_DEPS_DIR)]) | |
| 88 | |
| 89 | |
| 90 # TODO(mikecase): Remove this function once everything uses | |
| 91 # PushDataDepsWithIsolate instead. | |
| 92 def _PushDataDeps(device, test_options): | |
| 93 valgrind_tools.PushFilesForTool(test_options.tool, device) | |
| 94 _PushExtraSuiteDataDeps(device, test_options.test_apk) | |
| 95 | |
| 96 host_device_file_tuples = [] | |
| 97 for dest_host_pair in test_options.test_data: | |
| 98 dst_src = dest_host_pair.split(':', 1) | |
| 99 dst_layer = dst_src[0] | |
| 100 host_src = dst_src[1] | |
| 101 host_test_files_path = os.path.join(constants.DIR_SOURCE_ROOT, host_src) | |
| 102 if os.path.exists(host_test_files_path): | |
| 103 host_device_file_tuples += [( | |
| 104 host_test_files_path, | |
| 105 '%s/%s/%s' % ( | |
| 106 device.GetExternalStoragePath(), | |
| 107 _DEVICE_DATA_DIR, | |
| 108 dst_layer))] | |
| 109 if host_device_file_tuples: | |
| 110 device.PushChangedFiles(host_device_file_tuples) | |
| 111 | |
| 112 | |
| 113 def Setup(test_options, devices): | |
| 15 """Create and return the test runner factory and tests. | 114 """Create and return the test runner factory and tests. |
| 16 | 115 |
| 17 Args: | 116 Args: |
| 18 test_options: An InstrumentationOptions object. | 117 test_options: An InstrumentationOptions object. |
| 19 | 118 |
| 20 Returns: | 119 Returns: |
| 21 A tuple of (TestRunnerFactory, tests). | 120 A tuple of (TestRunnerFactory, tests). |
| 22 """ | 121 """ |
| 23 if (test_options.coverage_dir and not | 122 if (test_options.coverage_dir and not |
| 24 os.path.exists(test_options.coverage_dir)): | 123 os.path.exists(test_options.coverage_dir)): |
| 25 os.makedirs(test_options.coverage_dir) | 124 os.makedirs(test_options.coverage_dir) |
| 26 | 125 |
| 27 test_pkg = test_package.TestPackage(test_options.test_apk_path, | 126 test_pkg = test_package.TestPackage(test_options.test_apk_path, |
| 28 test_options.test_apk_jar_path, | 127 test_options.test_apk_jar_path, |
| 29 test_options.test_support_apk_path) | 128 test_options.test_support_apk_path) |
| 30 tests = test_pkg.GetAllMatchingTests( | 129 tests = test_pkg.GetAllMatchingTests( |
| 31 test_options.annotations, | 130 test_options.annotations, |
| 32 test_options.exclude_annotations, | 131 test_options.exclude_annotations, |
| 33 test_options.test_filter) | 132 test_options.test_filter) |
| 34 if not tests: | 133 if not tests: |
| 35 logging.error('No instrumentation tests to run with current args.') | 134 logging.error('No instrumentation tests to run with current args.') |
| 36 | 135 |
| 136 if test_options.test_data: | |
| 137 device_utils.DeviceUtils.parallel(devices).pMap( | |
| 138 _PushDataDeps, test_options) | |
| 139 else: | |
| 140 _GenerateDepsDirUsingIsolate(test_options.test_apk, | |
| 141 test_options.isolate_file_path) | |
| 142 device_utils.DeviceUtils.parallel(devices).pMap( | |
| 143 _PushDataDepsWithIsolate, test_options) | |
| 144 | |
| 37 def TestRunnerFactory(device, shard_index): | 145 def TestRunnerFactory(device, shard_index): |
| 38 return test_runner.TestRunner(test_options, device, shard_index, | 146 return test_runner.TestRunner(test_options, device, shard_index, |
| 39 test_pkg) | 147 test_pkg) |
| 40 | 148 |
| 41 return (TestRunnerFactory, tests) | 149 return (TestRunnerFactory, tests) |
| OLD | NEW |