| # 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/rust/rustc_test.gni") |
| import("//src/starnix/build/args.gni") |
| import("//src/starnix/kernel/starnix.gni") |
| import("//src/starnix/tests/build/starnix_linux_test_component.gni") |
| |
| template("rust_syscall_test") { |
| _test_name = target_name |
| if (defined(invoker.test_name)) { |
| _test_name = invoker.test_name |
| } |
| |
| _test_binary_name = "starnix_rust_${target_name}_bin" |
| if (_test_name != target_name) { |
| _test_binary_name = "starnix_rust_${target_name}_${_test_name}_bin" |
| } |
| |
| _source_root = "src/${_test_name}.rs" |
| if (defined(invoker.source_root)) { |
| _source_root = invoker.source_root |
| } |
| |
| _sources = [] |
| if (defined(invoker.sources)) { |
| _sources = invoker.sources |
| } else { |
| _sources = [ _source_root ] |
| } |
| |
| _deps = [] |
| if (defined(invoker.deps)) { |
| _deps = invoker.deps |
| } |
| |
| _resources = [] |
| if (defined(invoker.resources)) { |
| _resources = invoker.resources |
| } |
| |
| # Build the Rust test binary for the target Linux toolchain |
| rustc_test(_test_binary_name) { |
| edition = "2024" |
| source_root = _source_root |
| sources = _sources |
| deps = _deps |
| } |
| |
| # Generate the component manifest |
| _manifest_label = "${target_name}.cml" |
| _manifest_file = "$target_gen_dir/${_manifest_label}" |
| generated_file(_manifest_label) { |
| outputs = [ _manifest_file ] |
| output_conversion = "json" |
| _program = { |
| binary = "data/tests/${_test_binary_name}" |
| } |
| if (defined(invoker.test_target_kernel)) { |
| _program.test_target_kernel = invoker.test_target_kernel |
| } |
| |
| _includes = [] |
| if (defined(invoker.includes)) { |
| _includes = invoker.includes |
| } |
| |
| contents = { |
| include = [ |
| "//src/starnix/tests/syscalls/rust/meta/syscalls_libtest.shard.cml", |
| ] |
| include += _includes |
| program = _program |
| } |
| } |
| |
| # Define the test component |
| starnix_linux_test_component(target_name) { |
| test_label = ":${_test_binary_name}" |
| test_binary = _test_binary_name |
| manifest = _manifest_file |
| deps = [ ":${_manifest_label}" ] |
| foreach(_resource, _resources) { |
| deps += [ "${_resource}($target_linux_toolchain)" ] |
| } |
| uses_expectations = true |
| generated_expectations = ":syscalls_rust_test_expectations" |
| test_type = "starnix" |
| |
| if (defined(invoker.custom_expectations)) { |
| generated_expectations = |
| "${invoker.custom_expectations}($target_linux_toolchain)" |
| } |
| } |
| } |