v8/tools/testrunner/local/android.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

206 lines
6.8 KiB
Python
Raw Normal View History

# Copyright 2018 the V8 project authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
Wrapper around the Android device abstraction from src/build/android.
"""
import logging
import os
import sys
BASE_DIR = os.path.normpath(
os.path.join(os.path.dirname(__file__), '..', '..', '..'))
ANDROID_DIR = os.path.join(BASE_DIR, 'build', 'android')
DEVICE_DIR = '/data/local/tmp/v8/'
class TimeoutException(Exception):
def __init__(self, timeout, output=None):
self.timeout = timeout
self.output = output
class CommandFailedException(Exception):
def __init__(self, status, output):
self.status = status
self.output = output
class _Driver(object):
"""Helper class to execute shell commands on an Android device."""
def __init__(self, device=None):
assert os.path.exists(ANDROID_DIR)
sys.path.insert(0, ANDROID_DIR)
# We import the dependencies only on demand, so that this file can be
# imported unconditionally.
import devil_chromium
from devil.android import device_errors # pylint: disable=import-error
from devil.android import device_utils # pylint: disable=import-error
from devil.android.perf import cache_control # pylint: disable=import-error
from devil.android.perf import perf_control # pylint: disable=import-error
global cache_control
global device_errors
global perf_control
devil_chromium.Initialize()
# Find specified device or a single attached device if none was specified.
# In case none or multiple devices are attached, this raises an exception.
self.device = device_utils.DeviceUtils.HealthyDevices(
retries=5, enable_usb_resets=True, device_arg=device)[0]
Revert "Reland "[tools] Push files using high-level device.PushChangedFiles method"" This reverts commit 6e03d7ee42953188d0d3cb5235068f025d1df456. Reason for revert: This breaks the Android bot: https://ci.chromium.org/p/v8/builders/luci.v8.ci/V8%20Android%20Arm64%20-%20N5X/2933 It's quite hidden due to https://crbug.com/v8/8731 but all shards time out. It looks like to to this change, testing takes dramatically longer, maybe the pushing takes now much longer than before. If we want decide for this, the builder needs to get many more shards. Original change's description: > Reland "[tools] Push files using high-level device.PushChangedFiles method" > > This is a reland of d045f6668231bb5974d6bacc64f513fbcf840ac7 > > 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: Michael Achenbach <machenbach@chromium.org> > Cr-Commit-Position: refs/heads/master@{#59221} TBR=machenbach@chromium.org,tandrii@chromium.org,sergiyb@chromium.org,bpastene@chromium.org,jbudorick@chromium.org # Not skipping CQ checks because original CL landed > 1 day ago. Bug: chromium:893593 Change-Id: Ifea307b5de8f39b660966fc6bef54601df91d841 Reviewed-on: https://chromium-review.googlesource.com/c/1450119 Reviewed-by: Michael Achenbach <machenbach@chromium.org> Reviewed-by: Sergiy Belozorov <sergiyb@chromium.org> Commit-Queue: Michael Achenbach <machenbach@chromium.org> Cr-Commit-Position: refs/heads/master@{#59305}
2019-02-01 20:05:43 +00:00
# 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)
Revert "Reland "[tools] Push files using high-level device.PushChangedFiles method"" This reverts commit 6e03d7ee42953188d0d3cb5235068f025d1df456. Reason for revert: This breaks the Android bot: https://ci.chromium.org/p/v8/builders/luci.v8.ci/V8%20Android%20Arm64%20-%20N5X/2933 It's quite hidden due to https://crbug.com/v8/8731 but all shards time out. It looks like to to this change, testing takes dramatically longer, maybe the pushing takes now much longer than before. If we want decide for this, the builder needs to get many more shards. Original change's description: > Reland "[tools] Push files using high-level device.PushChangedFiles method" > > This is a reland of d045f6668231bb5974d6bacc64f513fbcf840ac7 > > 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: Michael Achenbach <machenbach@chromium.org> > Cr-Commit-Position: refs/heads/master@{#59221} TBR=machenbach@chromium.org,tandrii@chromium.org,sergiyb@chromium.org,bpastene@chromium.org,jbudorick@chromium.org # Not skipping CQ checks because original CL landed > 1 day ago. Bug: chromium:893593 Change-Id: Ifea307b5de8f39b660966fc6bef54601df91d841 Reviewed-on: https://chromium-review.googlesource.com/c/1450119 Reviewed-by: Michael Achenbach <machenbach@chromium.org> Reviewed-by: Sergiy Belozorov <sergiyb@chromium.org> Commit-Queue: Michael Achenbach <machenbach@chromium.org> Cr-Commit-Position: refs/heads/master@{#59305}
2019-02-01 20:05:43 +00:00
def push_file(self, host_dir, file_name, target_rel='.',
skip_if_missing=False):
"""Push a single file to the device (cached).
Args:
Revert "Reland "[tools] Push files using high-level device.PushChangedFiles method"" This reverts commit 6e03d7ee42953188d0d3cb5235068f025d1df456. Reason for revert: This breaks the Android bot: https://ci.chromium.org/p/v8/builders/luci.v8.ci/V8%20Android%20Arm64%20-%20N5X/2933 It's quite hidden due to https://crbug.com/v8/8731 but all shards time out. It looks like to to this change, testing takes dramatically longer, maybe the pushing takes now much longer than before. If we want decide for this, the builder needs to get many more shards. Original change's description: > Reland "[tools] Push files using high-level device.PushChangedFiles method" > > This is a reland of d045f6668231bb5974d6bacc64f513fbcf840ac7 > > 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: Michael Achenbach <machenbach@chromium.org> > Cr-Commit-Position: refs/heads/master@{#59221} TBR=machenbach@chromium.org,tandrii@chromium.org,sergiyb@chromium.org,bpastene@chromium.org,jbudorick@chromium.org # Not skipping CQ checks because original CL landed > 1 day ago. Bug: chromium:893593 Change-Id: Ifea307b5de8f39b660966fc6bef54601df91d841 Reviewed-on: https://chromium-review.googlesource.com/c/1450119 Reviewed-by: Michael Achenbach <machenbach@chromium.org> Reviewed-by: Sergiy Belozorov <sergiyb@chromium.org> Commit-Queue: Michael Achenbach <machenbach@chromium.org> Cr-Commit-Position: refs/heads/master@{#59305}
2019-02-01 20:05:43 +00:00
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).
skip_if_missing: Keeps silent about missing files when set. Otherwise logs
error.
"""
Revert "Reland "[tools] Push files using high-level device.PushChangedFiles method"" This reverts commit 6e03d7ee42953188d0d3cb5235068f025d1df456. Reason for revert: This breaks the Android bot: https://ci.chromium.org/p/v8/builders/luci.v8.ci/V8%20Android%20Arm64%20-%20N5X/2933 It's quite hidden due to https://crbug.com/v8/8731 but all shards time out. It looks like to to this change, testing takes dramatically longer, maybe the pushing takes now much longer than before. If we want decide for this, the builder needs to get many more shards. Original change's description: > Reland "[tools] Push files using high-level device.PushChangedFiles method" > > This is a reland of d045f6668231bb5974d6bacc64f513fbcf840ac7 > > 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: Michael Achenbach <machenbach@chromium.org> > Cr-Commit-Position: refs/heads/master@{#59221} TBR=machenbach@chromium.org,tandrii@chromium.org,sergiyb@chromium.org,bpastene@chromium.org,jbudorick@chromium.org # Not skipping CQ checks because original CL landed > 1 day ago. Bug: chromium:893593 Change-Id: Ifea307b5de8f39b660966fc6bef54601df91d841 Reviewed-on: https://chromium-review.googlesource.com/c/1450119 Reviewed-by: Michael Achenbach <machenbach@chromium.org> Reviewed-by: Sergiy Belozorov <sergiyb@chromium.org> Commit-Queue: Michael Achenbach <machenbach@chromium.org> Cr-Commit-Position: refs/heads/master@{#59305}
2019-02-01 20:05:43 +00:00
# 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)
def push_executable(self, shell_dir, target_dir, binary):
"""Push files required to run a V8 executable.
Args:
shell_dir: Absolute parent directory of the executable on the host.
target_dir: Parent directory of the executable on the device (relative to
devices' base dir for testing).
binary: Name of the binary to push.
"""
Revert "Reland "[tools] Push files using high-level device.PushChangedFiles method"" This reverts commit 6e03d7ee42953188d0d3cb5235068f025d1df456. Reason for revert: This breaks the Android bot: https://ci.chromium.org/p/v8/builders/luci.v8.ci/V8%20Android%20Arm64%20-%20N5X/2933 It's quite hidden due to https://crbug.com/v8/8731 but all shards time out. It looks like to to this change, testing takes dramatically longer, maybe the pushing takes now much longer than before. If we want decide for this, the builder needs to get many more shards. Original change's description: > Reland "[tools] Push files using high-level device.PushChangedFiles method" > > This is a reland of d045f6668231bb5974d6bacc64f513fbcf840ac7 > > 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: Michael Achenbach <machenbach@chromium.org> > Cr-Commit-Position: refs/heads/master@{#59221} TBR=machenbach@chromium.org,tandrii@chromium.org,sergiyb@chromium.org,bpastene@chromium.org,jbudorick@chromium.org # Not skipping CQ checks because original CL landed > 1 day ago. Bug: chromium:893593 Change-Id: Ifea307b5de8f39b660966fc6bef54601df91d841 Reviewed-on: https://chromium-review.googlesource.com/c/1450119 Reviewed-by: Michael Achenbach <machenbach@chromium.org> Reviewed-by: Sergiy Belozorov <sergiyb@chromium.org> Commit-Queue: Michael Achenbach <machenbach@chromium.org> Cr-Commit-Position: refs/heads/master@{#59305}
2019-02-01 20:05:43 +00:00
self.push_file(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.
Revert "Reland "[tools] Push files using high-level device.PushChangedFiles method"" This reverts commit 6e03d7ee42953188d0d3cb5235068f025d1df456. Reason for revert: This breaks the Android bot: https://ci.chromium.org/p/v8/builders/luci.v8.ci/V8%20Android%20Arm64%20-%20N5X/2933 It's quite hidden due to https://crbug.com/v8/8731 but all shards time out. It looks like to to this change, testing takes dramatically longer, maybe the pushing takes now much longer than before. If we want decide for this, the builder needs to get many more shards. Original change's description: > Reland "[tools] Push files using high-level device.PushChangedFiles method" > > This is a reland of d045f6668231bb5974d6bacc64f513fbcf840ac7 > > 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: Michael Achenbach <machenbach@chromium.org> > Cr-Commit-Position: refs/heads/master@{#59221} TBR=machenbach@chromium.org,tandrii@chromium.org,sergiyb@chromium.org,bpastene@chromium.org,jbudorick@chromium.org # Not skipping CQ checks because original CL landed > 1 day ago. Bug: chromium:893593 Change-Id: Ifea307b5de8f39b660966fc6bef54601df91d841 Reviewed-on: https://chromium-review.googlesource.com/c/1450119 Reviewed-by: Michael Achenbach <machenbach@chromium.org> Reviewed-by: Sergiy Belozorov <sergiyb@chromium.org> Commit-Queue: Michael Achenbach <machenbach@chromium.org> Cr-Commit-Position: refs/heads/master@{#59305}
2019-02-01 20:05:43 +00:00
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,
)
def run(self, target_dir, binary, args, rel_path, timeout, env=None,
logcat_file=False):
"""Execute a command on the device's shell.
Args:
target_dir: Parent directory of the executable on the device (relative to
devices' base dir for testing).
binary: Name of the binary.
args: List of arguments to pass to the binary.
rel_path: Relative path on device to use as CWD.
timeout: Timeout in seconds.
env: The environment variables with which the command should be run.
logcat_file: File into which to stream adb logcat log.
"""
binary_on_device = os.path.join(DEVICE_DIR, target_dir, binary)
cmd = [binary_on_device] + args
def run_inner():
try:
output = self.device.RunShellCommand(
cmd,
cwd=os.path.join(DEVICE_DIR, rel_path),
check_return=True,
env=env,
timeout=timeout,
retries=0,
)
return '\n'.join(output)
except device_errors.AdbCommandFailedError as e:
raise CommandFailedException(e.status, e.output)
except device_errors.CommandTimeoutError as e:
raise TimeoutException(timeout, e.output)
if logcat_file:
with self.device.GetLogcatMonitor(output_file=logcat_file) as logmon:
result = run_inner()
logmon.Close()
return result
else:
return run_inner()
def drop_ram_caches(self):
"""Drop ran caches on device."""
cache = cache_control.CacheControl(self.device)
cache.DropRamCaches()
def set_high_perf_mode(self):
"""Set device into high performance mode."""
perf = perf_control.PerfControl(self.device)
perf.SetHighPerfMode()
def set_default_perf_mode(self):
"""Set device into default performance mode."""
perf = perf_control.PerfControl(self.device)
perf.SetDefaultPerfMode()
_ANDROID_DRIVER = None
def android_driver(device=None):
"""Singleton access method to the driver class."""
global _ANDROID_DRIVER
if not _ANDROID_DRIVER:
_ANDROID_DRIVER = _Driver(device)
return _ANDROID_DRIVER