tests: extract _test_virtio_block_topology wrapper

Extract test logic from test_virtio_block_topology into
a shared _test_virtio_block_topology wrapper function in
tests_wrappers.rs. The loop device creation and cleanup
are kept in the parent test case. 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:35:09 -07:00
committed by Rob Bradford
parent 8f40aed0ca
commit ef81bb1358
2 changed files with 67 additions and 69 deletions

View File

@@ -2803,3 +2803,68 @@ pub(crate) fn _test_disk_hotplug(guest: &Guest, landlock_enabled: bool) {
handle_child_output(r, &output);
}
pub(crate) fn _test_virtio_block_topology(guest: &Guest, loop_dev: &str) {
let mut child = GuestCommand::new(guest)
.default_cpus()
.default_memory()
.default_kernel_cmdline()
.args([
"--disk",
format!(
"path={}",
guest.disk_config.disk(DiskType::OperatingSystem).unwrap()
)
.as_str(),
format!(
"path={}",
guest.disk_config.disk(DiskType::CloudInit).unwrap()
)
.as_str(),
format!("path={loop_dev}").as_str(),
])
.default_net()
.capture_output()
.spawn()
.unwrap();
let r = std::panic::catch_unwind(|| {
guest.wait_vm_boot().unwrap();
// MIN-IO column
assert_eq!(
guest
.ssh_command("lsblk -t| grep vdc | awk '{print $3}'")
.unwrap()
.trim()
.parse::<u32>()
.unwrap_or_default(),
4096
);
// PHY-SEC column
assert_eq!(
guest
.ssh_command("lsblk -t| grep vdc | awk '{print $5}'")
.unwrap()
.trim()
.parse::<u32>()
.unwrap_or_default(),
4096
);
// LOG-SEC column
assert_eq!(
guest
.ssh_command("lsblk -t| grep vdc | awk '{print $6}'")
.unwrap()
.trim()
.parse::<u32>()
.unwrap_or_default(),
4096
);
});
kill_child(&mut child);
let output = child.wait_with_output().unwrap();
handle_child_output(r, &output);
}