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:
Anatol Belski
2026-05-15 01:17:04 +02:00
committed by Rob Bradford
parent 3b1afe3e3d
commit 356f153085

View File

@@ -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);
}
}