From dda89d70273470bb71e102c6b912d3cc17f7260f Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Tue, 25 Nov 2025 04:27:52 +0000 Subject: [PATCH] tests: Check disk consistency after use We've encountered issues that Cloud Hypervisor corrupts disk images after use. Those issues may not be immediately obvious until the corrupted images are used again. Run consistency checks over the disk images in the test cases to catch issues as early as possible. Signed-off-by: Wei Liu --- tests/integration.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/integration.rs b/tests/integration.rs index 468ab36b7..845121635 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -3489,24 +3489,59 @@ mod common_parallel { _test_virtio_block(FOCAL_IMAGE_NAME, true, true); } + /// Uses `qemu-img check` to verify disk image consistency. + /// + /// Supported formats are `qcow2` (compressed and uncompressed), + /// `vhdx`, `qed`, `parallels`, `vmdk`, and `vdi`. See man page + /// for more details. + /// + /// It takes either a full path to the image or just the name of + /// the image located in the `workloads` directory. + fn disk_check_consistency(path_or_image_name: impl AsRef) { + let path = if path_or_image_name.as_ref().exists() { + // A full path is provided + path_or_image_name.as_ref().to_path_buf() + } else { + // An image name is provided + let mut workload_path = dirs::home_dir().unwrap(); + workload_path.push("workloads"); + workload_path.as_path().join(path_or_image_name.as_ref()) + }; + + let output = std::process::Command::new("qemu-img") + .args(["check", path.to_str().unwrap()]) + .output() + .expect("should spawn and run command successfully"); + + assert!( + output.status.success(), + "qemu-img check failed: {}", + String::from_utf8_lossy(&output.stderr) + ); + } + #[test] fn test_virtio_block_qcow2() { _test_virtio_block(JAMMY_IMAGE_NAME_QCOW2, false, false); + disk_check_consistency(JAMMY_IMAGE_NAME_QCOW2); } #[test] fn test_virtio_block_qcow2_zlib() { _test_virtio_block(JAMMY_IMAGE_NAME_QCOW2_ZLIB, false, false); + disk_check_consistency(JAMMY_IMAGE_NAME_QCOW2_ZLIB); } #[test] fn test_virtio_block_qcow2_zstd() { _test_virtio_block(JAMMY_IMAGE_NAME_QCOW2_ZSTD, false, false); + disk_check_consistency(JAMMY_IMAGE_NAME_QCOW2_ZSTD); } #[test] fn test_virtio_block_qcow2_backing_file() { _test_virtio_block(JAMMY_IMAGE_NAME_QCOW2_BACKING_FILE, false, false); + disk_check_consistency(JAMMY_IMAGE_NAME_QCOW2_BACKING_FILE); } #[test] @@ -3556,6 +3591,7 @@ mod common_parallel { .expect("Expect generating dynamic VHDx image from RAW image"); _test_virtio_block(FOCAL_IMAGE_NAME_VHDX, false, false); + disk_check_consistency(FOCAL_IMAGE_NAME_VHDX); } #[test] @@ -3635,6 +3671,8 @@ mod common_parallel { let output = cloud_child.wait_with_output().unwrap(); handle_child_output(r, &output); + + disk_check_consistency(vhdx_path); } fn vhdx_image_size(disk_name: &str) -> u64 {