diff options
Diffstat (limited to 'build')
-rw-r--r-- | build/android/pylib/device/device_utils.py | 11 | ||||
-rw-r--r-- | build/android/pylib/remote/device/remote_device_test_run.py | 23 | ||||
-rw-r--r-- | build/android/pylib/utils/zip_utils.py | 31 |
3 files changed, 55 insertions, 10 deletions
diff --git a/build/android/pylib/device/device_utils.py b/build/android/pylib/device/device_utils.py index c0a5a4f..fe9d2c6 100644 --- a/build/android/pylib/device/device_utils.py +++ b/build/android/pylib/device/device_utils.py @@ -31,6 +31,7 @@ from pylib.utils import host_utils from pylib.utils import md5sum from pylib.utils import parallelizer from pylib.utils import timeout_retry +from pylib.utils import zip_utils _DEFAULT_TIMEOUT = 30 _DEFAULT_RETRIES = 3 @@ -831,15 +832,7 @@ class DeviceUtils(object): def _CreateDeviceZip(zip_path, host_device_tuples): with zipfile.ZipFile(zip_path, 'w') as zip_file: for host_path, device_path in host_device_tuples: - if os.path.isfile(host_path): - zip_file.write(host_path, device_path, zipfile.ZIP_DEFLATED) - else: - for hd, _, files in os.walk(host_path): - dd = '%s/%s' % (device_path, os.path.relpath(host_path, hd)) - zip_file.write(hd, dd, zipfile.ZIP_STORED) - for f in files: - zip_file.write(os.path.join(hd, f), '%s/%s' % (dd, f), - zipfile.ZIP_DEFLATED) + zip_utils.WriteToZipFile(zip_file, host_path, device_path) @decorators.WithTimeoutAndRetriesFromInstance() def FileExists(self, device_path, timeout=None, retries=None): diff --git a/build/android/pylib/remote/device/remote_device_test_run.py b/build/android/pylib/remote/device/remote_device_test_run.py index b9d06be..dfa22d5 100644 --- a/build/android/pylib/remote/device/remote_device_test_run.py +++ b/build/android/pylib/remote/device/remote_device_test_run.py @@ -9,11 +9,13 @@ import os import sys import tempfile import time +import zipfile from pylib import constants from pylib.base import test_run from pylib.remote.device import appurify_sanitized from pylib.remote.device import remote_device_helper +from pylib.utils import zip_utils class RemoteDeviceTestRun(test_run.TestRun): """Run gtests and uirobot tests on a remote device.""" @@ -142,7 +144,26 @@ class RemoteDeviceTestRun(test_run.TestRun): config = {'runner': runner_package} self._app_id = self._UploadAppToDevice(app_path) - self._test_id = self._UploadTestToDevice('robotium', test_path) + + data_deps = self._test_instance.GetDataDependencies() + if data_deps: + with tempfile.NamedTemporaryFile(suffix='.zip') as test_with_deps: + sdcard_files = [] + host_test = os.path.basename(test_path) + with zipfile.ZipFile(test_with_deps.name, 'w') as zip_file: + zip_file.write(test_path, host_test, zipfile.ZIP_DEFLATED) + for h, _ in data_deps: + zip_utils.WriteToZipFile(zip_file, h, '.') + if os.path.isdir(h): + sdcard_files.extend(os.listdir(h)) + else: + sdcard_files.extend(h) + config['sdcard_files'] = ','.join(sdcard_files) + config['host_test'] = host_test + self._test_id = self._UploadTestToDevice( + 'robotium', test_with_deps.name) + else: + self._test_id = self._UploadTestToDevice('robotium', test_path) logging.info('Setting config: %s' % config) self._SetTestConfig('robotium', config) diff --git a/build/android/pylib/utils/zip_utils.py b/build/android/pylib/utils/zip_utils.py new file mode 100644 index 0000000..d799463 --- /dev/null +++ b/build/android/pylib/utils/zip_utils.py @@ -0,0 +1,31 @@ +# Copyright 2015 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import logging +import os +import zipfile + + +def WriteToZipFile(zip_file, path, arc_path): + """Recursively write |path| to |zip_file| as |arc_path|. + + zip_file: An open instance of zipfile.ZipFile. + path: An absolute path to the file or directory to be zipped. + arc_path: A relative path within the zip file to which the file or directory + located at |path| should be written. + """ + if os.path.isdir(path): + for dir_path, _, file_names in os.walk(path): + dir_arc_path = os.path.join(arc_path, os.path.relpath(dir_path, path)) + logging.debug('dir: %s -> %s', dir_path, dir_arc_path) + zip_file.write(dir_path, dir_arc_path, zipfile.ZIP_STORED) + for f in file_names: + file_path = os.path.join(dir_path, f) + file_arc_path = os.path.join(dir_arc_path, f) + logging.debug('file: %s -> %s', file_path, file_arc_path) + zip_file.write(file_path, file_arc_path, zipfile.ZIP_DEFLATED) + else: + logging.debug('file: %s -> %s', path, arc_path) + zip_file.write(path, arc_path, zipfile.ZIP_DEFLATED) + |