blob: 222d61863935afae9a5f09c27f9d46a021084701 [file]
# Copyright 2023 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.gni")
import("//build/test.gni")
import("//build/testing/host_test.gni")
import("//build/testing/host_test_data.gni")
import("//src/lib/testing/expectation/generated_expectations_file.gni")
import("//src/starnix/build/args.gni")
import("//src/starnix/kernel/starnix.gni")
import("//src/starnix/tests/build/starnix_linux_test_component.gni")
import("//src/starnix/tests/environments.gni")
import("//src/starnix/tests/starnix_test_subpackages.gni")
import("//src/starnix/tests/syscalls/cpp/syscall_test.gni")
import("//src/storage/ext4/testing/test_ext4_server.gni")
# The "vanilla" syscall tests, e.g. those that do not have deps to package and
# can be run on both arch32 and arch64.
syscall_tests_without_deps = [
# go/keep-sorted start
"abort_test",
"aio_test",
"anon_test",
"ashmem_test",
"aspace_test",
"binder_test",
"bpf_test",
"cache_flush_test",
"cgroup_freezer_test",
"cgroup_test",
"cpuinfo_test",
"custom_artifact_test",
"epoll_test",
"fallocate_test",
"fcntl_test",
"fs_test",
"fsverity_test",
"getrandom_test",
"inotify_test",
"io_uring_test",
"kcmp_test",
"membarrier_test",
"memfd_test",
"mmap_test",
"netlink_test",
"perf_event_open_test",
"personality_test",
"pidfd_test",
"pipe_test",
"poll_test",
"pressure_test",
"process_mrelease_test",
"procfs_mem_test",
"read_write_test",
"reboot_test",
"renameat2_exchange_sticky_test",
"restart_read_test",
"rlimit_test",
"sched_test",
"seccomp_test",
"sendfile_test",
"setpriority_test",
"signalfd_test",
"socket_test",
"sw_breakpoint_test",
"symlink_test",
"sync_test",
"sysctl_test",
"sysfs_kernel_test",
"sysfs_power_test",
"sysinfo_test",
"syslog_test",
"terminal_test",
"test_helper_test",
"thread_group_lifecycle_test",
"timerfd_test",
"tmpfs_test",
"trivial_test",
"tun_test",
"uio_test",
"userfaultfd_test",
"vdso_test",
"vmsplice_test",
"waitpid_exit_signal_test",
"waitpid_flags_test",
"xattr_test",
"zombie_test",
# go/keep-sorted end
]
syscall_tests_etc = [
{
name = "exit_test"
# Test exit without running at_exit and this mislead sanitizers.
disable_sanitizers_on_host = true
},
{
name = "ioctl_test"
container_config = {
extra_features = [ "framebuffer" ]
}
},
{
name = "fuchsia_network_monitor_fs_test"
container_config = {
extra_features = [ "network_manager" ]
}
},
{
name = "touch_standby_test"
container_config = {
extra_features = [ "framebuffer" ]
}
},
{
name = "udev_test"
container_config = {
extra_features = [ "framebuffer" ]
}
},
{
name = "mount_test"
resources = [
":hello_world_resource",
":mount_ext4_img",
":simple_erofs_image",
]
executables = [
"test_programs:custom_pt_interp_child",
"test_programs:exit_zero",
]
},
{
name = "time_test"
container_config = {
enable_utc_time_adjustment = true
}
},
{
name = "loop_test"
resources = [ ":hello_world_resource" ]
},
{
name = "fuse_test"
resources = [ ":fuse_overlayfs" ]
},
{
name = "ptrace_test"
executables = [ ":ptrace_test_exec_child" ]
},
{
name = "extended_pstate_test"
executables = [ ":extended_pstate_initial_state_child" ]
},
{
name = "suid_test"
executables = [ ":print_uid_gid_exec_child" ]
},
{
name = "signal_handling_test"
executables = [
":ptrace_test_exec_child",
":signal_handling_test_exec_child",
"test_programs:signal_handling_test_exec_parent_after_exit",
"test_programs:signal_handling_test_exec_parent_before_exit",
]
},
{
name = "exec_test"
executables = [ ":print_uid_gid_exec_child" ]
},
{
name = "procfs_test"
executables = [ ":procfs_test_exec_child" ]
},
{
name = "futex_test"
executables = [ ":syscall_test_exec_child" ]
},
{
name = "capabilities_test"
executables = [ "test_programs:print_helper" ]
},
{
name = "prctl_test"
executables = [ "test_programs:print_helper" ]
},
{
name = "overlayfs_test"
executables = [
":print_uid_gid_exec_child",
"test_programs:exit_zero",
]
},
{
name = "task_test"
executables = [
"test_programs:clone_exec_helper",
"test_programs:custom_pt_interp_child",
"test_programs:exit_zero",
]
},
{
name = "timers_test"
executables = [ ":timers_test_exec_child" ]
},
]
# Flaky tests are run with debug logging on, for diagnostics.
# TODO: b/449149502 - Move the test back into syscall_tests_etc once diagnosed.
syscall_tests_flaky = [
{
name = "timerfd_mutable_test"
container_config = {
extra_features = []
enable_utc_time_adjustment = true
}
},
]
if (target_cpu == "x64") {
# TODO(https://fxbug.dev/42059962): arm64 emulator does not have Vulkan support yet.
# These tests require test-ui-stack.
syscall_tests_etc += [
{
name = "input_test"
container_config = {
extra_features = [ "framebuffer" ]
}
},
{
name = "uinput_test"
container_config = {
extra_features = [ "framebuffer" ]
}
},
]
}
mlock_onfault_behaviors = [
true,
false,
]
mlock_pin_flavors = [
"noop",
"shadow_process",
"vmar_always_need",
]
foreach(onfault_behavior, mlock_onfault_behaviors) {
foreach(pin_flavor, mlock_pin_flavors) {
mlock_defines = []
if (onfault_behavior) {
onfault_str = "_always_onfault"
mlock_defines = [ "MLOCK_ALWAYS_ONFAULT" ]
} else {
onfault_str = ""
}
syscall_tests_etc += [
{
name = "mlock_test${onfault_str}_${pin_flavor}_pin"
sources = [ "mlock_test.cc" ]
defines = mlock_defines
# Sanitizer runtimes stub out mlock() because it is incompatible with
# their virtual memory management.
disable_sanitizers_on_host = true
container_config = {
mlock_always_onfault = onfault_behavior
mlock_pin_flavor = pin_flavor
}
},
]
}
}
# This is a temporary list of host tests which have been fully migrated to
# Machina. These tests will NOT be built and ran against the host. This list
# will be removed once migration is fully complete.
syscall_tests_migrated_to_machina = [
# Note that mlock_test is fully migrated to Machina, but since the target name
# is dynamically generated it's not easy to filter it this way. It'll get
# cleaned up once the full migration is complete and host tests are completely
# turned down.
# go/keep-sorted start
"abort_test",
"aspace_test",
"bpf_test",
"capabilities_test",
"cgroup_freezer_test",
"cgroup_test",
"cpuinfo_test",
"custom_artifact_test",
"epoll_test",
"exec_test",
"exit_test",
"extended_pstate_test",
"fallocate_test",
"fcntl_test",
"fs_test",
"fsverity_test",
"fuchsia_network_monitor_fs_test",
"fuse_test",
"futex_test",
"getrandom_test",
"inotify_test",
"io_uring_test",
"ioctl_test",
"loop_test",
"membarrier_test",
"memfd_test",
"mmap_test",
"mount_test",
"netlink_test",
"overlayfs_test",
"pidfd_test",
"pipe_test",
"poll_test",
"prctl_test",
"pressure_test",
"process_mrelease_test",
"procfs_mem_test",
"procfs_test",
"ptrace_test",
"read_write_test",
"reboot_test",
"restart_read_test",
"rlimit_test",
"sched_test",
"seccomp_test",
"sendfile_test",
"setpriority_test",
"signal_handling_test",
"signalfd_test",
"socket_test",
"suid_test",
"sw_breakpoint_test",
"symlink_test",
"sync_test",
"sysctl_test",
"sysfs_kernel_test",
"sysfs_power_test",
"syslog_test",
"task_test",
"test_helper_test",
"thread_group_lifecycle_test",
"time_test",
"timerfd_test",
"timers_test",
"tmpfs_test",
"touch_standby_test",
"trivial_test",
"tun_test",
"udev_test",
"uio_test",
"userfaultfd_test",
"vdso_test",
"vmsplice_test",
"waitpid_exit_signal_test",
"waitpid_flags_test",
"zombie_test",
# go/keep-sorted end
]
if (target_cpu == "x64") {
# TODO(https://fxbug.dev/42059962): Join this with the normal inclusions.
syscall_tests_migrated_to_machina += [
"input_test",
"uinput_test",
]
}
all_test_names = syscall_tests_without_deps
foreach(test_def, syscall_tests_etc) {
all_test_names += [ test_def.name ]
}
# Build a list of tests to run against the host.
# TODO(b/435279160): Once all tests are migrated, simplify the build target
# filtering logic.
legacy_host_tests = all_test_names
foreach(test_name, syscall_tests_migrated_to_machina) {
# If the user has set starnix_force_build_host_tests, skip any filtering and
# build all the tests. Otherwise, Machina is the preferred environment and
# we'll filter out migrated targets.
if (!starnix_force_build_host_tests) {
legacy_host_tests -= [ test_name ]
}
}
# TODO: b/449149502 - Remove once diagnosed.
all_flaky_test_names = []
foreach(test_def, syscall_tests_flaky) {
all_flaky_test_names += [ test_def.name ]
}
group("tests") {
testonly = true
deps = [
":starnix_syscalls_cpp_flaky_tests",
":starnix_syscalls_cpp_tests",
]
if (current_cpu == "arm64") {
deps += [
":starnix_arch32_syscalls_cpp_flaky_tests",
":starnix_arch32_syscalls_cpp_tests",
]
}
if (host_os == "linux" && host_cpu == "x64") {
foreach(test_name, legacy_host_tests) {
deps += [
# These are Linux tests which haven't migrated to Machina, build and run
# them as host tests.
":starnix_${test_name}_baseline($host_toolchain)",
]
}
}
}
group("linux_vm_tests") {
testonly = true
deps = [ ":linux_syscalls_cpp_tests" ]
}
source_set("test_utils") {
testonly = true
sources = [
"binder/client.cc",
"binder/client.h",
"binder/common.cc",
"binder/common.h",
"binder/manager.cc",
"binder/manager.h",
"binder/manager_provider_client_test.h",
"binder/provider.cc",
"binder/provider.h",
"binder_helper.cc",
"binder_helper.h",
"capabilities_helper.cc",
"capabilities_helper.h",
"fault_test.h",
"fault_test_suite.h",
"io_uring_helper.cc",
"io_uring_helper.h",
"proc_test_base.h",
"syscall_matchers.h",
"task_test.h",
"test_helper.cc",
"test_helper.h",
]
public_deps = [
"//sdk/lib/fit",
"//third_party/googletest:gmock",
"//third_party/googletest:gtest",
"//third_party/rapidjson",
"//zircon/system/ulib/fbl",
]
deps = [ "//src/lib/fxl" ]
configs += [ "//build/config:rtti" ]
}
if (current_cpu == "x64" || current_cpu == "arm64") {
resource("fuse_overlayfs") {
sources = []
if (current_cpu == "x64") {
sources += [ "//prebuilt/starnix/fuse-overlayfs-amd64/fuse-overlayfs" ]
}
if (current_cpu == "arm64") {
sources += [ "//prebuilt/starnix/fuse-overlayfs-arm64/fuse-overlayfs" ]
}
outputs = [ "data/fuse-overlayfs" ]
}
} else {
group("fuse_overlayfs") {
}
}
resource("mount_ext4_img") {
sources = [ "data/mount_ext4.img" ]
outputs = [ "data/mount_ext4.img" ]
}
resource("hello_world_resource") {
sources = [ "data/hello_world.txt" ]
outputs = [ "data/hello_world.txt" ]
}
resource("simple_erofs_image") {
sources = [
"//src/storage/erofs/testing/data/simple.erofs",
"//src/storage/erofs/testing/data/simple/file1",
]
outputs = [ "data/{{source_file_part}}" ]
}
resource_from_executables("test_helper_executables") {
executables = [
# go/keep-sorted start
":extended_pstate_initial_state_child",
":print_uid_gid_exec_child",
":procfs_test_exec_child",
":ptrace_test_exec_child",
":signal_handling_test_exec_child",
":syscall_test_exec_child",
":timers_test_exec_child",
"test_programs:clone_exec_helper",
"test_programs:custom_pt_interp_child",
"test_programs:exit_zero",
"test_programs:print_helper",
"test_programs:signal_handling_test_exec_parent_after_exit",
"test_programs:signal_handling_test_exec_parent_before_exit",
# go/keep-sorted end
]
toolchain = target_linux_toolchain
}
group("syscall_test_deps") {
testonly = true
deps = [
# go/keep-sorted start
":fuse_overlayfs",
":hello_world_resource",
":mount_ext4_img",
":simple_erofs_image",
":test_helper_executables",
# go/keep-sorted end
]
}
config("march") {
if (current_cpu == "riscv64") {
# Keep `march` consistent with the value used by Android, see
# https://cs.android.com/android/platform/superproject/+/master:build/soong/cc/config/riscv64_device.go;drc=726b001ae1a3388f65b571350bef4d373a3768c8;l=36
cflags = [ "-march=rv64gcv_zba_zbb_zbs" ]
}
}
# Starnix tests: default to empty resources and executables
foreach(test_name, syscall_tests_without_deps) {
syscall_test(test_name) {
}
}
foreach(test_def, syscall_tests_etc) {
syscall_test(test_def.name) {
forward_variables_from(test_def, "*", [ "name" ])
}
}
# TODO: b/449149502 - Remove once diagnosed.
foreach(test_def, syscall_tests_flaky) {
syscall_test(test_def.name) {
forward_variables_from(test_def, "*", [ "name" ])
}
}
test("crash") {
sources = [ "crash.cc" ]
deps = [
":test_utils",
"//src/lib/fxl/test:gtest_main",
"//third_party/googletest:gtest",
]
}
if (is_linux) {
executable("extended_pstate_initial_state_child") {
testonly = true
emit_tool_path = false
# TODO(https://fxbug.dev/297293167) enable ASan instrumentation for Linux binaries in Starnix
exclude_toolchain_tags = [ "instrumented" ]
sources = [ "extended_pstate_initial_state_child.cc" ]
# This binary does not use libc or a dynamic linker since it is testing the
# state presented to _start.
disable_syslog_backend = true
cflags = [ "-fno-builtin" ]
ldflags = [
"-nostdlib",
"-nostartfiles",
"-static-pie",
]
configs -= [
"//build/config/linux:default-pie",
"//build/config/linux:implicit-host-libs",
]
# This config is also applied by the syscall_test() template and is
# necessary for vector instructions to compile on riscv64.
configs += [ ":march" ]
}
executable("procfs_test_exec_child") {
testonly = true
emit_tool_path = false
sources = [ "procfs_test_exec_child.cc" ]
exclude_toolchain_tags = [ "coverage" ]
deps = [ ":test_utils" ]
}
executable("ptrace_test_exec_child") {
testonly = true
emit_tool_path = false
sources = [ "ptrace_test_exec_child.cc" ]
exclude_toolchain_tags = [ "coverage" ]
deps = [ ":test_utils" ]
}
executable("signal_handling_test_exec_child") {
testonly = true
emit_tool_path = false
sources = [ "signal_handling_test_exec_child.cc" ]
exclude_toolchain_tags = [ "coverage" ]
deps = [ ":test_utils" ]
}
executable("syscall_test_exec_child") {
testonly = true
emit_tool_path = false
sources = [ "syscall_test_exec_child.cc" ]
exclude_toolchain_tags = [ "coverage" ]
deps = [ ":test_utils" ]
}
executable("timers_test_exec_child") {
testonly = true
emit_tool_path = false
sources = [ "timers_test_exec_child.cc" ]
exclude_toolchain_tags = [ "coverage" ]
deps = [ ":test_utils" ]
}
executable("print_uid_gid_exec_child") {
testonly = true
emit_tool_path = false
sources = [ "print_uid_gid_exec_child.cc" ]
exclude_toolchain_tags = [ "coverage" ]
deps = [ ":test_utils" ]
}
}
generated_expectations_file("syscalls_cpp_test_expectations") {
includes = [
"expectations/syscalls_cpp_test.json5",
"expectations/syscalls_cpp_test_${current_cpu}.json5",
]
if (current_toolchain == target_linux_arch32_toolchain) {
includes += [ "expectations/syscalls_cpp_test_arch32.json5" ]
}
}
generated_expectations_file("linux_cpp_test_expectations") {
includes = [ "expectations/linux_syscalls_cpp_test.json5" ]
}
starnix_linux_test_component("crash_test") {
test_label = ":crash"
test_binary = "crash"
test_type = "starnix"
}
foreach(test_name, syscall_tests_without_deps) {
syscall_test("linux_${test_name}") {
test_name = test_name
test_target_kernel = "linux"
custom_expectations = ":linux_cpp_test_expectations"
}
}
foreach(test_def, syscall_tests_etc) {
syscall_test("linux_${test_def.name}") {
test_name = test_def.name
forward_variables_from(test_def,
"*",
[
"name",
"resources",
"executables",
])
test_target_kernel = "linux"
custom_expectations = ":linux_cpp_test_expectations"
}
}
fuchsia_test_package("linux_syscalls_cpp_tests") {
test_components = []
deps = []
foreach(test_name, all_test_names) {
test_components += [ ":linux_${test_name}" ]
deps += [ ":linux_${test_name}_config" ]
}
subpackages = starnix_test_subpackages
subpackages += [ "//src/starnix/containers/debian:debian_package" ]
if (target_cpu == "x64") {
# TODO(https://fxbug.dev/42059962): arm64 emulator does not have Vulkan support yet.
# Without Vulkan, test-ui-stack will stuck on Scenic startup.
subpackages += [ "//src/ui/testing/test_ui_stack:test-ui-stack" ]
}
deps += [ "//src/lib/testing/expectation:expectation_comparer" ]
test_specs = {
# TODO(https://fxbug.dev/319150842): GCE doesn't support Vulkan, so, for now, just disable all
# of these tests on GCE.
_env = basic_envs
_env += [ gce_env ]
_env -= [ gce_env ]
if (_env == []) {
build_only = true
} else {
environments = _env
}
log_settings = {
# Tests exercise failure cases, so ERROR logs are expected.
max_severity = "ERROR"
}
package_resolution_timeout_secs = 660
}
}
# TODO: b/449149502 - Remove once diagnosed.
fuchsia_test_package("starnix_syscalls_cpp_flaky_tests") {
test_components = [ ":crash_test" ]
deps = []
foreach(test_name, all_flaky_test_names) {
test_components += [ ":${test_name}" ]
deps += [ ":${test_name}_config" ]
}
subpackages = starnix_test_subpackages
subpackages += [ "//src/starnix/containers/debian:debian_package" ]
if (target_cpu == "x64") {
# TODO(https://fxbug.dev/42059962): arm64 emulator does not have Vulkan support yet.
# Without Vulkan, test-ui-stack will stuck on Scenic startup.
subpackages += [ "//src/ui/testing/test_ui_stack:test-ui-stack" ]
}
deps += [ "//src/lib/testing/expectation:expectation_comparer" ]
test_specs = {
environments = basic_envs
log_settings = {
# Tests exercise failure cases, so ERROR logs are expected.
max_severity = "ERROR"
# Flaky tests need additional diagnostics.
min_severity = "DEBUG"
}
package_resolution_timeout_secs = 660
}
}
syscall_test("ext4_write_test") {
includes =
[ "//src/starnix/tests/syscalls/cpp/meta/ext4_write_test.shard.cml" ]
resources = [ ":hello_world_resource" ]
}
ext4_test_server("ext4_write_test_pkg") {
image = "data/mount_ext4.img"
}
fuchsia_test_package("starnix_syscalls_cpp_tests") {
test_components = [
":crash_test",
":ext4_write_test",
]
deps = []
foreach(test_name, all_test_names) {
test_components += [ ":${test_name}" ]
deps += [ ":${test_name}_config" ]
}
subpackages = starnix_test_subpackages
subpackages += [
"//src/starnix/containers/debian:debian_package",
":ext4_write_test_pkg",
]
if (target_cpu == "x64") {
# TODO(https://fxbug.dev/42059962): arm64 emulator does not have Vulkan support yet.
# Without Vulkan, test-ui-stack will stuck on Scenic startup.
subpackages += [ "//src/ui/testing/test_ui_stack:test-ui-stack" ]
}
deps += [ "//src/lib/testing/expectation:expectation_comparer" ]
test_specs = {
# TODO(https://fxbug.dev/319150842): GCE doesn't support Vulkan, so, for now, just disable all
# of these tests on GCE.
_env = basic_envs
_env += [ gce_env ]
_env -= [ gce_env ]
if (_env == []) {
build_only = true
} else {
environments = _env
}
log_settings = {
# Tests exercise failure cases, so ERROR logs are expected.
max_severity = "ERROR"
}
package_resolution_timeout_secs = 660
}
}
if (current_cpu == "arm64") {
fuchsia_test_package("starnix_arch32_syscalls_cpp_tests") {
test_components = []
deps = []
foreach(test_name, all_test_names) {
test_components += [ ":${test_name}_arch32" ]
deps += [ ":${test_name}_config" ]
}
subpackages = starnix_test_subpackages
subpackages += [ "//src/starnix/containers/debian:debian_package" ]
if (target_cpu == "x64") {
# TODO(https://fxbug.dev/42059962): arm64 emulator does not have Vulkan support yet.
# Without Vulkan, test-ui-stack will stuck on Scenic startup.
subpackages += [ "//src/ui/testing/test_ui_stack:test-ui-stack" ]
}
deps += [ "//src/lib/testing/expectation:expectation_comparer" ]
test_specs = {
# TODO(https://fxbug.dev/319150842): GCE doesn't support Vulkan, so, for now, just disable all
# of these tests on GCE.
_env = arch32_envs
_env += [ gce_env ]
_env -= [ gce_env ]
if (_env == []) {
build_only = true
} else {
environments = _env
}
log_settings = {
# Tests exercise failure cases, so ERROR logs are expected.
max_severity = "ERROR"
}
package_resolution_timeout_secs = 660
}
}
# TODO: b/449149502 - Remove once diagnosed.
fuchsia_test_package("starnix_arch32_syscalls_cpp_flaky_tests") {
test_components = []
deps = []
foreach(test_name, all_flaky_test_names) {
test_components += [ ":${test_name}_arch32" ]
deps += [ ":${test_name}_config" ]
}
subpackages = starnix_test_subpackages
subpackages += [ "//src/starnix/containers/debian:debian_package" ]
if (target_cpu == "x64") {
# TODO(https://fxbug.dev/42059962): arm64 emulator does not have Vulkan support yet.
# Without Vulkan, test-ui-stack will stuck on Scenic startup.
subpackages += [ "//src/ui/testing/test_ui_stack:test-ui-stack" ]
}
deps += [ "//src/lib/testing/expectation:expectation_comparer" ]
test_specs = {
# TODO(https://fxbug.dev/319150842): GCE doesn't support Vulkan, so, for now, just disable all
# of these tests on GCE.
_env = arch32_envs
_env += [ gce_env ]
_env -= [ gce_env ]
if (_env == []) {
build_only = true
} else {
environments = _env
}
log_settings = {
# Tests exercise failure cases, so ERROR logs are expected.
max_severity = "ERROR"
}
package_resolution_timeout_secs = 660
}
}
}