block: qcow: Test decompress_cluster deflate roundtrip

Compress a known 64K buffer with raw deflate, pass it through
decompress_cluster with ZlibDecoder, and verify the output matches
the original data.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
Anatol Belski
2026-04-18 00:01:19 +02:00
committed by Rob Bradford
parent a502354619
commit ed9154b39d

View File

@@ -304,7 +304,8 @@ pub(crate) mod unit_tests {
use flate2::write::DeflateEncoder;
use vmm_sys_util::tempfile::TempFile;
use super::pread_alloc;
use super::{decompress_cluster, pread_alloc};
use crate::qcow::decoder::ZlibDecoder;
const COMPRESSED_FLAG: u64 = 1 << 62;
const CLUSTER_USED_FLAG: u64 = 1 << 63;
@@ -422,4 +423,17 @@ pub(crate) mod unit_tests {
pread_alloc(file.as_raw_fd(), 4000, 200).unwrap_err();
}
#[test]
fn test_decompress_cluster() {
let cluster_size = 65536;
let original: Vec<u8> = (0..=255).cycle().take(cluster_size).collect();
let mut encoder = DeflateEncoder::new(Vec::new(), Compression::default());
encoder.write_all(&original).unwrap();
let compressed = encoder.finish().unwrap();
let result = decompress_cluster(&compressed, cluster_size, &ZlibDecoder {}).unwrap();
assert_eq!(result, original);
}
}