| # 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/dist/resource.gni") |
| import("//build/testing/boot_tests/zbi_test.gni") |
| |
| # This is the default if no $deps parameter is passed to mexec_zbi_test(). |
| mexec_zbi_test_default_deps = [ |
| "//src/bringup/lib/mexec/testing:mexec-zbi-test-entry", |
| "//zircon/kernel", |
| ] |
| |
| # Build a "chain-loading" ZBI test that boots a provided ZBI test via mexec. |
| # |
| # `mexec_zbi_test()` defines a new ZBI test (see zbi_test.gni) by a simple |
| # program, launched directly by userboot, that loads a specified child ZBI and |
| # boots it via mexec. |
| # |
| # Parameters |
| # |
| # * child_zbi |
| # - Required: Label of the ZBI target to boot via mexec. The success |
| # string is expected to be printed on boot of the child ZBI. If the |
| # $child_zbi_file parameter is not also specified, this label must name |
| # something like a zbi() target defined within the same file and toolchain |
| # in which this template is instantiated. That is, a target on which |
| # get_target_outputs() works and whose first output is the ZBI file. |
| # - Type: label |
| # |
| # * child_zbi_file |
| # - Optional: Path to the input child ZBI file. This is required when |
| # `child_zbi` does not point to a label in the current file and toolchain, |
| # since `get_target_outputs(child_zbi)` is used by default to compute it |
| # when not specified. |
| # |
| # * args |
| # - Optional: List of additional kernel command line arguments |
| # The documentation above details specific arguments provided by |
| # default by the template; no argument that overrides these should be |
| # provided here. |
| # - Type: list(string) |
| # |
| # * deps |
| # - Optional: Dependencies for the *outer* zbi_test() target. |
| # This is what brings both the kernel and the mexec-launcher program |
| # into the outer ZBI, along with kernel command-line args needed to |
| # enable their use. The default deps include the canonical kernel |
| # and a standard mexec launcher program. |
| # - Type: list(label) |
| # - Default: mexec_zbi_test_default_deps |
| # |
| # * metadata |
| # - Optional: Usual meaning, but note the metadata is applied to the |
| # inner resource() target that depends on $child_zbi rather than to |
| # the zbi_test() target (which will collect it anyway). This allows |
| # the metadata to constrain collection across the $child_zbi deps graph |
| # before it feeds into the zbi() metadata collection in the zbi_test(). |
| # - Type: scope |
| # |
| # See zbi_test() for other parameters. |
| # |
| template("mexec_zbi_test") { |
| test_target = target_name |
| resource_target = "_mexec_zbi_test.$target_name.resource" |
| |
| assert(defined(invoker.child_zbi), "`child_zbi` not set") |
| |
| if (defined(invoker.child_zbi_file)) { |
| child_zbi_file = invoker.child_zbi_file |
| } else { |
| # The first output for `zbi_test` and `zbi` targets is documented as being |
| # the path to the associated ZBI. |
| child_outputs = get_target_outputs(invoker.child_zbi) |
| assert(child_outputs != [], |
| "get_target_outputs(${invoker.child_zbi}) returned no outputs") |
| child_zbi_file = child_outputs[0] |
| } |
| |
| resource(resource_target) { |
| visibility = [ ":*" ] |
| testonly = true |
| forward_variables_from(invoker, [ "metadata" ]) |
| sources = [ child_zbi_file ] |
| outputs = [ "testdata/mexec-child.zbi" ] |
| deps = [ invoker.child_zbi ] |
| } |
| |
| zbi_test(test_target) { |
| forward_variables_from(invoker, "*", [ "metadata" ]) |
| if (!defined(deps)) { |
| deps = mexec_zbi_test_default_deps |
| } |
| deps += [ ":$resource_target" ] |
| } |
| } |