Commit ea769b76 authored by Wez's avatar Wez Committed by Commit Bot

[fuchsia] Fully format run_package.py.

Bug: 1038786, 1132032
Change-Id: I1c78e60428604cc7c9d720e69cb4cb9175fa6593
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2461735
Commit-Queue: Wez <wez@chromium.org>
Commit-Queue: David Dorwin <ddorwin@chromium.org>
Auto-Submit: Wez <wez@chromium.org>
Reviewed-by: default avatarDavid Dorwin <ddorwin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#815352}
parent d9882f77
# Copyright 2018 The Chromium Authors. All rights reserved. # Copyright 2018 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
"""Contains a helper function for deploying and executing a packaged """Contains a helper function for deploying and executing a packaged
executable on a Target.""" executable on a Target."""
...@@ -31,7 +30,8 @@ def _AttachKernelLogReader(target): ...@@ -31,7 +30,8 @@ def _AttachKernelLogReader(target):
"""Attaches a kernel log reader as a long-running SSH task.""" """Attaches a kernel log reader as a long-running SSH task."""
logging.info('Attaching kernel logger.') logging.info('Attaching kernel logger.')
return target.RunCommandPiped(['dlog', '-f'], stdin=open(os.devnull, 'r'), return target.RunCommandPiped(['dlog', '-f'],
stdin=open(os.devnull, 'r'),
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT) stderr=subprocess.STDOUT)
...@@ -45,7 +45,7 @@ class SystemLogReader(object): ...@@ -45,7 +45,7 @@ class SystemLogReader(object):
self._system_log = None self._system_log = None
def __enter__(self): def __enter__(self):
return self return self
def __exit__(self, exc_type, exc_val, exc_tb): def __exit__(self, exc_type, exc_val, exc_tb):
"""Stops the system logging processes and closes the output file.""" """Stops the system logging processes and closes the output file."""
...@@ -61,10 +61,10 @@ class SystemLogReader(object): ...@@ -61,10 +61,10 @@ class SystemLogReader(object):
logging.debug('Writing fuchsia system log to %s' % system_log_file) logging.debug('Writing fuchsia system log to %s' % system_log_file)
self._listener_proc = target.RunCommandPiped(['log_listener'], self._listener_proc = target.RunCommandPiped(['log_listener'],
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT) stderr=subprocess.STDOUT)
self._system_log = open(system_log_file,'w', buffering=1) self._system_log = open(system_log_file, 'w', buffering=1)
self._symbolizer_proc = RunSymbolizer(self._listener_proc.stdout, self._symbolizer_proc = RunSymbolizer(self._listener_proc.stdout,
self._system_log, self._system_log,
BuildIdsPaths(package_paths)) BuildIdsPaths(package_paths))
...@@ -89,7 +89,7 @@ class MergedInputStream(object): ...@@ -89,7 +89,7 @@ class MergedInputStream(object):
# Disable buffering for the stream to make sure there is no delay in logs. # Disable buffering for the stream to make sure there is no delay in logs.
self._output_stream = os.fdopen(write_pipe, 'w', 0) self._output_stream = os.fdopen(write_pipe, 'w', 0)
self._thread = threading.Thread(target=self._Run) self._thread = threading.Thread(target=self._Run)
self._thread.start(); self._thread.start()
return os.fdopen(read_pipe, 'r') return os.fdopen(read_pipe, 'r')
...@@ -155,6 +155,7 @@ class RunPackageArgs: ...@@ -155,6 +155,7 @@ class RunPackageArgs:
in the package. Omitting this parameter will disable symbolization. in the package. Omitting this parameter will disable symbolization.
system_logging: If set, connects a system log reader to the target. system_logging: If set, connects a system log reader to the target.
""" """
def __init__(self): def __init__(self):
self.symbolizer_config = None self.symbolizer_config = None
self.system_logging = False self.system_logging = False
...@@ -170,7 +171,7 @@ def _DrainStreamToStdout(stream, quit_event): ...@@ -170,7 +171,7 @@ def _DrainStreamToStdout(stream, quit_event):
"""Outputs the contents of |stream| until |quit_event| is set.""" """Outputs the contents of |stream| until |quit_event| is set."""
while not quit_event.is_set(): while not quit_event.is_set():
rlist, _, _ = select.select([ stream ], [], [], 0.1) rlist, _, _ = select.select([stream], [], [], 0.1)
if rlist: if rlist:
line = rlist[0].readline() line = rlist[0].readline()
if not line: if not line:
...@@ -178,8 +179,8 @@ def _DrainStreamToStdout(stream, quit_event): ...@@ -178,8 +179,8 @@ def _DrainStreamToStdout(stream, quit_event):
print(line.rstrip()) print(line.rstrip())
def RunPackage(output_dir, target, package_paths, package_name, def RunPackage(output_dir, target, package_paths, package_name, package_args,
package_args, args): args):
"""Installs the Fuchsia package at |package_path| on the target, """Installs the Fuchsia package at |package_path| on the target,
executes it with |package_args|, and symbolizes its output. executes it with |package_args|, and symbolizes its output.
...@@ -192,17 +193,15 @@ def RunPackage(output_dir, target, package_paths, package_name, ...@@ -192,17 +193,15 @@ def RunPackage(output_dir, target, package_paths, package_name,
Returns the exit code of the remote package process.""" Returns the exit code of the remote package process."""
system_logger = ( system_logger = (_AttachKernelLogReader(target)
_AttachKernelLogReader(target) if args.system_logging else None) if args.system_logging else None)
try: try:
if system_logger: if system_logger:
# Spin up a thread to asynchronously dump the system log to stdout # Spin up a thread to asynchronously dump the system log to stdout
# for easier diagnoses of early, pre-execution failures. # for easier diagnoses of early, pre-execution failures.
log_output_quit_event = multiprocessing.Event() log_output_quit_event = multiprocessing.Event()
log_output_thread = threading.Thread( log_output_thread = threading.Thread(target=lambda: _DrainStreamToStdout(
target= system_logger.stdout, log_output_quit_event))
lambda: _DrainStreamToStdout(system_logger.stdout, log_output_quit_event)
)
log_output_thread.daemon = True log_output_thread.daemon = True
log_output_thread.start() log_output_thread.start()
...@@ -215,11 +214,10 @@ def RunPackage(output_dir, target, package_paths, package_name, ...@@ -215,11 +214,10 @@ def RunPackage(output_dir, target, package_paths, package_name,
logging.info('Running application.') logging.info('Running application.')
command = ['run', _GetComponentUri(package_name)] + package_args command = ['run', _GetComponentUri(package_name)] + package_args
process = target.RunCommandPiped( process = target.RunCommandPiped(command,
command, stdin=open(os.devnull, 'r'),
stdin=open(os.devnull, 'r'), stdout=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
stderr=subprocess.STDOUT)
if system_logger: if system_logger:
output_stream = MergedInputStream( output_stream = MergedInputStream(
...@@ -240,8 +238,8 @@ def RunPackage(output_dir, target, package_paths, package_name, ...@@ -240,8 +238,8 @@ def RunPackage(output_dir, target, package_paths, package_name,
else: else:
# The test runner returns an error status code if *any* tests fail, # The test runner returns an error status code if *any* tests fail,
# so we should proceed anyway. # so we should proceed anyway.
logging.warning( logging.warning('Process exited with status code %d.' %
'Process exited with status code %d.' % process.returncode) process.returncode)
finally: finally:
if system_logger: if system_logger:
......
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