blob: 9637b8c84f511d13d3152a4a02afbd63680e0ff7 [file] [log] [blame]
# Copyright 2022 The Fuchsia 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/test.gni")
import("//build/testing/zbi_test.gni")
import("//build/zbi/kernel_cmdline.gni")
# Build an executable to run as the standalone test binary under Zircon.
#
# This wraps a test() with the metadata appropriate to have it launched by
# userboot as the standalone. This target should be included in deps of a
# zbi_test() target, along with a kernel. An auxiliary metadata target
# "$target_name.cmdline" is defined and referenced in data_deps.
#
# Parameters: (see test for other parameters)
#
# userboot_entry_type (optional, defaults to "test")
# [string] May be "test" or "boot". By setting this parameter, the
# executable will be launched by userboot as a test program or as boot
# program.
#
# Note that defaults for `configs` exclude the implicit fdio dependency, and
# defaults for `disable_syslog_backend` and `assert_no_deps` are injected to
# avoid other implicit deps inappropriate for standalone test executables and
# to ensure those haven't crept in from elsewhere in the deps graph. These
# parameters can be set explicitly to override this.
template("zbi_test_executable") {
if (defined(invoker.output_name)) {
output_name = invoker.output_name
} else {
output_name = target_name
}
install_path = "test/$output_name"
if (defined(invoker.userboot_entry_type)) {
userboot_entry_type = invoker.userboot_entry_type
} else {
userboot_entry_type = "test"
}
main_target = target_name
cmdline_target = "$target_name.cmdline"
test(main_target) {
data_deps = []
forward_variables_from(invoker, "*")
data_deps += [ ":$cmdline_target" ]
}
kernel_cmdline(cmdline_target) {
testonly = true
forward_variables_from(invoker, [ "visibility" ])
if (defined(visibility)) {
visibility += [ ":$main_target" ]
}
if (userboot_entry_type == "test") {
args = [
"userboot.test.root=",
"userboot.test.next=$install_path",
]
} else {
args = [
"userboot.root=",
"userboot.next=$install_path",
]
}
}
}
set_defaults("zbi_test_executable") {
configs = default_executable_configs
if (is_fuchsia && !is_kernel) {
configs -= [ "//build/config/fuchsia:fdio_config" ]
}
assert_no_deps = [
"//sdk/lib/fdio/*",
"//sdk/lib/syslog/*",
]
disable_syslog_backend = true
}