Commit a4bb64cd authored by Stephen Roe's avatar Stephen Roe Committed by Commit Bot

Reland "[fuchsia] Collect Fuchsia system logs from Chrome-Fuchsia tests."

This is a reland of e2eb7388

System log collection is enabled by specifying a --enable-fuchsia-system-log argument which causes the test runner scripts to write the fuchsia system log to the test system_log file instead of writing the fuchsia kernel log file.

Original change's description:
> [fuchsia] Collect Fuchsia system logs from Chrome-Fuchsia tests.
>
> The Fuchsia system logs contain more detailed information than the Fuchsia kernel logs.
>
> Currently only Fuchsia kernel logs are collected.  The kernel logs are:
> - written to the swarming task output log along with the actual test output
> - optionally written to a "system_log" file in the test isolate output
>
> This CL will:
> - optionally write the Fuchsia system log to a "log_listener_log" in the test isolate output
>
> The Fuchsia system log will be written if the kernel log is written.
>
> The Fuchsia system log is written to "log_listener_log".  The name "log_listener_log" was used because the Fuchsia kernel log contents are already saved in "system_log".
>
> Bug: 1042512
> Change-Id: I900b5dfe9f6587f1901c19612060b979fae4da99
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2130679
> Reviewed-by: Kevin Marshall <kmarshall@chromium.org>
> Commit-Queue: Stephen Roe <steveroe@google.com>
> Cr-Commit-Position: refs/heads/master@{#756118}

Bug: 1042512
Change-Id: I9edf2991e697e09b81b7c206cce0de04ca42b500
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2136143
Commit-Queue: Stephen Roe <steveroe@google.com>
Reviewed-by: default avatarKevin Marshall <kmarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758636}
parent 9ee01d32
......@@ -62,6 +62,10 @@ def AddCommonArgs(arg_parser):
common_args.add_argument('--ssh-config', '-F',
help='The path to the SSH configuration used for '
'connecting to the target device.')
common_args.add_argument('--enable-fuchsia-system-log',
action='store_true',
help='Write the Fuchsia system log to the test '
'system_log instead of the Fuchsia kernel log.')
common_args.add_argument('--fuchsia-out-dir',
help='Path to a Fuchsia build output directory. '
'Equivalent to setting --ssh_config and '
......
......@@ -20,6 +20,7 @@ import time
import threading
import uuid
from symbolizer import RunSymbolizer
from symbolizer import SymbolizerFilter
FAR = common.GetHostToolPathFromPlatform('far')
......@@ -36,6 +37,49 @@ def _AttachKernelLogReader(target):
stdout=subprocess.PIPE)
def _BuildIdsPaths(package_paths):
"""Generate build ids paths for symbolizer processes."""
build_ids_paths = map(
lambda package_path: os.path.join(
os.path.dirname(package_path), 'ids.txt'),
package_paths)
return build_ids_paths
class SystemLogReader(object):
"""Collects and symbolizes Fuchsia system log to a file."""
def __init__(self):
self._listener_proc = None
self._symbolizer_proc = None
self._system_log = None
def __enter__(self):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
"""Stops the system logging processes and closes the output file."""
if self._symbolizer_proc:
self._symbolizer_proc.kill()
if self._listener_proc:
self._listener_proc.kill()
if self._system_log:
self._system_log.close()
def Start(self, target, package_paths, system_log_file):
"""Start a system log reader as a long-running SSH task."""
logging.debug('Writing fuchsia system log to %s' % system_log_file)
self._listener_proc = target.RunCommandPiped(['log_listener'],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
self._system_log = open(system_log_file,'w', buffering=1)
self._symbolizer_proc = RunSymbolizer(self._listener_proc.stdout,
self._system_log,
_BuildIdsPaths(package_paths))
class MergedInputStream(object):
"""Merges a number of input streams into a UNIX pipe on a dedicated thread.
Terminates when the file descriptor of the primary stream (the first in
......@@ -194,11 +238,8 @@ def RunPackage(output_dir, target, package_paths, package_name,
output_stream = process.stdout
# Run the log data through the symbolizer process.
build_ids_paths = map(
lambda package_path: os.path.join(
os.path.dirname(package_path), 'ids.txt'),
package_paths)
output_stream = SymbolizerFilter(output_stream, build_ids_paths)
output_stream = SymbolizerFilter(output_stream,
_BuildIdsPaths(package_paths))
for next_line in output_stream:
print(next_line.rstrip())
......
......@@ -18,7 +18,7 @@ import time
from common_args import AddCommonArgs, ConfigureLogging, GetDeploymentTargetForArgs
from net_test_server import SetupTestServer
from run_package import RunPackage, RunPackageArgs
from run_package import RunPackage, RunPackageArgs, SystemLogReader
DEFAULT_TEST_SERVER_CONCURRENCY = 4
......@@ -139,32 +139,37 @@ def main():
child_args.extend(args.child_args)
with GetDeploymentTargetForArgs(args) as target:
target.Start()
with SystemLogReader() as system_logger:
target.Start()
if args.test_launcher_filter_file:
target.PutFile(args.test_launcher_filter_file, TEST_FILTER_PATH,
for_package=args.package_name)
child_args.append('--test-launcher-filter-file=' + TEST_FILTER_PATH)
if args.enable_fuchsia_system_log:
if args.system_log_file and args.system_log_file != '-':
system_logger.Start(target, args.package, args.system_log_file)
test_server = None
if args.enable_test_server:
assert test_concurrency
test_server = SetupTestServer(target, test_concurrency,
args.package_name)
if args.test_launcher_filter_file:
target.PutFile(args.test_launcher_filter_file, TEST_FILTER_PATH,
for_package=args.package_name)
child_args.append('--test-launcher-filter-file=' + TEST_FILTER_PATH)
run_package_args = RunPackageArgs.FromCommonArgs(args)
returncode = RunPackage(
args.output_directory, target, args.package, args.package_name,
child_args, run_package_args)
test_server = None
if args.enable_test_server:
assert test_concurrency
test_server = SetupTestServer(target, test_concurrency,
args.package_name)
if test_server:
test_server.Stop()
run_package_args = RunPackageArgs.FromCommonArgs(args)
returncode = RunPackage(
args.output_directory, target, args.package, args.package_name,
child_args, run_package_args)
if args.test_launcher_summary_output:
target.GetFile(TEST_RESULT_PATH, args.test_launcher_summary_output,
for_package=args.package_name)
if test_server:
test_server.Stop()
return returncode
if args.test_launcher_summary_output:
target.GetFile(TEST_RESULT_PATH, args.test_launcher_summary_output,
for_package=args.package_name)
return returncode
if __name__ == '__main__':
......
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