| # Copyright 2020 The Fuchsia Authors |
| # |
| # Use of this source code is governed by a MIT-style |
| # license that can be found in the LICENSE file or at |
| # https://opensource.org/licenses/MIT |
| |
| if (current_toolchain != default_toolchain) { |
| import("//build/dist/generated_resource.gni") |
| import("//src/bringup/lib/mexec/testing/zbi_test.gni") |
| import("//zircon/kernel/phys/phys_executable.gni") |
| import("//zircon/kernel/phys/qemu.gni") |
| import("//zircon/kernel/phys/zbi_executable.gni") |
| |
| assert(toolchain.environment == "kernel.phys" || |
| toolchain_variant.base == qemu_environment) |
| |
| # This provides a PhysMain function appropriate for zbi_test() targets. |
| source_set("qemu-test-main") { |
| testonly = true |
| sources = [ "qemu-test-main.cc" ] |
| defines = [ "ZBI_TEST_SUCCESS_STRING=\"$zbi_test_success_string\"" ] |
| deps = [ |
| "//zircon/kernel/lib/arch", |
| "//zircon/kernel/lib/libc", |
| "//zircon/system/ulib/uart", |
| ] |
| public_deps = [ |
| # This is public to propagate its public_deps so dependents |
| # of qemu-test-main can use #include "test-main.h". |
| ":test-main", |
| ] |
| } |
| |
| source_set("zbi-test-main") { |
| testonly = true |
| sources = [ "zbi-test-main.cc" ] |
| defines = [ "ZBI_TEST_SUCCESS_STRING=\"$zbi_test_success_string\"" ] |
| public_deps = [ ":test-main" ] |
| deps = [ "//zircon/kernel/lib/libc" ] |
| } |
| |
| source_set("test-main") { |
| testonly = true |
| public = [ "test-main.h" ] |
| public_deps = [ |
| "..:main", |
| "..:symbolize", |
| "//zircon/kernel/lib/arch:headers", |
| ] |
| } |
| |
| # Build a test that runs directly as a QEMU kernel. This is wired up as a |
| # zbi_test() for infrastructure purposes though there is nothing in the ZBI. |
| template("phys_qemu_test") { |
| main_target = target_name |
| executable_target = "_qemu_phys_test.$target_name.executable" |
| zbi_target = "_qemu_phys_test.$target_name.zbi_test" |
| |
| phys_executable(executable_target) { |
| testonly = true |
| visibility = [ ":*" ] |
| deps = [] |
| forward_variables_from(invoker, |
| "*", |
| [ |
| "output_dir", |
| "output_extension", |
| "output_name", |
| "tags", |
| "testonly", |
| "target_name", |
| "timeout", |
| ]) |
| deps += qemu_deps + [ ":qemu-test-main" ] |
| } |
| |
| zbi_test(zbi_target) { |
| visibility = [ ":*" ] |
| |
| # Ensure the file, and its images.json entry, is not named |
| # _qemu_phys_test.xxxx.zbi_test, which is pretty unreadable and |
| # an implementation detail anyway. |
| output_name = main_target |
| |
| # The ZBI is empty other than the boilerplate cmdline, and does not |
| # contain a ZBI-bootable kernel. |
| args = [] |
| cpu = "" |
| deps = [] |
| tags = [ "incomplete" ] |
| if (defined(invoker.tags)) { |
| tags += invoker.tags |
| } |
| |
| # The special kernel is all that really matters for this test. |
| device_types = [ "QEMU" ] |
| qemu_kernel = ":$executable_target" |
| |
| # Set a short timeout since the tests don't necessarily shut down QEMU |
| # after printing the success string. |
| timeout = qemu_short_timeout |
| } |
| |
| group(main_target) { |
| testonly = true |
| forward_variables_from(invoker, [ "visibility" ]) |
| public_deps = [ ":$zbi_target($qemu_environment)" ] |
| } |
| } |
| |
| # TODO(fxbug.dev/57245): We provide a dummy resource to contrive 'completeness' |
| # in the following ZBI tests, which is a requirement for bootability under the |
| # current policy of zedboot, gigaboot, and the boot-shims using the old |
| # `zbi_check`. Once that is no longer a requirement, remove this target. |
| generated_resource("dummy.txt") { |
| testonly = true |
| visibility = [ "./*" ] |
| contents = "This space is intentionally left blank." |
| outputs = [ "$target_gen_dir/dummy.txt" ] |
| } |
| |
| # Build a ZBI test that uses the physboot framework. |
| template("phys_zbi_test") { |
| if (defined(invoker.test_deps)) { |
| test_deps = invoker.test_deps |
| } else { |
| test_deps = [ ":$target_name.executable" ] |
| zbi_executable("$target_name.executable") { |
| visibility = [ ":*" ] |
| testonly = true |
| deps = [] |
| forward_variables_from(invoker, |
| "*", |
| [ |
| "target_name", |
| "test_deps", |
| "timeout", |
| ]) |
| deps += [ ":zbi-test-main" ] |
| } |
| } |
| |
| zbi_test(target_name) { |
| args = [] |
| deps = test_deps + [ ":dummy.txt" ] |
| |
| # TODO(mcgrathr): enable on hardware too |
| device_types = [ |
| "AEMU", |
| "QEMU", |
| ] |
| |
| if (defined(invoker.timeout)) { |
| if (invoker.timeout != false) { |
| timeout = invoker.timeout |
| } |
| } else { |
| # Set a short timeout since the tests don't reliably reboot the machine. |
| timeout = qemu_short_timeout |
| } |
| } |
| } |
| |
| # Build both a phys_qemu_test() and zbi_executable()/zbi_test() from the |
| # same sources. |
| # |
| # Generates a target with a name of the form "qemu-xxx" for the QEMU test, |
| # and "zbi-xxx" for the ZBI test. |
| template("common_test") { |
| phys_qemu_test("qemu-$target_name") { |
| visibility = [ ":*" ] |
| forward_variables_from(invoker, "*", [ "target_name" ]) |
| } |
| |
| phys_zbi_test("zbi-$target_name") { |
| visibility = [ ":*" ] |
| forward_variables_from(invoker, "*", [ "target_name" ]) |
| } |
| |
| group(target_name) { |
| testonly = true |
| deps = [ |
| ":qemu-$target_name", |
| ":zbi-$target_name", |
| ] |
| } |
| } |
| |
| common_test("hello-world-test") { |
| sources = [ "hello-world-test.cc" ] |
| deps = [ |
| ":test-main", |
| "//zircon/kernel/lib/libc", |
| ] |
| } |
| |
| common_test("backtrace-test") { |
| sources = [ "backtrace-test.cc" ] |
| deps = [ |
| ":test-main", |
| "//zircon/kernel/lib/arch", |
| "//zircon/kernel/lib/libc", |
| ] |
| } |
| |
| # Ideally we'd test all four combinations on arm64 and both combinations on |
| # x86. But the common library code is always compiled with shadow-call-stack |
| # on arm64 so we can't disable the ABI support for it and with safe-stack on |
| # x86 so we can't disable the ABI support for it there. The start.S code only |
| # enables extra stack support conditionally so as not to waste space, so there |
| # isn't a good way to test non-default configurations. |
| common_test("phys-unittests") { |
| sources = [ |
| "phys-unittests.cc", |
| "stack-tests.cc", |
| ] |
| deps = [ |
| ":test-main", |
| "//zircon/kernel/lib/libc", |
| "//zircon/kernel/lib/unittest", |
| "//zircon/kernel/tests", |
| ] |
| } |
| |
| common_test("memory-test") { |
| sources = [ "phys-memory-test.cc" ] |
| deps = [ |
| ":test-main", |
| "..:allocation", |
| "//zircon/kernel/lib/ktl", |
| "//zircon/kernel/lib/libc", |
| ] |
| } |
| |
| zbi_input("decompress-test-data") { |
| visibility = [ ":*" ] |
| testonly = true |
| type = "ramdisk" |
| args = [ |
| "--compressed=zstd.max", |
| "--entry=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz", |
| ] |
| } |
| |
| # Test the zbitl decompression code. |
| # |
| # This requires a zbi_input, so we only run it as a ZBI test. |
| phys_zbi_test("zbi-decompress-test") { |
| sources = [ "decompress-test.cc" ] |
| deps = [ |
| ":test-main", |
| "..:allocation", |
| "..:zbi-memory", |
| "..:zbitl-allocation", |
| "//zircon/kernel/lib/ktl", |
| "//zircon/kernel/lib/libc", |
| "//zircon/system/ulib/zbitl", |
| "//zircon/system/ulib/zxc", |
| ] |
| data_deps = [ ":decompress-test-data" ] |
| } |
| |
| zbi_executable("chain-load-test") { |
| visibility = [ ":*" ] |
| testonly = true |
| sources = [ "chain-load-test.cc" ] |
| deps = [ |
| ":zbi-test-main", |
| "..:allocation", |
| "..:boot-zbi", |
| "..:zbi-memory", |
| "..:zbitl-allocation", |
| "//zircon/kernel/lib/ktl", |
| "//zircon/kernel/lib/libc", |
| "//zircon/system/ulib/zbitl", |
| "//zircon/system/ulib/zxc", |
| ] |
| } |
| |
| phys_zbi_test("zbi-chain-load-hello-world-test") { |
| test_deps = [ |
| ":chain-load-hello-world-test-data", |
| ":chain-load-test", |
| ] |
| } |
| |
| zbi_input("chain-load-hello-world-test-data") { |
| visibility = [ ":*" ] |
| testonly = true |
| type = "ramdisk" |
| args = [ "--compressed=zstd.max" ] |
| deps = [ ":zbi-hello-world-test.executable" ] |
| sources = get_target_outputs(deps[0]) |
| } |
| |
| phys_zbi_test("zbi-chain-load-core-tests") { |
| test_deps = [ |
| ":chain-load-core-tests-data", |
| ":chain-load-test", |
| ] |
| |
| # Once it chain-loads Zircon, it will shut down by itself, but not |
| # necessarily really quickly since the tests take a little while to run. |
| timeout = false |
| } |
| |
| zbi_input("chain-load-core-tests-data") { |
| visibility = [ ":*" ] |
| testonly = true |
| type = "ramdisk" |
| args = [ "--compressed=zstd.max" ] |
| deps = [ "//zircon/system/utest/core:core-tests.zbi($default_toolchain)" ] |
| sources = [ get_label_info(deps[0], "target_out_dir") + "/core-tests.zbi" ] |
| } |
| |
| group("test") { |
| testonly = true |
| deps = [ |
| ":backtrace-test", |
| ":hello-world-test", |
| ":phys-unittests", |
| ":zbi-decompress-test", |
| ":zbi-memory-test", |
| "code-patching", |
| ] |
| if (current_cpu == "arm64") { |
| deps += [ |
| ":zbi-chain-load-core-tests", |
| ":zbi-chain-load-hello-world-test", |
| ] |
| } |
| if (current_cpu == "x64") { |
| deps += [ ":qemu-memory-test" ] |
| } |
| } |
| } else { # current_toolchain == default_toolchain |
| import("//src/bringup/lib/mexec/testing/zbi_test.gni") |
| |
| # We create mexec-chainloading variations of all of the phys ZBI tests. |
| test_deps = [] |
| foreach(test, |
| [ |
| "zbi-backtrace-test", |
| "zbi-hello-world-test", |
| "zbi-memory-test", |
| "zbi-phys-unittests", |
| "zbi-decompress-test", |
| ]) { |
| mexec_zbi_test("mexec-$test") { |
| child_zbi = ":$test(//zircon/kernel/phys:kernel.phys_$current_cpu)" |
| child_zbi_file = |
| get_label_info(child_zbi, "target_out_dir") + "/$test.zbi" |
| } |
| |
| test_deps += [ ":mexec-$test" ] |
| } |
| |
| group("test") { |
| testonly = true |
| deps = |
| [ ":test(//zircon/kernel/phys:kernel.phys_$current_cpu)" ] + test_deps |
| } |
| } |