blob: 8e302e7d511844962690cd985df50b76601c0c6e [file] [log] [blame]
# 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("//build/config/chrome_build.gni")
assert(is_chromeos)
declare_args() {
cros_board = ""
cros_sdk_version = ""
}
declare_args() {
# Determines if we're running tests on VMs or on devices.
# TODO(crbug.com/866062): Is there a better way to do this?
cros_is_vm = cros_board == "amd64-generic" || cros_board == "betty"
}
# Ensure that if one is set, the other is as well.
assert(cros_board == "" == (cros_sdk_version == ""))
# The build is using the Simple Chrome "cros chrome-sdk" to target real hardware
# or a VM, not linux-chromeos.
# NOTE: Most test targets in Chrome expect to run under linux-chromeos, so some
# have compile-time asserts that intentionally fail when this build flag is set.
# Build and run the tests for linux-chromeos instead.
# https://chromium.googlesource.com/chromium/src/+/master/docs/chromeos_build_instructions.md
# https://chromium.googlesource.com/chromiumos/docs/+/master/simple_chrome_workflow.md
is_cros_chrome_sdk = cros_board != ""
# Creates a script at $generated_script that can be used to launch a cros VM
# and optionally run a test within it.
# Args:
# test_exe: Name of test binary located in the out dir. This will get copied
# to the VM and executed there.
# tast_attr_expr: Tast expression to pass to local_test_runner on the VM.
# tast_tests: List of Tast tests to run on the VM. Note that when this is
# specified, the target name used to invoke this template will be
# designated as the "name" of this test and will primarly used for test
# results tracking and displaying (eg: flakiness dashboard).
# generated_script: Path to place the generated script.
# deploy_chrome: If true, deploys a locally built chrome located in the root
# build dir to the VM after launching it.
# runtime_deps_file: Path to file listing runtime deps for the test. If set,
# all files listed will be copied to the VM before testing.
template("generate_runner_script") {
forward_variables_from(invoker,
[
"deploy_chrome",
"generated_script",
"runtime_deps_file",
"tast_attr_expr",
"tast_tests",
"testonly",
"test_exe",
])
if (!defined(deploy_chrome)) {
deploy_chrome = false
}
# These are the only 2 conditions when ${_cache_path_prefix} is used, so
# initialize it in a conditional.
if (deploy_chrome || cros_is_vm) {
_cache_path_prefix = "//build/cros_cache/chrome-sdk/tarballs/${cros_board}+${cros_sdk_version}"
}
assert(defined(generated_script),
"Must specify where to place generated test launcher script via " +
"'generated_script'")
is_tast = defined(tast_attr_expr) || defined(tast_tests)
assert(!(is_tast && defined(test_exe)),
"Tast tests are invoked from binaries shipped with the VM image. " +
"There should be no locally built binary needed.")
action(target_name) {
if (defined(runtime_deps_file)) {
write_runtime_deps = runtime_deps_file
}
script = "//build/chromeos/create_test_runner_script.py"
outputs = [
generated_script,
]
deps = [
"//testing/buildbot/filters:chromeos_filters",
]
if (defined(invoker.deps)) {
deps += invoker.deps
}
data = [
# We use android test-runner's results libs to construct gtest output
# json.
"//build/android/pylib/__init__.py",
"//build/android/pylib/base/",
"//build/android/pylib/results/",
generated_script,
"//build/chromeos/",
"//build/cros_cache/chrome-sdk/misc/",
# We use luci-py's subprocess42 to launch test processes.
"//tools/swarming_client/utils/",
# The LKGM file controls what version of the VM image to download. Add it
# as data here so that changes to it will trigger analyze.
"//chromeos/CHROMEOS_LKGM",
"//third_party/chromite/",
]
# Add the VM/QEMU-launching bits if needed.
if (cros_is_vm) {
assert(defined(_cache_path_prefix))
_vm_image_path = "${_cache_path_prefix}+chromiumos_qemu_image.tar.xz/"
_qemu_dir = "${_cache_path_prefix}+app-emulation/"
_firmware_dir = "${_cache_path_prefix}+sys-firmware/"
data += [
_firmware_dir,
_vm_image_path,
_qemu_dir,
]
}
if (is_tast) {
data += [
"${_cache_path_prefix}+chromeos-base/tast-cmd/",
"${_cache_path_prefix}+chromeos-base/tast-remote-tests-cros/",
]
}
if (defined(invoker.data)) {
deps += invoker.data
}
if (defined(invoker.data_deps)) {
data_deps = invoker.data_deps
}
# Required arguments used at build time by the runner script generator.
args = [
"--script-output-path",
rebase_path(generated_script, root_build_dir),
"--cros-cache",
rebase_path("//build/cros_cache/", root_build_dir),
"--board",
cros_board,
"--output-directory",
rebase_path(root_out_dir, root_build_dir),
]
if (cros_is_vm) {
args += [ "--use-vm" ]
}
if (deploy_chrome) {
args += [ "--deploy-chrome" ]
# To deploy chrome to the VM, it needs to be stripped down to fit into
# the VM. This is done by using binutils in the toolchain. So add the
# toolchain to the data.
assert(defined(_cache_path_prefix))
data += [
"${_cache_path_prefix}+environment_chromeos-base_chromeos-chrome.tar.xz",
"${_cache_path_prefix}+target_toolchain/",
]
}
# When --test-exe is specified, test_runner.py will push the exe to the VM
# and execute it. Otherwise it wraps a host-side command and just takes care
# launching & tearing-down the VM.
if (defined(test_exe)) {
args += [
"--test-exe",
test_exe,
]
if (defined(runtime_deps_file)) {
args += [
"--runtime-deps-path",
rebase_path(runtime_deps_file, root_build_dir),
]
}
} else if (is_tast) {
# When --tast-tests is specified, test_runner.py will call
# local_test_runner on the VM to run the set of tests.
args += [
"--suite-name",
target_name,
]
if (defined(tast_attr_expr)) {
args += [
"--tast-attr-expr",
tast_attr_expr,
]
} else {
foreach(test, tast_tests) {
args += [
"--tast-tests",
test,
]
}
}
}
}
}
template("tast_test") {
forward_variables_from(invoker, "*")
# Default the expression to match any chrome-related test.
if (!defined(tast_attr_expr) && !defined(tast_tests)) {
# The following expression filters out all non-critical tests. See the link
# below for more details:
# https://chromium.googlesource.com/chromiumos/platform/tast/+/master/docs/test_attributes.md
tast_attr_expr =
"!disabled && !\"group:*\" && !informational && \"dep:chrome\""
if (!is_chrome_branded) {
tast_attr_expr += " && !\"dep:chrome_internal\""
}
} else {
assert(defined(tast_attr_expr) != defined(tast_tests),
"Specify one of tast_tests or tast_attr_expr.")
}
# Append any disabled tests to the expression.
if (defined(tast_disabled_tests)) {
assert(defined(tast_attr_expr),
"tast_attr_expr must be used when specifying tast_disabled_tests.")
foreach(test, tast_disabled_tests) {
tast_attr_expr += " && !\"name:${test}\""
}
}
if (defined(tast_attr_expr)) {
tast_attr_expr = "( " + tast_attr_expr + " )"
}
generate_runner_script(target_name) {
testonly = true
generated_script = "$root_build_dir/bin/run_${target_name}"
runtime_deps_file = "$root_out_dir/${target_name}.runtime_deps"
deploy_chrome = true
data_deps = [
"//:chromiumos_preflight", # Builds the browser.
"//chromeos:cros_chrome_deploy", # Adds additional browser run-time deps.
]
}
}