vm-virtio: checked_descriptor: Add unit test for exhausted chain

After the iterator yields the only descriptor in a chain, the
subsequent None must reflect exhaustion rather than a validation
failure, so failed and failed_addr stay unset.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
Anatol Belski
2026-05-15 01:30:35 +02:00
committed by Rob Bradford
parent f700b10cfd
commit 43ced114aa

View File

@@ -458,4 +458,16 @@ mod unit_tests {
// translated one.
assert_eq!(result.unwrap_err(), GuestAddress(gva));
}
#[test]
fn exhausted_chain_returns_none() {
// After the iterator yields the only descriptor in the chain, the
// subsequent None must reflect exhaustion, not a validation failure.
let (_mem, mem_atomic, mut queue) = setup_vq(128 * 1024, 0x4000, 256, 0);
let mem_guard = mem_atomic.memory();
let mut chain = queue.pop_descriptor_chain(mem_guard).unwrap();
let mut it = chain.checked_iter(None);
it.next().unwrap().unwrap();
assert!(it.next().is_none());
}
}