vm-virtio: checked_descriptor: Add unit test for failed_addr

Drive CheckedDescriptorIter with an out of range descriptor and
assert that failed_addr returns Some carrying the GuestAddress of
the rejected descriptor, not just the failed boolean.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
Anatol Belski
2026-05-15 01:25:09 +02:00
committed by Rob Bradford
parent 356f153085
commit 2eddaf506e

View File

@@ -336,4 +336,14 @@ mod unit_tests {
.expect_err("validation must reject the descriptor");
assert_eq!(err.0, 0x4000);
}
#[test]
fn err_reports_rejected_address() {
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 mut it = chain.checked_iter(None);
let result = it.next().expect("must yield an item");
assert_eq!(result.unwrap_err(), GuestAddress(0x4000));
}
}