blob: 7923beb7df3383131d0e64a9252a26fddb5835ba [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/unification/zbi/migrated_zbi.gni")
import("//build/unification/zbi/tests.gni")
import("//build/unification/zbi/zbi_input.gni")
import("//zircon/public/gn/test/zbi_test_success.gni")
# Composes a test zbi out of Zircon artifacts.
#
# Parameters
#
# args (optional)
# [list of strings] Command line arguments for the resulting zbi.
#
# reference (optional)
# [string] Name of the Zircon zbi test this target mimics.
#
# 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" ].
#
# replace, complete, compress
# See migrated_zbi.gni.
template("migrated_zbi_test") {
main_target = target_name
input_target = "${target_name}_input"
zbi_target = "${target_name}_zbi"
group_deps = []
entries = []
if (defined(invoker.args)) {
entries += invoker.args
}
entries += [ "userboot.shutdown" ]
zbi_input(input_target) {
forward_variables_from(invoker, [ "deps" ])
testonly = true
type = "cmdline"
args = []
foreach(entry, entries) {
args += [ "--entry=$entry" ]
}
}
migrated_zbi(zbi_target) {
forward_variables_from(invoker, "*", ["args", "reference", "device_types"])
testonly = true
if (!defined(output_name)) {
output_name = main_target
}
deps += [ ":$input_target" ]
}
group_deps += [ ":$zbi_target" ]
output_file = target_name
if (defined(invoker.output_name)) {
output_file = invoker.output_name
}
if (defined(invoker.output_extension)) {
if (invoker.output_extension != "") {
output_file += ".${invoker.output_extension}"
}
} else {
output_file += ".zbi"
}
if (defined(invoker.output_dir)) {
output_file = "${invoker.output_dir}/$output_file"
} else {
output_file = "$target_out_dir/$output_file"
}
if (defined(invoker.reference)) {
reference = invoker.reference
reference_zbi = false
foreach(test, zircon_zbi_tests) {
if (test.name == reference) {
assert(reference_zbi == false, "Duplicate zbi test: $reference")
reference_zbi = test.path
}
}
assert(reference_zbi != false, "Could not find zbi test $reference")
reference_target = "${target_name}_reference"
zbi_tool = "$zircon_tools_dir/zbi"
action(reference_target) {
forward_variables_from(invoker, [ "visibility" ])
testonly = true
script = "//build/unification/zbi/compare_zbis.py"
deps = [
":$zbi_target",
"//zircon/public/tool/zbi($host_toolchain)",
]
inputs = [
output_file,
reference_zbi,
zbi_tool,
]
outputs = [ "$target_gen_dir/$target_name.stamp" ]
args = [
"--tool",
rebase_path(zbi_tool, root_build_dir),
"--reference-zbi",
rebase_path(reference_zbi, root_build_dir),
"--generated-zbi",
rebase_path(output_file, root_build_dir),
"--stamp",
rebase_path(outputs[0], root_build_dir),
]
}
group_deps += [ ":$reference_target" ]
}
if (defined(invoker.device_types)) {
_device_types = invoker.device_types
} else {
_device_types = [ "QEMU" ]
}
group(main_target) {
forward_variables_from(invoker,
[
"assert_no_deps",
"visibility",
])
testonly = true
public_deps = group_deps
metadata = {
zbi_tests = [
{
cpu = current_cpu
disabled = false
name = main_target
label = get_label_info(":$target_name", "label_with_toolchain")
path = rebase_path(output_file, root_build_dir)
bootserver_netboot = [ "--boot" ]
success_string = zbi_test_success_string
device_types = _device_types
},
]
}
}
}