mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
block: qcow: Add aligned_pread unaligned offset test
Test that aligned_pread handles a non aligned offset by rounding down, reading an aligned region, and returning the correct slice from within the bounce buffer. Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
committed by
Rob Bradford
parent
021838b63c
commit
05d52d0353
@@ -1769,4 +1769,24 @@ mod unit_tests {
|
||||
let expected: Vec<u8> = (0..size).map(|i| (i % 251) as u8).collect();
|
||||
assert_eq!(buf, &expected[..]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_aligned_pread_unaligned_offset() {
|
||||
// Read at an offset that is not a multiple of alignment.
|
||||
// aligned_pread should round down the offset, read an aligned
|
||||
// region, then copy the correct slice into the caller buffer.
|
||||
let file_size = 8192usize;
|
||||
let (_tf, fd) = create_pattern_file(file_size);
|
||||
let alignment = 512;
|
||||
|
||||
let offset = 100u64;
|
||||
let len = 200usize;
|
||||
let mut buf = vec![0u8; len];
|
||||
aligned_pread(fd, &mut buf, offset, alignment).unwrap();
|
||||
|
||||
let expected: Vec<u8> = (offset as usize..offset as usize + len)
|
||||
.map(|i| (i % 251) as u8)
|
||||
.collect();
|
||||
assert_eq!(buf, expected);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user