mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
block: qcow: Test aligned_pwrite pass through path
Write 4096 bytes of pattern data at offset 0 using AlignedBuf and verify data integrity via plain pread_exact. All parameters are naturally aligned to 512 so the fast path is exercised. Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
committed by
Rob Bradford
parent
05d52d0353
commit
32af2f2a22
@@ -1789,4 +1789,22 @@ mod unit_tests {
|
|||||||
.collect();
|
.collect();
|
||||||
assert_eq!(buf, expected);
|
assert_eq!(buf, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_aligned_pwrite_pass_through() {
|
||||||
|
// When buffer address, length, and offset are all aligned,
|
||||||
|
// aligned_pwrite should take the fast path.
|
||||||
|
let size = 4096usize;
|
||||||
|
let (_tf, fd) = create_pattern_file(size);
|
||||||
|
let alignment = 512;
|
||||||
|
|
||||||
|
let data: Vec<u8> = (0..size).map(|i| ((i + 1) % 251) as u8).collect();
|
||||||
|
let mut abuf = AlignedBuf::new(size, alignment).unwrap();
|
||||||
|
abuf.as_mut_slice(size).copy_from_slice(&data);
|
||||||
|
aligned_pwrite(fd, abuf.as_slice(size), 0, alignment).unwrap();
|
||||||
|
|
||||||
|
let mut readback = vec![0u8; size];
|
||||||
|
pread_exact(fd, &mut readback, 0).unwrap();
|
||||||
|
assert_eq!(readback, data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user