Commit 0e0157a4 authored by Sergiy Byelozyorov's avatar Sergiy Byelozyorov Committed by Commit Bot

[tools] Upload adb logcat to logdog when running tests

R=machenbach@chromium.org

No-Try: true
Bug: chromium:872257
Change-Id: I4de1a9dfccbb0d123c1c42c31a1f697e628623fa
Reviewed-on: https://chromium-review.googlesource.com/1171224
Commit-Queue: Sergiy Byelozyorov <sergiyb@chromium.org>
Reviewed-by: 's avatarMichael Achenbach <machenbach@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55067}
parent 51e6ecb9
......@@ -611,6 +611,7 @@ class Platform(object):
self.shell_dir = options.shell_dir
self.shell_dir_secondary = options.shell_dir_secondary
self.extra_flags = options.extra_flags.split()
self.options = options
@staticmethod
def ReadBuildConfig(options):
......@@ -758,6 +759,14 @@ class AndroidPlatform(Platform): # pragma: no cover
else:
bench_rel = "."
logcat_file = None
if self.options.dump_logcats_to:
runnable_name = '-'.join(runnable.graphs)
logcat_file = os.path.join(
self.options.dump_logcats_to, 'logcat-%s-#%d%s.log' % (
runnable_name, count + 1, '-secondary' if secondary else ''))
logging.debug('Dumping logcat into %s', logcat_file)
try:
stdout = self.driver.run(
target_dir=target_dir,
......@@ -765,6 +774,7 @@ class AndroidPlatform(Platform): # pragma: no cover
args=runnable.GetCommandFlags(self.extra_flags),
rel_path=bench_rel,
timeout=runnable.timeout,
logcat_file=logcat_file,
)
logging.info(title % "Stdout" + "\n%s", stdout)
except android.CommandFailedException as e:
......@@ -944,6 +954,9 @@ def Main(args):
parser.add_option("--run-count-multiplier", default=1, type="int",
help="Multipled used to increase number of times each test "
"is retried.")
parser.add_option("--dump-logcats-to",
help="Writes logcat output from each test into specified "
"directory. Only supported for android targets.")
(options, args) = parser.parse_args(args)
......
......@@ -141,7 +141,8 @@ class _Driver(object):
skip_if_missing=True,
)
def run(self, target_dir, binary, args, rel_path, timeout, env=None):
def run(self, target_dir, binary, args, rel_path, timeout, env=None,
logcat_file=False):
"""Execute a command on the device's shell.
Args:
......@@ -152,23 +153,34 @@ class _Driver(object):
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
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:
raise TimeoutException(timeout)
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:
raise TimeoutException(timeout)
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."""
......
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