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

[fuchsia] Convert specific fuchsia test runner exceptions to exit codes.

This will enable BigQuery searches on exit codes to find intermittent
errors.

Bug: 1063106
Change-Id: I7387869331957f851817a7aa2deabf654ee3a954
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2162105Reviewed-by: default avatarWez <wez@chromium.org>
Commit-Queue: Stephen Roe <steveroe@google.com>
Cr-Commit-Position: refs/heads/master@{#763466}
parent 4ee7c239
# Copyright 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Converts exceptions to return codes and prints error messages.
This makes it easier to query build tables for particular error types as
exit codes are visible to queries while exception stack traces are not."""
import subprocess
import sys
import traceback
from target import FuchsiaTargetException
def _PrintException(value, trace):
"""Prints stack trace and error message for the current exception."""
traceback.print_tb(trace)
print(str(value))
def HandleExceptionAndReturnExitCode():
"""Maps the current exception to a return code and prints error messages.
Mapped exception types are assigned blocks of 8 return codes starting at 64.
The choice of 64 as the starting code is based on the Advanced Bash-Scripting
Guide (http://tldp.org/LDP/abs/html/exitcodes.html).
A generic exception is mapped to the start of the block. More specific
exceptions are mapped to numbers inside the block. For example, a
FuchsiaTargetException is mapped to return code 64, unless it involves SSH
in which case it is mapped to return code 65.
Exceptions not specifically mapped go to return code 1.
Returns the mapped return code."""
(type, value, trace) = sys.exc_info()
if type is FuchsiaTargetException:
if 'ssh' in str(value).lower():
print("Error: FuchsiaTargetException: SSH to Fuchsia target failed.")
return 65
_PrintException(value, trace)
return 64
elif type is IOError:
if value.errno == 11:
print("Error: IOError: [Errno 11] Resource temporarily unavailable.")
print("Info: Python print to stdout probably failed")
return 73
_PrintException(value, trace)
return 72
elif type is subprocess.CalledProcessError:
if value.cmd[0] == 'scp':
print("Error: scp operation failed - %s" % str(value))
return 81
_PrintException(value, trace)
return 80
else:
_PrintException(value, trace)
return 1
...@@ -19,6 +19,7 @@ import time ...@@ -19,6 +19,7 @@ import time
from common_args import AddCommonArgs, ConfigureLogging, GetDeploymentTargetForArgs from common_args import AddCommonArgs, ConfigureLogging, GetDeploymentTargetForArgs
from net_test_server import SetupTestServer from net_test_server import SetupTestServer
from run_package import RunPackage, RunPackageArgs, SystemLogReader from run_package import RunPackage, RunPackageArgs, SystemLogReader
from runner_exceptions import HandleExceptionAndReturnExitCode
DEFAULT_TEST_SERVER_CONCURRENCY = 4 DEFAULT_TEST_SERVER_CONCURRENCY = 4
...@@ -138,37 +139,41 @@ def main(): ...@@ -138,37 +139,41 @@ def main():
if args.child_args: if args.child_args:
child_args.extend(args.child_args) child_args.extend(args.child_args)
with GetDeploymentTargetForArgs(args) as target: try:
with SystemLogReader() as system_logger: with GetDeploymentTargetForArgs(args) as target:
target.Start() with SystemLogReader() as system_logger:
target.Start()
if args.system_log_file and args.system_log_file != '-': if args.system_log_file and args.system_log_file != '-':
system_logger.Start(target, args.package, args.system_log_file) system_logger.Start(target, args.package, args.system_log_file)
if args.test_launcher_filter_file: if args.test_launcher_filter_file:
target.PutFile(args.test_launcher_filter_file, TEST_FILTER_PATH, target.PutFile(args.test_launcher_filter_file, TEST_FILTER_PATH,
for_package=args.package_name) for_package=args.package_name)
child_args.append('--test-launcher-filter-file=' + TEST_FILTER_PATH) child_args.append('--test-launcher-filter-file=' + TEST_FILTER_PATH)
test_server = None test_server = None
if args.enable_test_server: if args.enable_test_server:
assert test_concurrency assert test_concurrency
test_server = SetupTestServer(target, test_concurrency, test_server = SetupTestServer(target, test_concurrency,
args.package_name) args.package_name)
run_package_args = RunPackageArgs.FromCommonArgs(args) run_package_args = RunPackageArgs.FromCommonArgs(args)
returncode = RunPackage( returncode = RunPackage(
args.output_directory, target, args.package, args.package_name, args.output_directory, target, args.package, args.package_name,
child_args, run_package_args) child_args, run_package_args)
if test_server: if test_server:
test_server.Stop() test_server.Stop()
if args.test_launcher_summary_output: if args.test_launcher_summary_output:
target.GetFile(TEST_RESULT_PATH, args.test_launcher_summary_output, target.GetFile(TEST_RESULT_PATH, args.test_launcher_summary_output,
for_package=args.package_name) for_package=args.package_name)
return returncode return returncode
except:
return HandleExceptionAndReturnExitCode()
if __name__ == '__main__': 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