Commit 3bce864e authored by Benjamin Pastene's avatar Benjamin Pastene Committed by Commit Bot

Create a wrapper and generator script around CrOS's run_vm_test script.

Example led build of one of the simple chrome bots:
https://ci.chromium.org/swarming/task/3cb56f4f4bb79410?server=chromium-swarm.appspot.com

Bug: 828607
Change-Id: Ifcbe4059544722b48f4ab31fb2e97331b4f976f2
Reviewed-on: https://chromium-review.googlesource.com/994062
Commit-Queue: Ben Pastene <bpastene@chromium.org>
Reviewed-by: default avatarDirk Pranke <dpranke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#550845}
parent 80351342
#!/usr/bin/env python
#
# Copyright 2018 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.
"""Creates a script that runs a CrOS VM test by delegating to
build/chromeos/run_vm_test.py.
"""
import argparse
import os
import re
import sys
SCRIPT_TEMPLATE = """\
#!/usr/bin/env python
#
# This file was generated by build/chromeos/create_vm_test_script.py
import os
import sys
def main():
script_directory = os.path.dirname(__file__)
def ResolvePath(path):
return os.path.abspath(os.path.join(script_directory, path))
vm_test_script = os.path.abspath(
os.path.join(script_directory, '{vm_test_script}'))
vm_args = {vm_test_args}
path_args = {vm_test_path_args}
for arg, path in path_args:
vm_args.extend([arg, ResolvePath(path)])
os.execv(vm_test_script,
[vm_test_script] + vm_args + sys.argv[1:])
if __name__ == '__main__':
sys.exit(main())
"""
def main(args):
parser = argparse.ArgumentParser()
parser.add_argument('--script-output-path')
parser.add_argument('--output-directory')
parser.add_argument('--test-exe')
parser.add_argument('--runtime-deps-path')
parser.add_argument('--cros-cache')
parser.add_argument('--board')
args = parser.parse_args(args)
def RelativizePathToScript(path):
return os.path.relpath(path, os.path.dirname(args.script_output_path))
run_test_path = RelativizePathToScript(
os.path.join(os.path.dirname(__file__), 'run_vm_test.py'))
vm_test_args = [
'--board', args.board,
'--test-exe', args.test_exe,
'-v',
]
vm_test_path_args = [
('--path-to-outdir', RelativizePathToScript(args.output_directory)),
('--runtime-deps-path', RelativizePathToScript(args.runtime_deps_path)),
('--cros-cache', RelativizePathToScript(args.cros_cache)),
]
with open(args.script_output_path, 'w') as script:
script.write(SCRIPT_TEMPLATE.format(
vm_test_script=run_test_path,
vm_test_args=str(vm_test_args),
vm_test_path_args=str(vm_test_path_args)))
os.chmod(args.script_output_path, 0750)
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))
#!/usr/bin/env python
#
# Copyright 2018 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.
import argparse
import contextlib
import logging
import os
import re
import stat
import subprocess
import sys
CHROMIUM_SRC_PATH = os.path.abspath(os.path.join(
os.path.dirname(__file__), '..', '..'))
CHROMITE_PATH = os.path.abspath(os.path.join(
CHROMIUM_SRC_PATH, 'third_party', 'chromite'))
CROS_RUN_VM_TEST_PATH = os.path.abspath(os.path.join(
CHROMITE_PATH, 'bin', 'cros_run_vm_test'))
_FILE_BLACKLIST = [
re.compile(r'.*build/chromeos.*'),
re.compile(r'.*build/cros_cache.*'),
re.compile(r'.*third_party/chromite.*'),
]
def read_runtime_files(runtime_deps_path, outdir):
if not runtime_deps_path:
return []
abs_runtime_deps_path = os.path.abspath(
os.path.join(outdir, runtime_deps_path))
with open(abs_runtime_deps_path) as runtime_deps_file:
files = [l.strip() for l in runtime_deps_file if l]
rel_file_paths = []
for f in files:
rel_file_path = os.path.relpath(
os.path.abspath(os.path.join(outdir, f)),
os.getcwd())
if not any(regex.match(rel_file_path) for regex in _FILE_BLACKLIST):
rel_file_paths.append(rel_file_path)
return rel_file_paths
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--verbose', '-v', action='store_true')
parser.add_argument(
'--path-to-outdir', type=str, required=True,
help='Path to output directory, all of whose contents will be deployed '
'to the device.')
parser.add_argument(
'--board', type=str, required=True, help='Type of CrOS device.')
parser.add_argument(
'--test-exe', type=str, required=True,
help='Path to test executable to run inside VM.')
parser.add_argument(
'--runtime-deps-path', type=str,
help='Runtime data dependency file from GN.')
parser.add_argument(
'--cros-cache', type=str, required=True, help='Path to cros cache.')
args, unknown_args = parser.parse_known_args()
if unknown_args:
print >> sys.stderr, 'Ignoring unknown args: %s' % unknown_args
args.cros_cache = os.path.abspath(os.path.join(
args.path_to_outdir, args.cros_cache))
cros_run_vm_test_cmd = [
CROS_RUN_VM_TEST_PATH,
'--start',
'--board', args.board,
'--cache-dir', args.cros_cache,
'--cwd', os.path.relpath(args.path_to_outdir, CHROMIUM_SRC_PATH),
]
if args.verbose:
cros_run_vm_test_cmd.append('--debug')
# cros_run_vm_test has trouble with relative paths that go up directors, so
# cd to src/, which should be the root of all data deps.
os.chdir(CHROMIUM_SRC_PATH)
for f in read_runtime_files(args.runtime_deps_path, args.path_to_outdir):
cros_run_vm_test_cmd.extend(['--files', f])
cros_run_vm_test_cmd += [
'--cmd',
'--',
'./' + args.test_exe,
]
print 'Running the following command:'
print ' '.join(cros_run_vm_test_cmd)
os.execv(CROS_RUN_VM_TEST_PATH, cros_run_vm_test_cmd)
if __name__ == '__main__':
sys.exit(main())
# Copyright 2018 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.
assert(is_chromeos)
template("generate_vm_runner_script") {
_cros_board = getenv("SDK_BOARD")
_cros_sdk = getenv("SDK_VERSION")
_vm_image_path = "//build/cros_cache/chrome-sdk/tarballs/${_cros_board}+${_cros_sdk}+chromiumos_qemu_image.tar.xz/chromiumos_qemu_image.bin"
_qemu_dir = "//build/cros_cache/chrome-sdk/tarballs/${_cros_board}+${_cros_sdk}+app-emulation/qemu-2.6.0-r2.tbz2/"
action(target_name) {
forward_variables_from(invoker, [ "testonly" ])
script = "//build/chromeos/create_vm_test_script.py"
outputs = [
invoker.generated_script,
]
data = [
invoker.generated_script,
"//build/chromeos/",
"//build/cros_cache/chrome-sdk/misc/",
"//third_party/chromite/",
_vm_image_path,
_qemu_dir,
]
# Arguments used at build time by the runner script generator.
args = [
"--script-output-path",
rebase_path(invoker.generated_script, root_build_dir),
"--output-directory",
rebase_path(root_out_dir, root_build_dir),
"--test-exe",
rebase_path(invoker.test_exe, root_build_dir),
"--runtime-deps-path",
rebase_path(invoker.runtime_deps_file, root_build_dir),
"--cros-cache",
rebase_path("//build/cros_cache/", root_build_dir),
"--board",
_cros_board,
]
}
}
...@@ -344,9 +344,48 @@ template("test") { ...@@ -344,9 +344,48 @@ template("test") {
} }
bundle_deps += [ ":$_resources_bundle_data" ] bundle_deps += [ ":$_resources_bundle_data" ]
} }
} else if (is_chromeos && getenv("SDK_VERSION") != "") {
# When the env var SDK_VERSION is set, assume we're in the cros chrome-sdk
# building simplechrome.
import("//build/config/chromeos/rules.gni")
assert(getenv("SDK_BOARD") != "", "Must specify board to build for.")
_gen_runner_target = "${target_name}__runner"
_runtime_deps_file =
"$root_out_dir/gen.runtime/" + get_label_info(target_name, "dir") +
"/" + get_label_info(target_name, "name") + ".runtime_deps"
generate_vm_runner_script(_gen_runner_target) {
testonly = true
generated_script = "$root_build_dir/bin/run_" + invoker.target_name
test_exe = "$root_out_dir/" + get_label_info(invoker.target_name, "name")
runtime_deps_file = _runtime_deps_file
}
executable(target_name) {
forward_variables_from(invoker, "*")
if (!defined(deps)) {
deps = []
}
if (!defined(data)) {
data = []
}
testonly = true
output_name = target_name
write_runtime_deps = _runtime_deps_file
data += [ _runtime_deps_file ]
deps += [
":$_gen_runner_target",
"//build/config:exe_and_shlib_deps",
]
}
} else { } else {
executable(target_name) { executable(target_name) {
deps = [] deps = []
forward_variables_from(invoker, "*") forward_variables_from(invoker, "*")
testonly = true testonly = true
......
...@@ -992,6 +992,7 @@ class MetaBuildWrapper(object): ...@@ -992,6 +992,7 @@ class MetaBuildWrapper(object):
isolate_map = self.ReadIsolateMap() isolate_map = self.ReadIsolateMap()
is_android = 'target_os="android"' in vals['gn_args'] is_android = 'target_os="android"' in vals['gn_args']
is_simplechrome = vals.get('cros_passthrough', False)
is_fuchsia = 'target_os="fuchsia"' in vals['gn_args'] is_fuchsia = 'target_os="fuchsia"' in vals['gn_args']
is_win = self.platform == 'win32' or 'target_os="win"' in vals['gn_args'] is_win = self.platform == 'win32' or 'target_os="win"' in vals['gn_args']
...@@ -1036,6 +1037,11 @@ class MetaBuildWrapper(object): ...@@ -1036,6 +1037,11 @@ class MetaBuildWrapper(object):
'../../testing/test_env.py', '../../testing/test_env.py',
os.path.join('bin', 'run_%s' % target), os.path.join('bin', 'run_%s' % target),
] ]
elif is_simplechrome and test_type != 'script':
cmdline = [
'../../testing/test_env.py',
os.path.join('bin', 'run_%s' % target),
]
elif use_xvfb and test_type == 'windowed_test_launcher': elif use_xvfb and test_type == 'windowed_test_launcher':
extra_files.append('../../testing/xvfb.py') extra_files.append('../../testing/xvfb.py')
cmdline = [ cmdline = [
......
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