mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vm-virtio: checked_descriptor: Add unit test for next_checked Err
Cover the rejection path of the trait method next_checked, asserting that an out of range descriptor is reported as Err(addr) carrying the original descriptor address. Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
committed by
Rob Bradford
parent
3b1afe3e3d
commit
356f153085
@@ -325,4 +325,15 @@ mod unit_tests {
|
||||
let res = chain.next_checked(None);
|
||||
assert!(matches!(res, Ok(None)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn next_checked_returns_err_on_invalid_descriptor() {
|
||||
let (_mem, mem_atomic, mut queue) = setup_vq(128 * 1024, 0x4000, 1 << 30, 0);
|
||||
let mem_guard = mem_atomic.memory();
|
||||
let mut chain = queue.pop_descriptor_chain(mem_guard).unwrap();
|
||||
let err = chain
|
||||
.next_checked(None)
|
||||
.expect_err("validation must reject the descriptor");
|
||||
assert_eq!(err.0, 0x4000);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user