Commit df195fd5 authored by Ben Pastene's avatar Ben Pastene Committed by Commit Bot

Add a yapf style to //build/chromeos/ and auto-format all python files.

Format all the things!

Change-Id: I33f02e6e21c4388f381b35e06394fb916bfddddd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1891735
Commit-Queue: Ben Pastene <bpastene@chromium.org>
Reviewed-by: default avatarJohn Budorick <jbudorick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#711845}
parent 1a685434
[style]
based_on_style = chromium
# Copyright (c) 2013 The Chromium Authors. All rights reserved. # Copyright (c) 2013 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.
"""Presubmit script for build/chromeos/. """Presubmit script for build/chromeos/.
See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for
...@@ -11,9 +10,7 @@ details on the presubmit API built into depot_tools. ...@@ -11,9 +10,7 @@ details on the presubmit API built into depot_tools.
def CommonChecks(input_api, output_api): def CommonChecks(input_api, output_api):
return input_api.canned_checks.RunPylint( return input_api.canned_checks.RunPylint(
input_api, input_api, output_api, pylintrc='pylintrc')
output_api,
pylintrc='pylintrc')
def CheckChangeOnUpload(input_api, output_api): def CheckChangeOnUpload(input_api, output_api):
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
# 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.
"""Creates a script that runs a CrOS VM test by delegating to """Creates a script that runs a CrOS VM test by delegating to
build/chromeos/test_runner.py. build/chromeos/test_runner.py.
""" """
...@@ -12,7 +11,6 @@ import argparse ...@@ -12,7 +11,6 @@ import argparse
import os import os
import sys import sys
SCRIPT_TEMPLATE = """\ SCRIPT_TEMPLATE = """\
#!/usr/bin/env python #!/usr/bin/env python
# #
...@@ -90,7 +88,8 @@ def main(args): ...@@ -90,7 +88,8 @@ def main(args):
vm_test_args.append('--deploy-chrome') vm_test_args.append('--deploy-chrome')
vm_test_args += [ vm_test_args += [
'--board', args.board, '--board',
args.board,
'-v', '-v',
] ]
if args.use_vm: if args.use_vm:
...@@ -100,17 +99,18 @@ def main(args): ...@@ -100,17 +99,18 @@ def main(args):
('--cros-cache', RelativizePathToScript(args.cros_cache)), ('--cros-cache', RelativizePathToScript(args.cros_cache)),
] ]
if args.runtime_deps_path: if args.runtime_deps_path:
vm_test_path_args.append( vm_test_path_args.append(('--runtime-deps-path',
('--runtime-deps-path', RelativizePathToScript(args.runtime_deps_path))) RelativizePathToScript(args.runtime_deps_path)))
if args.output_directory: if args.output_directory:
vm_test_path_args.append( vm_test_path_args.append(('--path-to-outdir',
('--path-to-outdir', RelativizePathToScript(args.output_directory))) RelativizePathToScript(args.output_directory)))
with open(args.script_output_path, 'w') as script: with open(args.script_output_path, 'w') as script:
script.write(SCRIPT_TEMPLATE.format( script.write(
vm_test_script=run_test_path, SCRIPT_TEMPLATE.format(
vm_test_args=str(vm_test_args), vm_test_script=run_test_path,
vm_test_path_args=str(vm_test_path_args))) vm_test_args=str(vm_test_args),
vm_test_path_args=str(vm_test_path_args)))
os.chmod(args.script_output_path, 0750) os.chmod(args.script_output_path, 0750)
......
...@@ -22,8 +22,8 @@ import dateutil.parser # pylint: disable=import-error ...@@ -22,8 +22,8 @@ import dateutil.parser # pylint: disable=import-error
import jsonlines # pylint: disable=import-error import jsonlines # pylint: disable=import-error
import psutil # pylint: disable=import-error import psutil # pylint: disable=import-error
CHROMIUM_SRC_PATH = os.path.abspath(os.path.join( CHROMIUM_SRC_PATH = os.path.abspath(
os.path.dirname(__file__), '..', '..')) os.path.join(os.path.dirname(__file__), '..', '..'))
# Use the android test-runner's gtest results support library for generating # Use the android test-runner's gtest results support library for generating
# output json ourselves. # output json ourselves.
...@@ -36,12 +36,12 @@ sys.path.insert( ...@@ -36,12 +36,12 @@ sys.path.insert(
0, os.path.join(CHROMIUM_SRC_PATH, 'tools', 'swarming_client', 'utils')) 0, os.path.join(CHROMIUM_SRC_PATH, 'tools', 'swarming_client', 'utils'))
import subprocess42 # pylint: disable=import-error import subprocess42 # pylint: disable=import-error
DEFAULT_CROS_CACHE = os.path.abspath(os.path.join( DEFAULT_CROS_CACHE = os.path.abspath(
CHROMIUM_SRC_PATH, 'build', 'cros_cache')) os.path.join(CHROMIUM_SRC_PATH, 'build', 'cros_cache'))
CHROMITE_PATH = os.path.abspath(os.path.join( CHROMITE_PATH = os.path.abspath(
CHROMIUM_SRC_PATH, 'third_party', 'chromite')) os.path.join(CHROMIUM_SRC_PATH, 'third_party', 'chromite'))
CROS_RUN_TEST_PATH = os.path.abspath(os.path.join( CROS_RUN_TEST_PATH = os.path.abspath(
CHROMITE_PATH, 'bin', 'cros_run_test')) os.path.join(CHROMITE_PATH, 'bin', 'cros_run_test'))
# GN target that corresponds to the cros browser sanity test. # GN target that corresponds to the cros browser sanity test.
SANITY_TEST_TARGET = 'cros_browser_sanity_test' SANITY_TEST_TARGET = 'cros_browser_sanity_test'
...@@ -68,15 +68,15 @@ class RemoteTest(object): ...@@ -68,15 +68,15 @@ class RemoteTest(object):
# This is a basic shell script that can be appended to in order to invoke the # This is a basic shell script that can be appended to in order to invoke the
# test on the device. # test on the device.
BASIC_SHELL_SCRIPT = [ BASIC_SHELL_SCRIPT = [
'#!/bin/sh', '#!/bin/sh',
# /home and /tmp are mounted with "noexec" in the device, but some of our # /home and /tmp are mounted with "noexec" in the device, but some of our
# tools and tests use those dirs as a workspace (eg: vpython downloads # tools and tests use those dirs as a workspace (eg: vpython downloads
# python binaries to ~/.vpython-root and /tmp/vpython_bootstrap). # python binaries to ~/.vpython-root and /tmp/vpython_bootstrap).
# /usr/local/tmp doesn't have this restriction, so change the location of # /usr/local/tmp doesn't have this restriction, so change the location of
# the home and temp dirs for the duration of the test. # the home and temp dirs for the duration of the test.
'export HOME=/usr/local/tmp', 'export HOME=/usr/local/tmp',
'export TMPDIR=/usr/local/tmp', 'export TMPDIR=/usr/local/tmp',
] ]
def __init__(self, args, unknown_args): def __init__(self, args, unknown_args):
...@@ -96,15 +96,18 @@ class RemoteTest(object): ...@@ -96,15 +96,18 @@ class RemoteTest(object):
self._test_cmd = [ self._test_cmd = [
CROS_RUN_TEST_PATH, CROS_RUN_TEST_PATH,
'--board', args.board, '--board',
'--cache-dir', args.cros_cache, args.board,
'--cache-dir',
args.cros_cache,
] ]
if args.use_vm: if args.use_vm:
self._test_cmd += [ self._test_cmd += [
'--start', '--start',
# Don't persist any filesystem changes after the VM shutsdown. # Don't persist any filesystem changes after the VM shutsdown.
'--copy-on-write', '--copy-on-write',
'--device', 'localhost' '--device',
'localhost'
] ]
else: else:
self._test_cmd += [ self._test_cmd += [
...@@ -127,9 +130,7 @@ class RemoteTest(object): ...@@ -127,9 +130,7 @@ class RemoteTest(object):
self._llvm_profile_var = '/tmp/profraw/%s' % llvm_profile_file self._llvm_profile_var = '/tmp/profraw/%s' % llvm_profile_file
# This should make the vm test runner exfil the profiling data. # This should make the vm test runner exfil the profiling data.
self._test_cmd += [ self._test_cmd += ['--results-src', '/tmp/profraw']
'--results-src', '/tmp/profraw'
]
self._test_env = setup_env() self._test_env = setup_env()
...@@ -146,7 +147,8 @@ class RemoteTest(object): ...@@ -146,7 +147,8 @@ class RemoteTest(object):
# set cwd. # set cwd.
self._test_cmd += [ self._test_cmd += [
'--remote-cmd', '--remote-cmd',
'--cwd', os.path.relpath(self._path_to_outdir, CHROMIUM_SRC_PATH), '--cwd',
os.path.relpath(self._path_to_outdir, CHROMIUM_SRC_PATH),
] ]
logging.info('Running the following command on the device:') logging.info('Running the following command on the device:')
logging.info('\n' + '\n'.join(script_contents)) logging.info('\n' + '\n'.join(script_contents))
...@@ -162,10 +164,10 @@ class RemoteTest(object): ...@@ -162,10 +164,10 @@ class RemoteTest(object):
# and gets timeout-killed by swarming. See also: # and gets timeout-killed by swarming. See also:
# https://chromium.googlesource.com/infra/luci/luci-py/+/master/appengine/swarming/doc/Bot.md#graceful-termination_aka-the-sigterm-and-sigkill-dance # https://chromium.googlesource.com/infra/luci/luci-py/+/master/appengine/swarming/doc/Bot.md#graceful-termination_aka-the-sigterm-and-sigkill-dance
test_proc = None test_proc = None
def _kill_child_procs(trapped_signal, _): def _kill_child_procs(trapped_signal, _):
logging.warning( logging.warning('Received signal %d. Killing child processes of test.',
'Received signal %d. Killing child processes of test.', trapped_signal)
trapped_signal)
if not test_proc or not test_proc.pid: if not test_proc or not test_proc.pid:
# This shouldn't happen? # This shouldn't happen?
logging.error('Test process not running.') logging.error('Test process not running.')
...@@ -176,12 +178,14 @@ class RemoteTest(object): ...@@ -176,12 +178,14 @@ class RemoteTest(object):
signal.signal(signal.SIGTERM, _kill_child_procs) signal.signal(signal.SIGTERM, _kill_child_procs)
for i in xrange(self._retries+1): for i in xrange(self._retries + 1):
logging.info('########################################') logging.info('########################################')
logging.info('Test attempt #%d', i) logging.info('Test attempt #%d', i)
logging.info('########################################') logging.info('########################################')
test_proc = subprocess42.Popen( test_proc = subprocess42.Popen(
self._test_cmd, stdout=sys.stdout, stderr=sys.stderr, self._test_cmd,
stdout=sys.stdout,
stderr=sys.stderr,
env=self._test_env) env=self._test_env)
try: try:
test_proc.wait(timeout=self._timeout) test_proc.wait(timeout=self._timeout)
...@@ -214,8 +218,9 @@ class RemoteTest(object): ...@@ -214,8 +218,9 @@ class RemoteTest(object):
# only one test (suite_name), and will either be a PASS or FAIL depending on # only one test (suite_name), and will either be a PASS or FAIL depending on
# return_code. # return_code.
if self._test_launcher_summary_output: if self._test_launcher_summary_output:
result = (base_test_result.ResultType.FAIL if return_code else result = (
base_test_result.ResultType.PASS) base_test_result.ResultType.FAIL
if return_code else base_test_result.ResultType.PASS)
suite_result = base_test_result.BaseTestResult(self.suite_name, result) suite_result = base_test_result.BaseTestResult(self.suite_name, result)
run_results = base_test_result.TestRunResults() run_results = base_test_result.TestRunResults()
run_results.AddResult(suite_result) run_results.AddResult(suite_result)
...@@ -245,17 +250,17 @@ class TastTest(RemoteTest): ...@@ -245,17 +250,17 @@ class TastTest(RemoteTest):
def build_test_command(self): def build_test_command(self):
if '--gtest_filter=%s' % self.suite_name in self._additional_args: if '--gtest_filter=%s' % self.suite_name in self._additional_args:
logging.info( logging.info('GTest filtering not supported for tast tests. The '
'GTest filtering not supported for tast tests. The ' '--gtest_filter arg will be ignored.')
'--gtest_filter arg will be ignored.')
self._additional_args.remove('--gtest_filter=%s' % self.suite_name) self._additional_args.remove('--gtest_filter=%s' % self.suite_name)
if any(arg.startswith('--gtest_repeat') for arg in self._additional_args): if any(arg.startswith('--gtest_repeat') for arg in self._additional_args):
logging.info( logging.info(
'--gtest_repeat not supported for tast tests. The arg will be ' '--gtest_repeat not supported for tast tests. The arg will be '
'ignored.') 'ignored.')
self._additional_args = [ self._additional_args = [
arg for arg in self._additional_args if not arg.startswith( arg for arg in self._additional_args
'--gtest_repeat')] if not arg.startswith('--gtest_repeat')
]
if self._additional_args: if self._additional_args:
logging.error( logging.error(
...@@ -265,7 +270,8 @@ class TastTest(RemoteTest): ...@@ -265,7 +270,8 @@ class TastTest(RemoteTest):
self._test_cmd += [ self._test_cmd += [
'--deploy', '--deploy',
'--mount', '--mount',
'--build-dir', os.path.relpath(self._path_to_outdir, CHROMIUM_SRC_PATH), '--build-dir',
os.path.relpath(self._path_to_outdir, CHROMIUM_SRC_PATH),
] ]
# Coverage tests require some special pre-test setup, so use an # Coverage tests require some special pre-test setup, so use an
...@@ -276,8 +282,8 @@ class TastTest(RemoteTest): ...@@ -276,8 +282,8 @@ class TastTest(RemoteTest):
# test. # test.
device_test_script_contents = self.BASIC_SHELL_SCRIPT[:] device_test_script_contents = self.BASIC_SHELL_SCRIPT[:]
device_test_script_contents += [ device_test_script_contents += [
'echo "LLVM_PROFILE_FILE=%s" >> /etc/chrome_dev.conf' % ( 'echo "LLVM_PROFILE_FILE=%s" >> /etc/chrome_dev.conf' %
self._llvm_profile_var) (self._llvm_profile_var)
] ]
local_test_runner_cmd = ['local_test_runner', '-waituntilready'] local_test_runner_cmd = ['local_test_runner', '-waituntilready']
...@@ -295,8 +301,8 @@ class TastTest(RemoteTest): ...@@ -295,8 +301,8 @@ class TastTest(RemoteTest):
device_test_script_contents) device_test_script_contents)
self._test_cmd += [ self._test_cmd += [
'--files', os.path.relpath(self._on_device_script), '--files',
'--', os.path.relpath(self._on_device_script), '--',
'./' + os.path.relpath(self._on_device_script, self._path_to_outdir) './' + os.path.relpath(self._on_device_script, self._path_to_outdir)
] ]
else: else:
...@@ -306,7 +312,8 @@ class TastTest(RemoteTest): ...@@ -306,7 +312,8 @@ class TastTest(RemoteTest):
# Capture tast's results in the logs dir as well. # Capture tast's results in the logs dir as well.
if self._logs_dir: if self._logs_dir:
self._test_cmd += [ self._test_cmd += [
'--results-dir', self._logs_dir, '--results-dir',
self._logs_dir,
] ]
if self._conditional: if self._conditional:
# Don't use pipes.quote() here. Something funky happens with the arg # Don't use pipes.quote() here. Something funky happens with the arg
...@@ -327,8 +334,8 @@ class TastTest(RemoteTest): ...@@ -327,8 +334,8 @@ class TastTest(RemoteTest):
tast_results_path = os.path.join(self._logs_dir, 'streamed_results.jsonl') tast_results_path = os.path.join(self._logs_dir, 'streamed_results.jsonl')
if not os.path.exists(tast_results_path): if not os.path.exists(tast_results_path):
logging.error( logging.error(
'Tast results not found at %s. Falling back to generic result ' 'Tast results not found at %s. Falling back to generic result '
'reporting.', tast_results_path) 'reporting.', tast_results_path)
return super(TastTest, self).post_run(return_code) return super(TastTest, self).post_run(return_code)
# See the link below for the format of the results: # See the link below for the format of the results:
...@@ -357,8 +364,8 @@ class TastTest(RemoteTest): ...@@ -357,8 +364,8 @@ class TastTest(RemoteTest):
for err in errors: for err in errors:
error_log += err['stack'].encode('utf-8') + '\n' error_log += err['stack'].encode('utf-8') + '\n'
error_log += ( error_log += (
"\nIf you're unsure why this test failed, consult the steps " "\nIf you're unsure why this test failed, consult the steps "
'outlined in\n%s\n' % TAST_DEBUG_DOC) 'outlined in\n%s\n' % TAST_DEBUG_DOC)
base_result = base_test_result.BaseTestResult( base_result = base_test_result.BaseTestResult(
test['name'], result, duration=duration_ms, log=error_log) test['name'], result, duration=duration_ms, log=error_log)
suite_results.AddResult(base_result) suite_results.AddResult(base_result)
...@@ -377,7 +384,6 @@ class TastTest(RemoteTest): ...@@ -377,7 +384,6 @@ class TastTest(RemoteTest):
return 0 return 0
class GTestTest(RemoteTest): class GTestTest(RemoteTest):
# The following list corresponds to paths that should not be copied over to # The following list corresponds to paths that should not be copied over to
...@@ -431,35 +437,34 @@ class GTestTest(RemoteTest): ...@@ -431,35 +437,34 @@ class GTestTest(RemoteTest):
result_dir = '.' result_dir = '.'
device_result_file = '/tmp/%s' % result_file device_result_file = '/tmp/%s' % result_file
self._test_cmd += [ self._test_cmd += [
'--results-src', device_result_file, '--results-src',
'--results-dest-dir', result_dir, device_result_file,
'--results-dest-dir',
result_dir,
] ]
# Build the shell script that will be used on the device to invoke the test. # Build the shell script that will be used on the device to invoke the test.
device_test_script_contents = self.BASIC_SHELL_SCRIPT[:] device_test_script_contents = self.BASIC_SHELL_SCRIPT[:]
if self._llvm_profile_var: if self._llvm_profile_var:
device_test_script_contents += [ device_test_script_contents += [
'export LLVM_PROFILE_FILE=%s'% self._llvm_profile_var, 'export LLVM_PROFILE_FILE=%s' % self._llvm_profile_var,
] ]
if self._vpython_dir: if self._vpython_dir:
vpython_spec_path = os.path.relpath( vpython_spec_path = os.path.relpath(
os.path.join(CHROMIUM_SRC_PATH, '.vpython'), os.path.join(CHROMIUM_SRC_PATH, '.vpython'), self._path_to_outdir)
self._path_to_outdir)
# Initialize the vpython cache. This can take 10-20s, and some tests # Initialize the vpython cache. This can take 10-20s, and some tests
# can't afford to wait that long on the first invocation. # can't afford to wait that long on the first invocation.
device_test_script_contents.extend([ device_test_script_contents.extend([
'export PATH=$PATH:$PWD/%s' % (self._vpython_dir), 'export PATH=$PATH:$PWD/%s' % (self._vpython_dir),
'vpython -vpython-spec %s -vpython-tool install' % ( 'vpython -vpython-spec %s -vpython-tool install' %
vpython_spec_path), (vpython_spec_path),
]) ])
test_invocation = ( test_invocation = ('LD_LIBRARY_PATH=./ ./%s --test-launcher-shard-index=%d '
'LD_LIBRARY_PATH=./ ./%s --test-launcher-shard-index=%d ' '--test-launcher-total-shards=%d' %
'--test-launcher-total-shards=%d' % ( (self._test_exe, self._test_launcher_shard_index,
self._test_exe, self._test_launcher_shard_index, self._test_launcher_total_shards))
self._test_launcher_total_shards)
)
if self._test_launcher_summary_output: if self._test_launcher_summary_output:
test_invocation += ' --test-launcher-summary-output=%s' % ( test_invocation += ' --test-launcher-summary-output=%s' % (
device_result_file) device_result_file)
...@@ -496,8 +501,8 @@ class GTestTest(RemoteTest): ...@@ -496,8 +501,8 @@ class GTestTest(RemoteTest):
# relative to src dir, so fix the path up a bit. # relative to src dir, so fix the path up a bit.
runtime_files.append( runtime_files.append(
os.path.relpath( os.path.relpath(
os.path.abspath(os.path.join(self._path_to_outdir, os.path.abspath(
self._vpython_dir)), os.path.join(self._path_to_outdir, self._vpython_dir)),
CHROMIUM_SRC_PATH)) CHROMIUM_SRC_PATH))
# TODO(bpastene): Add the vpython spec to the test's runtime deps instead # TODO(bpastene): Add the vpython spec to the test's runtime deps instead
# of handling it here. # of handling it here.
...@@ -547,17 +552,17 @@ class BrowserSanityTest(RemoteTest): ...@@ -547,17 +552,17 @@ class BrowserSanityTest(RemoteTest):
def build_test_command(self): def build_test_command(self):
if '--gtest_filter=%s' % SANITY_TEST_TARGET in self._additional_args: if '--gtest_filter=%s' % SANITY_TEST_TARGET in self._additional_args:
logging.info( logging.info('GTest filtering not supported for the sanity test. The '
'GTest filtering not supported for the sanity test. The ' '--gtest_filter arg will be ignored.')
'--gtest_filter arg will be ignored.')
self._additional_args.remove('--gtest_filter=%s' % SANITY_TEST_TARGET) self._additional_args.remove('--gtest_filter=%s' % SANITY_TEST_TARGET)
if any(arg.startswith('--gtest_repeat') for arg in self._additional_args): if any(arg.startswith('--gtest_repeat') for arg in self._additional_args):
logging.info( logging.info(
'--gtest_repeat not supported for sanity test. The arg will be ' '--gtest_repeat not supported for sanity test. The arg will be '
'ignored.') 'ignored.')
self._additional_args = [ self._additional_args = [
arg for arg in self._additional_args if not arg.startswith( arg for arg in self._additional_args
'--gtest_repeat')] if not arg.startswith('--gtest_repeat')
]
if self._additional_args: if self._additional_args:
logging.error( logging.error(
...@@ -572,8 +577,8 @@ class BrowserSanityTest(RemoteTest): ...@@ -572,8 +577,8 @@ class BrowserSanityTest(RemoteTest):
device_test_script_contents = self.BASIC_SHELL_SCRIPT[:] device_test_script_contents = self.BASIC_SHELL_SCRIPT[:]
if self._llvm_profile_var: if self._llvm_profile_var:
device_test_script_contents += [ device_test_script_contents += [
'echo "LLVM_PROFILE_FILE=%s" >> /etc/chrome_dev.conf' % ( 'echo "LLVM_PROFILE_FILE=%s" >> /etc/chrome_dev.conf' %
self._llvm_profile_var) (self._llvm_profile_var)
] ]
# vm_sanity.py is the sanity test, which is baked into the device image. # vm_sanity.py is the sanity test, which is baked into the device image.
...@@ -583,12 +588,14 @@ class BrowserSanityTest(RemoteTest): ...@@ -583,12 +588,14 @@ class BrowserSanityTest(RemoteTest):
device_test_script_contents) device_test_script_contents)
self._test_cmd += [ self._test_cmd += [
'--files', os.path.relpath(self._on_device_script), '--files',
os.path.relpath(self._on_device_script),
# The sanity test smoke-checks the system browser, so deploy our # The sanity test smoke-checks the system browser, so deploy our
# locally-built chrome to the device before testing. # locally-built chrome to the device before testing.
'--deploy', '--deploy',
'--mount', '--mount',
'--build-dir', os.path.relpath(self._path_to_outdir, CHROMIUM_SRC_PATH), '--build-dir',
os.path.relpath(self._path_to_outdir, CHROMIUM_SRC_PATH),
'--', '--',
'./' + os.path.relpath(self._on_device_script, self._path_to_outdir) './' + os.path.relpath(self._on_device_script, self._path_to_outdir)
] ]
...@@ -621,23 +628,26 @@ def host_cmd(args, unknown_args): ...@@ -621,23 +628,26 @@ def host_cmd(args, unknown_args):
raise TestFormatError('Must specify command to run on the host.') raise TestFormatError('Must specify command to run on the host.')
elif unknown_args: elif unknown_args:
raise TestFormatError( raise TestFormatError(
'Args "%s" unsupported. Is your host command correctly formatted?' % ( 'Args "%s" unsupported. Is your host command correctly formatted?' %
' '.join(unknown_args))) (' '.join(unknown_args)))
elif args.deploy_chrome and not args.path_to_outdir: elif args.deploy_chrome and not args.path_to_outdir:
raise TestFormatError( raise TestFormatError(
'--path-to-outdir must be specified if --deploy-chrome is passed.') '--path-to-outdir must be specified if --deploy-chrome is passed.')
cros_run_test_cmd = [ cros_run_test_cmd = [
CROS_RUN_TEST_PATH, CROS_RUN_TEST_PATH,
'--board', args.board, '--board',
'--cache-dir', args.cros_cache, args.board,
'--cache-dir',
args.cros_cache,
] ]
if args.use_vm: if args.use_vm:
cros_run_test_cmd += [ cros_run_test_cmd += [
'--start', '--start',
# Don't persist any filesystem changes after the VM shutsdown. # Don't persist any filesystem changes after the VM shutsdown.
'--copy-on-write', '--copy-on-write',
'--device', 'localhost', '--device',
'localhost',
] ]
else: else:
cros_run_test_cmd += [ cros_run_test_cmd += [
...@@ -658,7 +668,8 @@ def host_cmd(args, unknown_args): ...@@ -658,7 +668,8 @@ def host_cmd(args, unknown_args):
# Mounting the browser gives it enough disk space to not need stripping. # Mounting the browser gives it enough disk space to not need stripping.
'--mount', '--mount',
'--nostrip', '--nostrip',
'--build-dir', os.path.abspath(args.path_to_outdir), '--build-dir',
os.path.abspath(args.path_to_outdir),
] ]
cros_run_test_cmd += [ cros_run_test_cmd += [
...@@ -697,36 +708,47 @@ def add_common_args(*parsers): ...@@ -697,36 +708,47 @@ def add_common_args(*parsers):
parser.add_argument( parser.add_argument(
'--board', type=str, required=True, help='Type of CrOS device.') '--board', type=str, required=True, help='Type of CrOS device.')
parser.add_argument( parser.add_argument(
'--cros-cache', type=str, default=DEFAULT_CROS_CACHE, '--cros-cache',
type=str,
default=DEFAULT_CROS_CACHE,
help='Path to cros cache.') help='Path to cros cache.')
parser.add_argument( parser.add_argument(
'--path-to-outdir', type=str, required=True, '--path-to-outdir',
type=str,
required=True,
help='Path to output directory, all of whose contents will be ' help='Path to output directory, all of whose contents will be '
'deployed to the device.') 'deployed to the device.')
parser.add_argument( parser.add_argument(
'--runtime-deps-path', type=str, '--runtime-deps-path',
type=str,
help='Runtime data dependency file from GN.') help='Runtime data dependency file from GN.')
parser.add_argument( parser.add_argument(
'--vpython-dir', type=str, '--vpython-dir',
type=str,
help='Location on host of a directory containing a vpython binary to ' help='Location on host of a directory containing a vpython binary to '
'deploy to the device before the test starts. The location of ' 'deploy to the device before the test starts. The location of '
'this dir will be added onto PATH in the device. WARNING: The ' 'this dir will be added onto PATH in the device. WARNING: The '
'arch of the device might not match the arch of the host, so ' 'arch of the device might not match the arch of the host, so '
'avoid using "${platform}" when downloading vpython via CIPD.') 'avoid using "${platform}" when downloading vpython via CIPD.')
# TODO(bpastene): Switch all uses of "--vm-logs-dir" to "--logs-dir". # TODO(bpastene): Switch all uses of "--vm-logs-dir" to "--logs-dir".
parser.add_argument( parser.add_argument(
'--vm-logs-dir', '--logs-dir', type=str, dest='logs_dir', '--vm-logs-dir',
'--logs-dir',
type=str,
dest='logs_dir',
help='Will copy everything under /var/log/ from the device after the ' help='Will copy everything under /var/log/ from the device after the '
'test into the specified dir.') 'test into the specified dir.')
vm_or_device_group = parser.add_mutually_exclusive_group() vm_or_device_group = parser.add_mutually_exclusive_group()
vm_or_device_group.add_argument( vm_or_device_group.add_argument(
'--use-vm', action='store_true', '--use-vm',
action='store_true',
help='Will run the test in the VM instead of a device.') help='Will run the test in the VM instead of a device.')
vm_or_device_group.add_argument( vm_or_device_group.add_argument(
'--device', type=str, '--device',
type=str,
help='Hostname (or IP) of device to run the test on. This arg is not ' help='Hostname (or IP) of device to run the test on. This arg is not '
'required if --use-vm is set.') 'required if --use-vm is set.')
def main(): def main():
...@@ -736,46 +758,52 @@ def main(): ...@@ -736,46 +758,52 @@ def main():
host_cmd_parser = subparsers.add_parser( host_cmd_parser = subparsers.add_parser(
'host-cmd', 'host-cmd',
help='Runs a host-side test. Pass the host-side command to run after ' help='Runs a host-side test. Pass the host-side command to run after '
'"--". If --use-vm is passed, hostname and port for the device ' '"--". If --use-vm is passed, hostname and port for the device '
'will be 127.0.0.1:9222.') 'will be 127.0.0.1:9222.')
host_cmd_parser.set_defaults(func=host_cmd) host_cmd_parser.set_defaults(func=host_cmd)
host_cmd_parser.add_argument( host_cmd_parser.add_argument(
'--deploy-chrome', action='store_true', '--deploy-chrome',
action='store_true',
help='Will deploy a locally built Chrome binary to the device before ' help='Will deploy a locally built Chrome binary to the device before '
'running the host-cmd.') 'running the host-cmd.')
host_cmd_parser.add_argument('cmd', nargs=argparse.REMAINDER) host_cmd_parser.add_argument('cmd', nargs=argparse.REMAINDER)
# GTest args. # GTest args.
# TODO(bpastene): Rename 'vm-test' arg to 'gtest'. # TODO(bpastene): Rename 'vm-test' arg to 'gtest'.
gtest_parser = subparsers.add_parser( gtest_parser = subparsers.add_parser(
'vm-test', 'vm-test', help='Runs a device-side gtest.')
help='Runs a device-side gtest.')
gtest_parser.set_defaults(func=device_test) gtest_parser.set_defaults(func=device_test)
gtest_parser.add_argument( gtest_parser.add_argument(
'--test-exe', type=str, required=True, '--test-exe',
type=str,
required=True,
help='Path to test executable to run inside the device. If the value is ' help='Path to test executable to run inside the device. If the value is '
'%s, the sanity test that ships with the device image runs instead. ' '%s, the sanity test that ships with the device image runs instead. '
'This test smokes-check the system browser (eg: loads a simple ' 'This test smokes-check the system browser (eg: loads a simple '
'webpage, executes some javascript), so a fully-built Chrome binary ' 'webpage, executes some javascript), so a fully-built Chrome binary '
'that can get deployed to the device is expected to be available in ' 'that can get deployed to the device is expected to be available in '
'the out-dir.' % SANITY_TEST_TARGET) 'the out-dir.' % SANITY_TEST_TARGET)
# GTest args. Some are passed down to the test binary in the device. Others # GTest args. Some are passed down to the test binary in the device. Others
# are parsed here since they might need tweaking or special handling. # are parsed here since they might need tweaking or special handling.
gtest_parser.add_argument( gtest_parser.add_argument(
'--test-launcher-summary-output', type=str, '--test-launcher-summary-output',
type=str,
help='When set, will pass the same option down to the test and retrieve ' help='When set, will pass the same option down to the test and retrieve '
'its result file at the specified location.') 'its result file at the specified location.')
# Shard args are parsed here since we might also specify them via env vars. # Shard args are parsed here since we might also specify them via env vars.
gtest_parser.add_argument( gtest_parser.add_argument(
'--test-launcher-shard-index', '--test-launcher-shard-index',
type=int, default=os.environ.get('GTEST_SHARD_INDEX', 0), type=int,
default=os.environ.get('GTEST_SHARD_INDEX', 0),
help='Index of the external shard to run.') help='Index of the external shard to run.')
gtest_parser.add_argument( gtest_parser.add_argument(
'--test-launcher-total-shards', '--test-launcher-total-shards',
type=int, default=os.environ.get('GTEST_TOTAL_SHARDS', 1), type=int,
default=os.environ.get('GTEST_TOTAL_SHARDS', 1),
help='Total number of external shards.') help='Total number of external shards.')
gtest_parser.add_argument( gtest_parser.add_argument(
'--stop-ui', action='store_true', '--stop-ui',
action='store_true',
help='Will stop the UI service in the device before running the test.') help='Will stop the UI service in the device before running the test.')
# Tast test args. # Tast test args.
...@@ -783,23 +811,33 @@ def main(): ...@@ -783,23 +811,33 @@ def main():
tast_test_parser = subparsers.add_parser( tast_test_parser = subparsers.add_parser(
'tast', 'tast',
help='Runs a device-side set of Tast tests. For more details, see: ' help='Runs a device-side set of Tast tests. For more details, see: '
'https://chromium.googlesource.com/chromiumos/platform/tast/+/master/docs/running_tests.md') 'https://chromium.googlesource.com/chromiumos/platform/tast/+/master/docs/running_tests.md'
)
tast_test_parser.set_defaults(func=device_test) tast_test_parser.set_defaults(func=device_test)
tast_test_parser.add_argument( tast_test_parser.add_argument(
'--suite-name', type=str, required=True, '--suite-name',
type=str,
required=True,
help='Name to apply to the set of Tast tests to run. This has no effect ' help='Name to apply to the set of Tast tests to run. This has no effect '
'on what is executed, but is used mainly for test results reporting ' 'on what is executed, but is used mainly for test results reporting '
'and tracking (eg: flakiness dashboard).') 'and tracking (eg: flakiness dashboard).')
tast_test_parser.add_argument( tast_test_parser.add_argument(
'--test-launcher-summary-output', type=str, '--test-launcher-summary-output',
type=str,
help='Generates a simple GTest-style JSON result file for the test run.') help='Generates a simple GTest-style JSON result file for the test run.')
# TODO(bpastene): Change all uses of "--conditional" to use "--attr-expr". # TODO(bpastene): Change all uses of "--conditional" to use "--attr-expr".
tast_test_parser.add_argument( tast_test_parser.add_argument(
'--conditional', '--attr-expr', type=str, dest='conditional', '--conditional',
'--attr-expr',
type=str,
dest='conditional',
help='A boolean expression whose matching tests will run ' help='A boolean expression whose matching tests will run '
'(eg: ("dep:chrome")).') '(eg: ("dep:chrome")).')
tast_test_parser.add_argument( tast_test_parser.add_argument(
'--test', '-t', action='append', dest='tests', '--test',
'-t',
action='append',
dest='tests',
help='A Tast test to run in the device (eg: "ui.ChromeLogin").') help='A Tast test to run in the device (eg: "ui.ChromeLogin").')
add_common_args(gtest_parser, tast_test_parser, host_cmd_parser) add_common_args(gtest_parser, tast_test_parser, host_cmd_parser)
...@@ -815,8 +853,8 @@ def main(): ...@@ -815,8 +853,8 @@ def main():
try: try:
socket.getaddrinfo(LAB_DUT_HOSTNAME, None) socket.getaddrinfo(LAB_DUT_HOSTNAME, None)
except socket.gaierror: except socket.gaierror:
logging.error( logging.error('The default DUT hostname of %s is unreachable.',
'The default DUT hostname of %s is unreachable.', LAB_DUT_HOSTNAME) LAB_DUT_HOSTNAME)
return 1 return 1
if args.use_vm: if args.use_vm:
if not os.path.exists('/dev/kvm'): if not os.path.exists('/dev/kvm'):
......
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