blob: a90117b950cf005d328822ea8592b21d34f9d2fc [file] [log] [blame]
# Copyright 2020 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/images/vbmeta.gni")
import("//build/testing/boot_test.gni")
import("//build/zbi/zbi.gni")
import("//build/zbi/zbi_input.gni")
# Composes a test zbi out of Zircon artifacts.
#
# The $target_name target is a group() that holds the metadata and is what
# should be used in deps. The actual zbi() target is defined as
# "$target_name.zbi" so that e.g. get_target_outputs(":$target_name.zbi")
# can be used.
#
# If `use_vbmeta` is true, an associated VBMeta image (of the same base name)
# will be output alongside the ZBI.
#
# Parameters
#
# args (optional)
# [list of strings] Command line arguments for the resulting zbi. ZBI tests
# using the kernel and a non-default `userboot.next` options must add
# `userboot.{shutdown,reboot}` as well in order to guarantee that a success
# string is printed. See //zircon/system/utest/core:core-tests for a
# canonical example.
#
# device_types
# [list of strings] Devices the test should run on.
# Allowable values are those among the entries in
# //build/testing/platforms.gni; others will be ignored.
# Defaults to [ "QEMU" ].
#
# qemu_kernel
# [label_with_toolchain] Label corresponding to the qemu-kernel image
# in images.json that should be used with the zbi_image. This will appear
# as the qemu_kernel_label in a boot_tests.json entry.
# TODO(joshuaseaton|mcgrathr): Use a QEMU-specific boot test template for
# specifying QEMU kernel + ZBI initrd, rather than allowing QEMU kernel to
# be supplied here.
#
# deps, data_deps, replace, complete, compress
# See //build/zbi/zbi.gni.
template("zbi_test") {
main_target = target_name
zbi_target = "${target_name}.zbi"
not_needed(invoker,
[
"qemu_kernel",
"timeout",
])
input_deps = []
group_deps = []
entries = []
if (defined(invoker.args)) {
entries += invoker.args
}
if (entries != []) {
input_target = "${target_name}_input"
input_deps += [ ":$input_target" ]
zbi_input(input_target) {
forward_variables_from(invoker, [ "deps" ])
testonly = true
type = "cmdline"
args = []
foreach(entry, entries) {
args += [ "--entry=$entry" ]
}
}
}
forward_variables_from(invoker, [ "output_name" ])
if (!defined(output_name)) {
output_name = main_target
}
zbi(zbi_target) {
testonly = true
data_deps = []
forward_variables_from(invoker,
[
"cpu",
"compress",
"data_deps",
"output_dir",
"output_extension",
"visibility",
])
if (defined(visibility)) {
visibility += [ ":$main_target" ]
}
deps = invoker.deps + input_deps
if (defined(invoker.qemu_kernel)) {
data_deps += [ invoker.qemu_kernel ]
}
_output_dir = target_out_dir
if (defined(output_dir)) {
_output_dir = output_dir
}
_output_extension = "zbi"
if (defined(output_extension)) {
_output_extension = output_extension
}
_output_file = "${_output_dir}/${output_name}"
if (_output_extension != "") {
_output_file += ".${_output_extension}"
}
metadata = {
images = [
{
label = get_label_info(":$zbi_target", "label_with_toolchain")
name = output_name
path = rebase_path(_output_file, root_build_dir)
type = "zbi"
cpu = current_cpu
compressed =
!defined(invoker.compressed) ||
(invoker.compressed != false && invoker.compressed != "none")
if (defined(testonly) && testonly) {
testonly = true
}
forward_variables_from(invoker, [ "tags" ])
},
]
}
}
group_deps += [ ":$zbi_target" ]
output_zbi = target_name
if (defined(invoker.output_name)) {
output_zbi = invoker.output_name
}
if (defined(invoker.output_extension)) {
if (invoker.output_extension != "") {
output_zbi += ".${invoker.output_extension}"
}
} else {
output_zbi += ".zbi"
}
if (defined(invoker.output_dir)) {
output_zbi = "${invoker.output_dir}/$output_zbi"
} else {
output_zbi = "$target_out_dir/$output_zbi"
}
if (use_vbmeta) {
vbmeta_target = "${target_name}.vbmeta"
vbmeta(vbmeta_target) {
forward_variables_from(invoker, [ "visibility" ])
testonly = true
zbi = ":$zbi_target"
}
}
boot_test(main_target) {
forward_variables_from(invoker,
[
"assert_no_deps",
"device_types",
"qemu_kernel",
"timeout",
])
if (!defined(device_types)) {
device_types = [
"QEMU",
"AEMU",
]
}
zbi = ":$zbi_target"
if (use_vbmeta) {
vbmeta = ":$vbmeta_target"
}
}
}