Commit 6e03d7ee authored by Sergiy Belozorov's avatar Sergiy Belozorov Committed by Commit Bot

Reland "[tools] Push files using high-level device.PushChangedFiles method"

This is a reland of d045f666

Original change's description:
> [tools] Push files using high-level device.PushChangedFiles method
>
> R=machenbach@chromium.org
>
> No-Try: true
> Bug: chromium:893593
> Change-Id: I11cce7694eb7755ccee42c9a342fc1aa22663d85
> Reviewed-on: https://chromium-review.googlesource.com/c/1382468
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Commit-Queue: Sergiy Belozorov <sergiyb@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#58407}

Bug: chromium:893593
Change-Id: I88a7143b3f31d87d266b89221f81efe831ea3823
Reviewed-on: https://chromium-review.googlesource.com/c/1443055
Commit-Queue: Andrii Shyshkalov <tandrii@chromium.org>
Reviewed-by: 's avatarMichael Achenbach <machenbach@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59221}
parent 5bdb1329
......@@ -753,10 +753,11 @@ class AndroidPlatform(Platform): # pragma: no cover
self.driver.push_executable(
self.shell_dir_secondary, "bin_secondary", node.binary)
file_tuples = [
(bench_abs, file_name, bench_rel) for file_name in node.resources]
if isinstance(node, RunnableConfig):
self.driver.push_file(bench_abs, node.main, bench_rel)
for resource in node.resources:
self.driver.push_file(bench_abs, resource, bench_rel)
file_tuples.append((bench_abs, node.main, bench_rel))
self.driver.push_files(file_tuples)
def _Run(self, runnable, count, secondary=False):
suffix = ' - secondary' if secondary else ''
......
......@@ -53,53 +53,37 @@ class _Driver(object):
self.device = device_utils.DeviceUtils.HealthyDevices(
retries=5, enable_usb_resets=True, device_arg=device)[0]
# This remembers what we have already pushed to the device.
self.pushed = set()
def tear_down(self):
"""Clean up files after running all tests."""
self.device.RemovePath(DEVICE_DIR, force=True, recursive=True)
def push_file(self, host_dir, file_name, target_rel='.',
skip_if_missing=False):
"""Push a single file to the device (cached).
def push_files(self, file_tuples, skip_if_missing=False):
"""Push multiple files/dirs to the device.
Args:
host_dir: Absolute parent directory of the file to push.
file_name: Name of the file to push.
target_rel: Parent directory of the target location on the device
(relative to the device's base dir for testing).
file_tuples: List of 3-tuples (host_dir, file_name, target_rel), where
host_dir is absolute parent directory of the files/dirs to be pushed,
file_name is file or dir path to be pushed (relative to host_dir), and
target_rel is parent directory of the target location on the device
relative to the device's base dir for testing.
skip_if_missing: Keeps silent about missing files when set. Otherwise logs
error.
"""
# TODO(sergiyb): Implement this method using self.device.PushChangedFiles to
# avoid accessing low-level self.device.adb.
file_on_host = os.path.join(host_dir, file_name)
# Only push files not yet pushed in one execution.
if file_on_host in self.pushed:
return
file_on_device_tmp = os.path.join(DEVICE_DIR, '_tmp_', file_name)
file_on_device = os.path.join(DEVICE_DIR, target_rel, file_name)
folder_on_device = os.path.dirname(file_on_device)
# Only attempt to push files that exist.
if not os.path.exists(file_on_host):
if not skip_if_missing:
logging.critical('Missing file on host: %s' % file_on_host)
return
# Work-around for 'text file busy' errors. Push the files to a temporary
# location and then copy them with a shell command.
output = self.device.adb.Push(file_on_host, file_on_device_tmp)
# Success looks like this: '3035 KB/s (12512056 bytes in 4.025s)'.
# Errors look like this: 'failed to copy ... '.
if output and not re.search('^[0-9]', output.splitlines()[-1]):
logging.critical('PUSH FAILED: ' + output)
self.device.adb.Shell('mkdir -p %s' % folder_on_device)
self.device.adb.Shell('cp %s %s' % (file_on_device_tmp, file_on_device))
self.pushed.add(file_on_host)
host_device_tuples = []
for host_dir, file_name, target_rel in file_tuples:
file_on_host = os.path.join(host_dir, file_name)
if not os.path.exists(file_on_host):
if not skip_if_missing:
logging.critical('Missing file on host: %s' % file_on_host)
continue
file_on_device = os.path.join(DEVICE_DIR, target_rel, file_name)
host_device_tuples.append((file_on_host, file_on_device))
try:
self.device.PushChangedFiles(host_device_tuples)
except device_errors.CommandFailedError as e:
logging.critical('PUSH FAILED: %s', e.message)
def push_executable(self, shell_dir, target_dir, binary):
"""Push files required to run a V8 executable.
......@@ -110,34 +94,16 @@ class _Driver(object):
devices' base dir for testing).
binary: Name of the binary to push.
"""
self.push_file(shell_dir, binary, target_dir)
self.push_files([(shell_dir, binary, target_dir)])
# Push external startup data. Backwards compatible for revisions where
# these files didn't exist. Or for bots that don't produce these files.
self.push_file(
shell_dir,
'natives_blob.bin',
target_dir,
skip_if_missing=True,
)
self.push_file(
shell_dir,
'snapshot_blob.bin',
target_dir,
skip_if_missing=True,
)
self.push_file(
shell_dir,
'snapshot_blob_trusted.bin',
target_dir,
skip_if_missing=True,
)
self.push_file(
shell_dir,
'icudtl.dat',
target_dir,
skip_if_missing=True,
)
self.push_files([
(shell_dir, 'natives_blob.bin', target_dir),
(shell_dir, 'snapshot_blob.bin', target_dir),
(shell_dir, 'snapshot_blob_trusted.bin', target_dir),
(shell_dir, 'icudtl.dat', target_dir),
], skip_if_missing=True)
def run(self, target_dir, binary, args, rel_path, timeout, env=None,
logcat_file=False):
......
......@@ -238,11 +238,13 @@ class AndroidCommand(BaseCommand):
android_driver().push_executable(self.shell_dir, 'bin', self.shell_name)
file_tuples = []
for abs_file in self.files_to_push:
abs_dir = os.path.dirname(abs_file)
file_name = os.path.basename(abs_file)
rel_dir = os.path.relpath(abs_dir, BASE_DIR)
android_driver().push_file(abs_dir, file_name, rel_dir)
file_tuples.append((abs_dir, file_name, rel_dir))
android_driver().push_files(file_tuples)
start_time = time.time()
return_code = 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment