| # Copyright 2026 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/components/fuchsia_unittest_package.gni") |
| import("//build/cpp/library_headers.gni") |
| import("//build/test.gni") |
| import("//build/testing/boot_tests/boot_test.gni") |
| import("//build/testing/boot_tests/kernel_zbi_test.gni") |
| import("//build/toolchain/hermetic_source_set.gni") |
| import("//build/toolchain/zircon/user_basic_redirect.gni") |
| import("//build/zbi/kernel_cmdline.gni") |
| import("//sdk/lib/c/libc.gni") |
| import("//src/zircon/lib/zircon/libzircon.gni") |
| import("//zircon/kernel/kernel_package.gni") |
| |
| library_headers("headers") { |
| headers = [ "lib/userboot/startup.h" ] |
| public_deps = [ "//zircon/system/public" ] |
| } |
| |
| static_library("userboot") { |
| public_deps = [ |
| ":headers", |
| "//sdk/lib/c:static", |
| ] |
| complete_static_lib = true |
| deps = [ ":startup.basic" ] |
| |
| # Get the boot option set via a ZBI item that will roll up into the ultimate |
| # kernel ZBI that contains the userboot executable. While this is needed, |
| # the whole library is testonly. |
| data_deps = [ ":experimental-protocol" ] |
| testonly = true |
| } |
| |
| user_basic_redirect("startup.basic") { |
| visibility = [ ":*" ] |
| public_deps = [ ":startup" ] |
| } |
| |
| hermetic_source_set("startup") { |
| visibility = [ ":*" ] |
| global_symbols = [ |
| "TakeBootstrapChannel", |
| "_zx_startup_get_arguments", |
| "_zx_startup_get_handles", |
| "_zx_startup_preinit", |
| ] |
| undefined_symbols = libzircon_underscore_linkage_names + [ |
| "${libc_namespace}_gLog", |
| "__cxa_atexit", |
| "__dso_handle", |
| ] |
| allow_init = true |
| sources = [ "startup.cc" ] |
| deps = [ |
| ":headers", |
| "//sdk/lib/c/ld:log-panic", |
| "//sdk/lib/c/string:hermetic", |
| "//zircon/system/ulib/zx", |
| ] |
| } |
| |
| group("tests") { |
| testonly = true |
| deps = [ ":userboot-lib-tests" ] |
| } |
| |
| fuchsia_unittest_package("userboot-lib-tests") { |
| deps = [ ":userboot-lib-unittests" ] |
| } |
| |
| test("userboot-lib-unittests") { |
| sources = [ "unittests.cc" ] |
| deps = [ |
| "testing", |
| "//src/lib/elfldltl/testing", |
| "//src/lib/fxl/test:gtest_main", |
| "//third_party/googletest:gmock", |
| ] |
| data_deps = [ ":userboot-lib-static-pie-test" ] |
| } |
| |
| group("boot_tests") { |
| testonly = true |
| deps = [ ":userboot-lib-boot-test" ] |
| } |
| |
| static_remove_configs = [ "//build/config/fuchsia:fdio_config" ] |
| |
| test("userboot-lib-static-pie-test") { |
| configs += static_remove_configs |
| configs -= static_remove_configs |
| defines = [ "BOOT_TEST_SUCCESS_STRING=\"$boot_test_success_string\"" ] |
| sources = [ "userboot-lib-static-pie-test.cc" ] |
| ldflags = [ "-Wl,-zstack-size=0x200000" ] |
| deps = [ |
| ".", |
| "//zircon/system/ulib/zx", |
| ] |
| exclude_toolchain_tags = [ "uses-shadow" ] |
| } |
| |
| kernel_package("userboot-lib-test") { |
| visibility = [ ":*" ] |
| testonly = true |
| deps = [ |
| ":userboot-lib-static-pie-test", |
| "//zircon/kernel/bin:vmzircon.with-tests($default_test_kernel_switchset)", |
| "//zircon/kernel/image:common-package-items.no-userboot", |
| ] |
| } |
| |
| zbi_test("userboot-lib-boot-test") { |
| args = [ |
| "kernel.enable-serial-syscalls=true", |
| "kernel.select=userboot-lib-test", |
| "kernel.select.userboot=test/userboot-lib-static-pie-test", |
| "kernel.userboot.experimental-protocol", |
| ] |
| deps = [ |
| ":userboot-lib-test", |
| "//zircon/kernel/phys:physboot", |
| ] |
| } |
| |
| # Eventually the new protocol will be the only protocol and this will go away. |
| kernel_cmdline("experimental-protocol") { |
| testonly = true |
| visibility = [ ":*" ] |
| args = [ "kernel.userboot.experimental-protocol" ] |
| } |