Chromium Code Reviews| Index: build/android/pylib/instrumentation/setup.py |
| diff --git a/build/android/pylib/instrumentation/setup.py b/build/android/pylib/instrumentation/setup.py |
| index 57286e2f793dd644ecc9c9b57353f1a725fb049d..dad1f5d6d46389dad403e928ca36061bb4ddb46c 100644 |
| --- a/build/android/pylib/instrumentation/setup.py |
| +++ b/build/android/pylib/instrumentation/setup.py |
| @@ -7,11 +7,110 @@ |
| import logging |
| import os |
| +from pylib import constants |
| +from pylib import valgrind_tools |
| + |
| +from pylib.device import device_utils |
| from pylib.instrumentation import test_package |
| from pylib.instrumentation import test_runner |
| +from pylib.utils import isolator |
| + |
| +_DEVICE_DATA_DIR = 'chrome/test/data' |
| + |
| +_ISOLATE_FILE_PATHS = { |
| + 'AndroidWebViewTest': 'android_webview/android_webview_test_apk.isolate', |
| + 'ChromeShellTest': 'chrome/chrome_shell_test_apk.isolate', |
| + 'ContentShellTest': 'content/content_shell_test_apk.isolate', |
| + 'MojoTest': 'mojo/mojo_test_apk.isolate', |
| +} |
| +def _GenerateDepsDirUsingIsolate(suite_name, isolate_file_path=None): |
| + """Generate the dependency dir for the test suite using isolate. |
| + |
| + Args: |
| + suite_name: Name of the test suite (e.g. base_unittests). |
| + isolate_file_path: .isolate file path to use. If there is a default .isolate |
| + file path for the suite_name, this will override it. |
| + """ |
| + if isolate_file_path: |
| + if os.path.isabs(isolate_file_path): |
| + isolate_abs_path = isolate_file_path |
| + else: |
| + isolate_abs_path = os.path.join(constants.DIR_SOURCE_ROOT, |
| + isolate_file_path) |
| + else: |
| + isolate_rel_path = _ISOLATE_FILE_PATHS.get(suite_name) |
| + if not isolate_rel_path: |
| + logging.info('Did not find an isolate file for the test suite.') |
| + return |
| + isolate_abs_path = os.path.join(constants.DIR_SOURCE_ROOT, isolate_rel_path) |
| -def Setup(test_options): |
| + isolated_abs_path = os.path.join( |
| + constants.GetOutDirectory(), '%s.isolated' % suite_name) |
| + assert os.path.exists(isolate_abs_path), 'Cannot find %s' % isolate_abs_path |
| + |
| + i = isolator.Isolator(constants.ISOLATE_DEPS_DIR) |
| + i.Clear() |
| + i.Remap(isolate_abs_path, isolated_abs_path) |
| + # We're relying on the fact that timestamps are preserved |
| + # by the remap command (hardlinked). Otherwise, all the data |
| + # will be pushed to the device once we move to using time diff |
| + # instead of md5sum. Perform a sanity check here. |
| + i.VerifyHardlinks() |
| + i.MoveOutputDeps() |
| + |
| + |
|
mikecase (-- gone --)
2014/11/01 06:11:06
Wondering if you have a good solution to this. I w
|
| +def _PushExtraSuiteDataDeps(device, test_apk): |
| + """Pushes some extra data files/dirs needed by some test suite. |
| + |
| + Args: |
| + test_apk: The test suite basename for which to return file paths. |
| + """ |
| + if test_apk in ['ChromeTest', 'ContentShellTest']: |
| + test_files = 'net/data/ssl/certificates' |
| + host_device_file_tuple = [ |
| + (os.path.join(constants.DIR_SOURCE_ROOT, test_files), |
| + os.path.join(device.GetExternalStoragePath(), test_files))] |
| + device.PushChangedFiles(host_device_file_tuple) |
| + |
| + |
| +def _PushDataDepsWithIsolate(device, test_options): |
| + valgrind_tools.PushFilesForTool(test_options.tool, device) |
| + _PushExtraSuiteDataDeps(device, test_options.test_apk) |
| + |
| + if os.path.exists(constants.ISOLATE_DEPS_DIR): |
| + device_dir = os.path.join(device.GetExternalStoragePath(), |
| + _DEVICE_DATA_DIR) |
| + device.PushChangedFiles([ |
| + (os.path.join(constants.ISOLATE_DEPS_DIR, p), |
| + os.path.join(device_dir, p)) |
| + for p in os.listdir(constants.ISOLATE_DEPS_DIR)]) |
| + |
| + |
| +# TODO(mikecase): Remove this function once everything uses |
| +# PushDataDepsWithIsolate instead. |
| +def _PushDataDeps(device, test_options): |
| + valgrind_tools.PushFilesForTool(test_options.tool, device) |
| + _PushExtraSuiteDataDeps(device, test_options.test_apk) |
| + |
| + host_device_file_tuples = [] |
| + for dest_host_pair in test_options.test_data: |
| + dst_src = dest_host_pair.split(':', 1) |
| + dst_layer = dst_src[0] |
| + host_src = dst_src[1] |
| + host_test_files_path = os.path.join(constants.DIR_SOURCE_ROOT, host_src) |
| + if os.path.exists(host_test_files_path): |
| + host_device_file_tuples += [( |
| + host_test_files_path, |
| + '%s/%s/%s' % ( |
| + device.GetExternalStoragePath(), |
| + _DEVICE_DATA_DIR, |
| + dst_layer))] |
| + if host_device_file_tuples: |
| + device.PushChangedFiles(host_device_file_tuples) |
| + |
| + |
| +def Setup(test_options, devices): |
| """Create and return the test runner factory and tests. |
| Args: |
| @@ -34,6 +133,15 @@ def Setup(test_options): |
| if not tests: |
| logging.error('No instrumentation tests to run with current args.') |
| + if test_options.test_data: |
| + device_utils.DeviceUtils.parallel(devices).pMap( |
| + _PushDataDeps, test_options) |
| + else: |
| + _GenerateDepsDirUsingIsolate(test_options.test_apk, |
| + test_options.isolate_file_path) |
| + device_utils.DeviceUtils.parallel(devices).pMap( |
| + _PushDataDepsWithIsolate, test_options) |
| + |
| def TestRunnerFactory(device, shard_index): |
| return test_runner.TestRunner(test_options, device, shard_index, |
| test_pkg) |