From 6a76a6772d1e19f5ec54ce23d2e5080333ec4a9f Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Thu, 16 Dec 2021 17:18:04 +0000 Subject: [PATCH] tests: Add integration test for virtio-block topology This test relies on using losetup with a block size to create a block device from a file that has a specific block size for the topology detection code to pick up and passthrough to the guest. Signed-off-by: Rob Bradford --- tests/integration.rs | 101 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/tests/integration.rs b/tests/integration.rs index abd9d85e0..75f6b9d1e 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -4996,6 +4996,107 @@ mod tests { handle_child_output(r, &output); } + #[test] + fn test_virtio_block_topology() { + let focal = UbuntuDiskConfig::new(FOCAL_IMAGE_NAME.to_string()); + let guest = Guest::new(Box::new(focal)); + + let kernel_path = direct_kernel_boot_path(); + let test_disk_path = guest.tmp_dir.as_path().join("test.img"); + + Command::new("qemu-img") + .args(&[ + "create", + "-f", + "raw", + test_disk_path.to_str().unwrap(), + "16M", + ]) + .output() + .expect("qemu-img command failed"); + let out = Command::new("losetup") + .args(&[ + "--show", + "--find", + "--sector-size=4096", + test_disk_path.to_str().unwrap(), + ]) + .output() + .expect("failed to create loop device") + .stdout; + let _tmp = String::from_utf8_lossy(&out); + let loop_dev = _tmp.trim(); + + let mut child = GuestCommand::new(&guest) + .args(&["--cpus", "boot=1"]) + .args(&["--memory", "size=512M"]) + .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(None).unwrap(); + + // MIN-IO column + assert_eq!( + guest + .ssh_command("lsblk -t| grep vdc | awk '{print $3}'") + .unwrap() + .trim() + .parse::() + .unwrap_or_default(), + 4096 + ); + // PHY-SEC column + assert_eq!( + guest + .ssh_command("lsblk -t| grep vdc | awk '{print $5}'") + .unwrap() + .trim() + .parse::() + .unwrap_or_default(), + 4096 + ); + // LOG-SEC column + assert_eq!( + guest + .ssh_command("lsblk -t| grep vdc | awk '{print $6}'") + .unwrap() + .trim() + .parse::() + .unwrap_or_default(), + 4096 + ); + }); + + let _ = child.kill(); + let output = child.wait_with_output().unwrap(); + + handle_child_output(r, &output); + + Command::new("losetup") + .args(&["-d", loop_dev]) + .output() + .expect("loop device not found"); + } + #[test] fn test_virtio_balloon() { let focal = UbuntuDiskConfig::new(FOCAL_IMAGE_NAME.to_string());