mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
block: qcow: Add AlignedBuf allocation and access test
Test AlignedBuf with 512 and 4096 byte alignment. Verify pointer alignment, zero initialization, and write/read round trip. Passes under miri. Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
committed by
Rob Bradford
parent
11cf332114
commit
a84a0b8b25
@@ -1884,4 +1884,23 @@ mod unit_tests {
|
||||
let after: Vec<u8> = (after_start..file_size).map(|i| (i % 251) as u8).collect();
|
||||
assert_eq!(&whole[after_start..], &after[..]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_aligned_buf_allocation_and_access() {
|
||||
for alignment in [512, 4096] {
|
||||
let size = 1024usize;
|
||||
let mut abuf = AlignedBuf::new(size, alignment).unwrap();
|
||||
let aligned_size = size.next_multiple_of(alignment);
|
||||
|
||||
assert!(
|
||||
(abuf.ptr() as usize).is_multiple_of(alignment),
|
||||
"ptr not aligned to {alignment}"
|
||||
);
|
||||
assert!(abuf.as_slice(aligned_size).iter().all(|&b| b == 0));
|
||||
|
||||
let pattern: Vec<u8> = (0..size).map(|i| (i % 251) as u8).collect();
|
||||
abuf.as_mut_slice(size).copy_from_slice(&pattern);
|
||||
assert_eq!(abuf.as_slice(size), &pattern[..]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user