mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
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:
committed by
Rob Bradford
parent
af7fabd2c6
commit
c1d929d0cf
@@ -2577,3 +2577,57 @@ pub(crate) fn _test_memory_overhead(guest: &Guest, guest_memory_size_kb: u32) {
|
|||||||
|
|
||||||
handle_child_output(r, &output);
|
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);
|
||||||
|
}
|
||||||
|
|||||||
@@ -2864,66 +2864,8 @@ mod common_parallel {
|
|||||||
// the path for the hotplug disk is not pre-added to Landlock rules, this
|
// the path for the hotplug disk is not pre-added to Landlock rules, this
|
||||||
// the test will result in a failure.
|
// the test will result in a failure.
|
||||||
fn test_landlock() {
|
fn test_landlock() {
|
||||||
let disk_config = UbuntuDiskConfig::new(JAMMY_IMAGE_NAME.to_string());
|
let guest = basic_regular_guest!(JAMMY_IMAGE_NAME);
|
||||||
let guest = Guest::new(Box::new(disk_config));
|
_test_landlock(&guest);
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
let kernel_path = direct_kernel_boot_path();
|
|
||||||
#[cfg(target_arch = "aarch64")]
|
|
||||||
let kernel_path = edk2_path();
|
|
||||||
|
|
||||||
let api_socket = temp_api_path(&guest.tmp_dir);
|
|
||||||
|
|
||||||
let mut child = GuestCommand::new(&guest)
|
|
||||||
.args(["--api-socket", &api_socket])
|
|
||||||
.default_cpus()
|
|
||||||
.default_memory()
|
|
||||||
.args(["--kernel", kernel_path.to_str().unwrap()])
|
|
||||||
.args(["--cmdline", DIRECT_KERNEL_BOOT_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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn _test_disk_hotplug(landlock_enabled: bool) {
|
fn _test_disk_hotplug(landlock_enabled: bool) {
|
||||||
|
|||||||
Reference in New Issue
Block a user