| # Copyright 2019 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/config/zircon/levels.gni") |
| import("//build/test.gni") |
| import("//build/testing/boot_tests/kernel_zbi_test.gni") |
| import("//build/testing/boot_tests/zbi_test_executable.gni") |
| import("//build/testing/bootfs_test.gni") |
| import("//build/toolchain/rbe.gni") |
| import("//zircon/kernel/params.gni") |
| |
| # Each subdirectory just provides an eponymous source_set(). |
| core_tests = [ |
| "assert", |
| "bad-segsel", |
| "c11-condvar", |
| "c11-mutex", |
| "c11-thread", |
| "channel-call-etc", |
| "channel-iovec", |
| "channel-write-etc", |
| "clock", |
| "elf-tls", |
| "event-pair", |
| "exceptions", |
| "fifo", |
| "fpu", |
| "futex", |
| "handle-close", |
| "handle-dup", |
| "handle-info", |
| "handle-transfer", |
| "handle-wait", |
| "iob", |
| "object-child", |
| "object-wait", |
| "page-size", |
| "property", |
| "pthread", |
| "pthread-barrier", |
| "pthread-tls", |
| "socket", |
| "stack", |
| "stream", |
| "sync-completion", |
| "sync-condition", |
| "sync-mutex", |
| "syscall-generation", |
| "thread-initial-state", |
| "time", |
| "version", |
| ] |
| |
| # Requires use_next_vdso in the manifest. Build as a package and unified bootfs test, but not a |
| # standalone bootfs test. |
| # TODO(https://fxbug.dev/42170954): Remove this once standalone bootfs tests can access the next vDSO. |
| requires_next_vdso = [ |
| "pager-writeback", |
| "restricted-mode", |
| ] |
| |
| # These tests require custom component manifests to execute as components. |
| core_tests_with_custom_manifests = |
| [ |
| # Some tests require ZX_POL_NEW_PROCESS. |
| "channel", |
| "memory-mapping", |
| "port", |
| "process-shared", # requires ZX_POL_NEW_PROCESS, |
| # ZX_POL_AMBIENT_MARK_VMO_EXEC, and the next vDSO |
| |
| # Some tests require ZX_POL_AMBIENT_MARK_VMO_EXEC. |
| "vmo", |
| ] + requires_next_vdso |
| |
| # These tests need to run in a bootfs environment and can't run as a Fuchsia |
| # component even with additional configuration. |
| bootfs_only = [ |
| # These tests require ZX_POL_NEW_PROCESS for many tests. |
| "address-tagging", |
| "job", |
| "object-info", |
| "process", |
| "vmar", |
| |
| # Some tests new ZX_POL_NEW_PROCESS, and the DebugRegisterState tests on |
| # x86_64 fail when run as a component due to DR6 containing unexpected values. |
| "threads", |
| |
| # The pager tests rely on being able to check for test threads blocking on user pagers created |
| # by the test. They do this by verifying that the thread state is ZX_THREAD_STATE_BLOCKED_PAGER |
| # which only captures that the thread is blocked against *some* user pager, not any specific one. |
| # So they cannot run in an environment where test threads can block on pagers created outside of |
| # the test, e.g. when the test is run as a component. |
| # |
| # TODO(https://fxbug.dev/42170954): pager-writeback should be moved here too once standalone bootfs tests |
| # can access the next vDSO. |
| "pager", |
| ] |
| |
| # These tests need to run in the unified core-tests binary because |
| # they either call standalone::Get*Resource() or they need to run in a job |
| # tree without any exception handler. |
| unified_only = [ |
| "bad-syscall", |
| "bti", |
| "default-exception-handler", # needs job tree w/o exception handler. |
| "debuglog:unified-only", |
| "interrupt", |
| "next-vdso", |
| "pager-writeback", |
| "profile", |
| "resource", |
| "system-event", |
| "system-cpu", |
| "system-suspend", |
| "thread-sampler", |
| ] |
| assert(core_tests + core_tests_with_custom_manifests - |
| core_tests_with_custom_manifests == core_tests, |
| "core_tests and core_tests_with_custom_manifests must be disjoint") |
| assert(core_tests + bootfs_only - bootfs_only == core_tests, |
| "core_tests and bootfs_only must be disjoint") |
| assert(bootfs_only + core_tests_with_custom_manifests - |
| core_tests_with_custom_manifests == bootfs_only, |
| "bootfs_only and core_tests_with_custom_manifests must be disjoint") |
| assert(core_tests + unified_only - unified_only == core_tests, |
| "core_tests and unified_only must be disjoint") |
| |
| all_bootfs_tests = core_tests + core_tests_with_custom_manifests + bootfs_only |
| |
| # Build each test as a standalone binary meant to be run by runtests. |
| foreach(test_name, all_bootfs_tests) { |
| test(test_name) { |
| output_name = "core-$test_name" |
| |
| deps = [ test_name ] |
| |
| if (is_fuchsia) { |
| fdio_config = [ "//build/config/fuchsia:fdio_config" ] |
| if (configs + fdio_config - fdio_config != configs) { |
| configs -= fdio_config |
| } |
| deps += [ "//sdk/lib/fdio" ] |
| } |
| } |
| |
| bootfs_test("core-$test_name-bootfs-test") { |
| name = "core-$test_name" |
| deps = [ ":$test_name" ] |
| } |
| } |
| |
| # Build Fuchsia components and packages for tests that can run by |
| # fx test. |
| core_test_packages = [] |
| |
| # These tests can use an autogenerated manifest. |
| foreach(test_name, core_tests) { |
| fuchsia_test_package_name = "core-${test_name}-test-package" |
| core_test_packages += [ ":${fuchsia_test_package_name}" ] |
| |
| fuchsia_unittest_package(fuchsia_test_package_name) { |
| deps = [ ":${test_name}" ] |
| } |
| } |
| |
| # These tests specify a custom component manifest. |
| foreach(test_name, core_tests_with_custom_manifests) { |
| fuchsia_test_package_name = "core-${test_name}-test-package" |
| core_test_packages += [ ":${fuchsia_test_package_name}" ] |
| |
| fuchsia_unittest_package(fuchsia_test_package_name) { |
| deps = [ ":${test_name}" ] |
| manifest = "${test_name}/meta/${test_name}_test.cml" |
| } |
| } |
| |
| group("tests") { |
| testonly = true |
| deps = core_test_packages |
| } |
| |
| template("core_tests") { |
| kernel_zbi_test(target_name) { |
| assert_no_deps = [ |
| "//zircon/system/core/*", |
| "//zircon/system/dev/*", |
| ] |
| deps = [ ":core-tests-standalone" ] |
| forward_variables_from(invoker, |
| [ |
| "args", |
| "device_types", |
| "timeout", |
| "generate_cuckoo", |
| ]) |
| if (!defined(timeout)) { |
| # We've observed the ASAN variant of core-tests take as long as 701 |
| # seconds when booted via firmware on certain types of hardware. Leave a |
| # little buffer for growth. |
| timeout = 840 |
| } |
| } |
| } |
| |
| if (is_fuchsia) { |
| # Now build all of those (and more) together into the core-tests |
| # binary. This can and must be run directly from userboot because |
| # some of the tests require the root resource handle or no system |
| # services whatsoever. |
| zbi_test_executable("core-tests-standalone") { |
| deps = [ |
| "//src/zircon/testing/standalone-test", |
| "//zircon/system/ulib/zxtest", |
| ] |
| |
| deps += all_bootfs_tests + unified_only |
| |
| # These arguments are always needed in the ZBI to run this executable. |
| data_deps = [ ":core-tests-standalone.args" ] |
| |
| # LTO for this target requires a massive amount of memory, |
| # and thus, should be run less concurrently with other large jobs. |
| # See https://fxbug.dev/338504187 for context. |
| if (is_lto_variant || optimize == "size_lto") { |
| pool = "//build/config:highmem($default_toolchain)" |
| if (link_rbe_enable) { |
| # OOM on RBE workers |
| configs += [ "//build/config:no_remote_link" ] |
| } |
| } |
| } |
| |
| kernel_cmdline("core-tests-standalone.args") { |
| args = [ |
| "kernel.vdso.always_use_next=true", |
| "kernel.enable-debugging-syscalls=true", |
| "kernel.test.ram.reserve=0x8000", |
| "kernel.compression.strategy=lz4", |
| "kernel.compression.storage-strategy=tri_page", |
| "kernel.compression.reclaim_anonymous=true", |
| "kernel.compression.reclaim_zero_forks=true", |
| "kernel.compression.random-debug-compress=true", |
| ] |
| |
| # Only add this switch if we're building with ZX_DEBUG_ASSERT enabled |
| # in the kernel, or we'll trigger a panic on kernel start. Some kernel |
| # code asserts that this switch is only set for a debug configuration. |
| if (zx_assert_level > 1) { |
| args += [ "kernel.pmm.alloc-random-should-wait=true" ] |
| } |
| } |
| } |
| |
| boot_tests = [ ":core-tests" ] |
| |
| core_tests("core-tests") { |
| device_types = kernel_test_device_types |
| } |
| |
| # If we are building for x64, make sure to run the core tests on a system which |
| # has been configured to force selection of HPET as the timing source instead |
| # of choosing TSC if possible. |
| if (current_cpu == "x64") { |
| core_tests("core-tests-hpet") { |
| args = [ "kernel.wallclock=hpet" ] |
| device_types = [ "Intel NUC Kit NUC7i5DNHE" ] |
| |
| # TODO(b/336639740): Re-enable cuckoo for core-tests-hpet when |
| # underlying issue is fixed. |
| generate_cuckoo = false |
| |
| # core-hpet test is taking longer than 14mins. Bump the timeout to 16mins |
| # as a mitigation. |
| timeout = 960 |
| } |
| |
| boot_tests += [ ":core-tests-hpet" ] |
| } |
| |
| if (current_cpu == "arm64") { |
| _smccc11_device_types = [ |
| "AEMU", |
| "Astro", |
| "QEMU", |
| "Sherlock", |
| ] |
| foreach(alternate, |
| [ |
| { |
| option = "auto" |
| device_types = kernel_test_device_types |
| }, |
| { |
| option = "arch3" |
| device_types = _smccc11_device_types |
| }, |
| { |
| option = "arch1" |
| device_types = _smccc11_device_types |
| }, |
| { |
| option = "psci" |
| device_types = _smccc11_device_types |
| }, |
| { |
| option = "smccc10" |
| device_types = kernel_test_device_types |
| }, |
| ]) { |
| core_tests("core-tests-workaround-${alternate.option}") { |
| args = [ "kernel.arm64.alternate-vbar=${alternate.option}" ] |
| device_types = alternate.device_types |
| } |
| boot_tests += [ ":core-tests-workaround-${alternate.option}" ] |
| } |
| } |
| |
| # TODO(https://fxbug.dev/42170495): Remove once migration is complete. |
| core_tests("core-tests-serial-migration") { |
| args = [ "kernel.experimental.serial_migration=true" ] |
| device_types = [ "QEMU" ] |
| } |
| boot_tests += [ ":core-tests-serial-migration" ] |
| |
| group("boot_tests") { |
| testonly = true |
| deps = boot_tests |
| } |