mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
block: qcow: Test compressed cluster read via QcowFile
Write a known data pattern through QcowFile, compress all clusters in place, reopen and read back via the seek based file_read path. This covers the decompress_l2_cluster code path used by QcowFile which is separate from the pread based path in QcowSync/QcowAsync. Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
committed by
Rob Bradford
parent
365ed236cc
commit
519acda794
@@ -2353,6 +2353,7 @@ mod unit_tests {
|
||||
|
||||
use super::util::{COMPRESSED_FLAG, ZERO_FLAG};
|
||||
use super::*;
|
||||
use crate::qcow_common::unit_tests::compress_allocated_clusters;
|
||||
|
||||
fn valid_header_v3() -> Vec<u8> {
|
||||
vec![
|
||||
@@ -4590,4 +4591,27 @@ mod unit_tests {
|
||||
assert_eq!(qcow.header.version, 2);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_compressed_read() {
|
||||
let cluster_size = 65536usize;
|
||||
let data: Vec<u8> = (0..=255).cycle().take(cluster_size).collect();
|
||||
let temp = TempFile::new().unwrap();
|
||||
{
|
||||
let raw_file = RawFile::new(temp.as_file().try_clone().unwrap(), false);
|
||||
let mut qcow = QcowFile::new(raw_file, 3, 100 * 1024 * 1024, false).unwrap();
|
||||
qcow.seek(SeekFrom::Start(0)).unwrap();
|
||||
qcow.write_all(&data).unwrap();
|
||||
qcow.flush().unwrap();
|
||||
}
|
||||
|
||||
compress_allocated_clusters(&mut temp.as_file().try_clone().unwrap());
|
||||
|
||||
let raw_file = RawFile::new(temp.as_file().try_clone().unwrap(), false);
|
||||
let mut qcow = QcowFile::from(raw_file).unwrap();
|
||||
qcow.seek(SeekFrom::Start(0)).unwrap();
|
||||
let mut buf = vec![0u8; cluster_size];
|
||||
qcow.read_exact(&mut buf).unwrap();
|
||||
assert_eq!(buf, data);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user