Skip to content

Commit

Permalink
Update testrunner to use wrapper args in rerun statement.
Browse files Browse the repository at this point in the history
Can pass forward system args to rerun script. This will reduce the
verbosity of the copy/pasteable.

This makes the wrapper script pass the sys.argv to the test runner and
then the test runner can use that to recreate the  call that developers
most often use to run tests. This still supports using:
./build/android/test_runner.py gtest --output-directory .... directly.

This will reduce the rerun arg from a run of
   ./out/emulator/bin/run_crypto_unittests -v --break-on-failure

from:
build/android/test_runner.py gtest --output-directory out/emulator --runtime-deps-path out/emulator/gen.runtime/crypto/crypto_unittests__test_runner_script.runtime_deps --suite crypto_unittests -v --break-on-failure

to just:
  ./out/emulator/bin/run_crypto_unittests -v --break-on-failure

Bug: 917480
Change-Id: Ic84bb42541ec75e31839f902e8301f2bbd4e3cd5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3704958
Reviewed-by: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: Peter Wen <wnwen@chromium.org>
Commit-Queue: Benjamin Joyce <bjoyce@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1017398}
  • Loading branch information
Ben Joyce authored and Chromium LUCI CQ committed Jun 23, 2022
1 parent 9974a82 commit 109bb83
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
18 changes: 14 additions & 4 deletions build/android/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ def AddCommonOptions(parser):
action='store_true',
help='Whether to archive test output locally and generate '
'a local results detail page.')
parser.add_argument('--wrapper-script-args',
help='A string of args that were passed to the wrapper '
'script. This should probably not be edited by a '
'user as it is passed by the wrapper itself.')

class FastLocalDevAction(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
Expand Down Expand Up @@ -1061,8 +1065,10 @@ def upload_logcats_file():
annotation=getattr(args, 'annotations', None),
flakiness_server=getattr(args, 'flakiness_dashboard_server',
None))

if iteration_results.GetNotPass():
_LogRerunStatement(iteration_results.GetNotPass())
_LogRerunStatement(iteration_results.GetNotPass(),
args.wrapper_script_args)

if args.break_on_failure and not iteration_results.DidRunPass():
break
Expand Down Expand Up @@ -1130,14 +1136,16 @@ def upload_logcats_file():
else constants.ERROR_EXIT_CODE)


def _LogRerunStatement(failed_tests):
def _LogRerunStatement(failed_tests, wrapper_arg_str):
"""Logs a message that can rerun the failed tests.
Logs a copy/pasteable message that filters tests so just the failing tests
are run.
Args:
failed_tests: A set of test results that did not pass.
wrapper_arg_str: A string of args that were passed to the called wrapper
script.
"""
rerun_arg_list = []
try:
Expand All @@ -1150,9 +1158,11 @@ def _LogRerunStatement(failed_tests):

test_filter_file = os.path.join(os.path.relpath(constants.GetOutDirectory()),
_RERUN_FAILED_TESTS_FILE)
arg_list = shlex.split(
wrapper_arg_str.strip('\'')) if wrapper_arg_str else sys.argv
index = 0
while index < len(sys.argv):
arg = sys.argv[index]
while index < len(arg_list):
arg = arg_list[index]
# Skip adding the filter=<file> and/or the filter arg as we're replacing
# it with the new filter arg.
# This covers --test-filter=, --test-launcher-filter-file=, --gtest-filter=,
Expand Down
1 change: 1 addition & 0 deletions build/config/android/internal_rules.gni
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,7 @@ template("test_runner_script") {
_test_type,
"--output-directory",
"@WrappedPath(.)",
"--wrapper-script-args",
]

if (_runtime_deps) {
Expand Down
9 changes: 9 additions & 0 deletions build/util/generate_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
PY_TEMPLATE = textwrap.dedent("""\
import os
import re
import shlex
import subprocess
import sys
Expand Down Expand Up @@ -104,6 +105,13 @@ def FindIsolatedOutdir(raw_args):
outdir = os.environ['ISOLATED_OUTDIR']
return outdir, remaining_args
def InsertWrapperScriptArgs(args):
i = 0
while i < len(args):
if args[i] == '--wrapper-script-args':
args.insert(i + 1, "'%s'" % shlex.join(s for s in sys.argv))
break
i += 1
def FilterIsolatedOutdirBasedArgs(outdir, args):
rargs = []
Expand Down Expand Up @@ -142,6 +150,7 @@ def main(raw_args):
executable_path = ExpandWrappedPath('{executable_path}')
outdir, remaining_args = FindIsolatedOutdir(raw_args)
args = {executable_args}
InsertWrapperScriptArgs(args)
args = FilterIsolatedOutdirBasedArgs(outdir, args)
executable_args = ExpandWrappedPaths(args)
cmd = [executable_path] + args + remaining_args
Expand Down

0 comments on commit 109bb83

Please sign in to comment.