mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
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:
committed by
Rob Bradford
parent
8f40aed0ca
commit
ef81bb1358
@@ -2803,3 +2803,68 @@ pub(crate) fn _test_disk_hotplug(guest: &Guest, landlock_enabled: bool) {
|
|||||||
|
|
||||||
handle_child_output(r, &output);
|
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);
|
||||||
|
}
|
||||||
|
|||||||
@@ -3251,10 +3251,7 @@ mod common_parallel {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_virtio_block_topology() {
|
fn test_virtio_block_topology() {
|
||||||
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));
|
|
||||||
|
|
||||||
let kernel_path = direct_kernel_boot_path();
|
|
||||||
let test_disk_path = guest.tmp_dir.as_path().join("test.img");
|
let test_disk_path = guest.tmp_dir.as_path().join("test.img");
|
||||||
|
|
||||||
let output = exec_host_command_output(
|
let output = exec_host_command_output(
|
||||||
@@ -3271,71 +3268,7 @@ mod common_parallel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let loop_dev = create_loop_device(test_disk_path.to_str().unwrap(), 4096, 5);
|
let loop_dev = create_loop_device(test_disk_path.to_str().unwrap(), 4096, 5);
|
||||||
|
_test_virtio_block_topology(&guest, &loop_dev);
|
||||||
let mut child = GuestCommand::new(&guest)
|
|
||||||
.default_cpus()
|
|
||||||
.default_memory()
|
|
||||||
.args(["--kernel", kernel_path.to_str().unwrap()])
|
|
||||||
.args(["--cmdline", DIRECT_KERNEL_BOOT_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);
|
|
||||||
|
|
||||||
Command::new("losetup")
|
Command::new("losetup")
|
||||||
.args(["-d", &loop_dev])
|
.args(["-d", &loop_dev])
|
||||||
.output()
|
.output()
|
||||||
|
|||||||
Reference in New Issue
Block a user