Commit 83b500c1 authored by Ben Pastene's avatar Ben Pastene Committed by Commit Bot

Add a sanity-test mode to the cros vm test runner.

When a test command is specified, the run_cros_vm_test will run the vm
sanity test. This test is baked into the VM and smoke checks the system
browser by loading empty pages and running some simple javascript.

Since it depends on the system browser, we need to first deploy a locally
built Chrome to the VM (via the --deploy arg). The deploy script needs to
know the gn args that built the browser to know which libs to copy over.
Since we don't have the full set of args at test-time, give it a dummy
set of args to trigger the default deploying behavior.

Bug: 832374
Change-Id: I84f7fdd94672fcb220eaa4d9625395c1d0ab7636
Reviewed-on: https://chromium-review.googlesource.com/1050981
Commit-Queue: Ben Pastene <bpastene@chromium.org>
Reviewed-by: default avatarDirk Pranke <dpranke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#558372}
parent 78aa0578
...@@ -82,22 +82,29 @@ def host_cmd(args): ...@@ -82,22 +82,29 @@ def host_cmd(args):
def vm_test(args): def vm_test(args):
is_sanity_test = args.test_exe == 'cros_vm_sanity_test'
cros_run_vm_test_cmd = [ cros_run_vm_test_cmd = [
CROS_RUN_VM_TEST_PATH, CROS_RUN_VM_TEST_PATH,
'--start', '--start',
'--board', args.board, '--board', args.board,
'--cache-dir', args.cros_cache, '--cache-dir', args.cros_cache,
'--cwd', os.path.relpath(args.path_to_outdir, CHROMIUM_SRC_PATH),
] ]
# cros_run_vm_test has trouble with relative paths that go up directories, so # cros_run_vm_test has trouble with relative paths that go up directories, so
# cd to src/, which should be the root of all data deps. # cd to src/, which should be the root of all data deps.
os.chdir(CHROMIUM_SRC_PATH) os.chdir(CHROMIUM_SRC_PATH)
for f in read_runtime_files(args.runtime_deps_path, args.path_to_outdir): runtime_files = read_runtime_files(
args.runtime_deps_path, args.path_to_outdir)
# If we're pushing files, we need to set the cwd.
if runtime_files:
cros_run_vm_test_cmd.extend(
['--cwd', os.path.relpath(args.path_to_outdir, CHROMIUM_SRC_PATH)])
for f in runtime_files:
cros_run_vm_test_cmd.extend(['--files', f]) cros_run_vm_test_cmd.extend(['--files', f])
if args.test_launcher_summary_output: if args.test_launcher_summary_output and not is_sanity_test:
result_dir, result_file = os.path.split(args.test_launcher_summary_output) result_dir, result_file = os.path.split(args.test_launcher_summary_output)
# If args.test_launcher_summary_output is a file in cwd, result_dir will be # If args.test_launcher_summary_output is a file in cwd, result_dir will be
# an empty string, so replace it with '.' when this is the case so # an empty string, so replace it with '.' when this is the case so
...@@ -110,15 +117,24 @@ def vm_test(args): ...@@ -110,15 +117,24 @@ def vm_test(args):
'--results-dest-dir', result_dir, '--results-dest-dir', result_dir,
] ]
cros_run_vm_test_cmd += [ if is_sanity_test:
'--cmd', # run_cros_vm_test's default behavior when no cmd is specified is the sanity
'--', # test that's baked into the VM image. This test smoke-checks the system
'./' + args.test_exe, # browser, so deploy our locally-built chrome to the VM before testing.
'--test-launcher-shard-index=%d' % args.test_launcher_shard_index, cros_run_vm_test_cmd += [
'--test-launcher-total-shards=%d' % args.test_launcher_total_shards, '--deploy',
] '--build-dir', os.path.relpath(args.path_to_outdir, CHROMIUM_SRC_PATH),
]
else:
cros_run_vm_test_cmd += [
'--cmd',
'--',
'./' + args.test_exe,
'--test-launcher-shard-index=%d' % args.test_launcher_shard_index,
'--test-launcher-total-shards=%d' % args.test_launcher_total_shards,
]
if args.test_launcher_summary_output: if args.test_launcher_summary_output and not is_sanity_test:
cros_run_vm_test_cmd += [ cros_run_vm_test_cmd += [
'--test-launcher-summary-output=%s' % vm_result_file, '--test-launcher-summary-output=%s' % vm_result_file,
] ]
...@@ -126,8 +142,18 @@ def vm_test(args): ...@@ -126,8 +142,18 @@ def vm_test(args):
logging.info('Running the following command:') logging.info('Running the following command:')
logging.info(' '.join(cros_run_vm_test_cmd)) logging.info(' '.join(cros_run_vm_test_cmd))
# deploy_chrome needs a set of GN args used to build chrome to determine if
# certain libraries need to be pushed to the VM. It looks for the args via an
# env var. To trigger the default deploying behavior, give it a dummy set of
# args.
# TODO(crbug.com/823996): Make the GN-dependent deps controllable via cmd-line
# args.
env_copy = os.environ.copy()
if not env_copy.get('GN_ARGS'):
env_copy['GN_ARGS'] = 'is_chromeos = true'
env_copy['PATH'] = env_copy['PATH'] + ':' + os.path.join(CHROMITE_PATH, 'bin')
return subprocess.call( return subprocess.call(
cros_run_vm_test_cmd, stdout=sys.stdout, stderr=sys.stderr) cros_run_vm_test_cmd, stdout=sys.stdout, stderr=sys.stderr, env=env_copy)
def main(): def main():
...@@ -155,7 +181,12 @@ def main(): ...@@ -155,7 +181,12 @@ def main():
'--cros-cache', type=str, required=True, help='Path to cros cache.') '--cros-cache', type=str, required=True, help='Path to cros cache.')
vm_test_parser.add_argument( vm_test_parser.add_argument(
'--test-exe', type=str, required=True, '--test-exe', type=str, required=True,
help='Path to test executable to run inside VM.') help='Path to test executable to run inside VM. If the value is '
'"cros_vm_sanity_test", the sanity test that ships with the VM '
'image runs instead. This test smokes-check the system browser '
'(eg: loads a simple webpage, executes some javascript), so a '
'fully-built Chrome binary that can get deployed to the VM is '
'expected to available in the out-dir.')
vm_test_parser.add_argument( vm_test_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 deployed ' help='Path to output directory, all of whose contents will be deployed '
......
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