tests: extract _test_landlock to tests_wrappers

Extract test logic from test_landlock into a shared
_test_landlock wrapper function in tests_wrappers.rs.
Update the parent test case to use the basic_regular_guest
macro. The wrapper uses default_kernel_cmdline() for
kernel/cmdline setup.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
This commit is contained in:
Muminul Islam
2026-03-21 18:30:30 -07:00
committed by Rob Bradford
parent af7fabd2c6
commit c1d929d0cf
2 changed files with 56 additions and 60 deletions

View File

@@ -2577,3 +2577,57 @@ pub(crate) fn _test_memory_overhead(guest: &Guest, guest_memory_size_kb: u32) {
handle_child_output(r, &output);
}
pub(crate) fn _test_landlock(guest: &Guest) {
let api_socket = temp_api_path(&guest.tmp_dir);
let mut child = GuestCommand::new(guest)
.args(["--api-socket", &api_socket])
.default_cpus()
.default_memory()
.default_kernel_cmdline()
.args(["--landlock"])
.default_disks()
.default_net()
.capture_output()
.spawn()
.unwrap();
let r = std::panic::catch_unwind(|| {
guest.wait_vm_boot().unwrap();
// Check /dev/vdc is not there
assert_eq!(
guest
.ssh_command("lsblk | grep -c vdc.*16M || true")
.unwrap()
.trim()
.parse::<u32>()
.unwrap_or(1),
0
);
// Now let's add the extra disk.
let mut blk_file_path = dirs::home_dir().unwrap();
blk_file_path.push("workloads");
blk_file_path.push("blk.img");
// As the path to the hotplug disk is not pre-added, this remote
// command will fail.
assert!(!remote_command(
&api_socket,
"add-disk",
Some(
format!(
"path={},id=test0,readonly=true",
blk_file_path.to_str().unwrap()
)
.as_str()
),
));
});
let _ = child.kill();
let output = child.wait_with_output().unwrap();
handle_child_output(r, &output);
}