vm-virtio: checked_descriptor: Add unit test for next_checked exhaustion

Cover the exhausted path of the DescriptorChainExt::next_checked
trait method, asserting that Ok(None) is returned once the chain
has no further descriptors.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
Anatol Belski
2026-05-15 01:04:32 +02:00
committed by Rob Bradford
parent be432bda07
commit 3b1afe3e3d

View File

@@ -313,4 +313,16 @@ mod unit_tests {
assert_eq!(desc.addr().0, 0x4000);
assert_eq!(desc.len(), 256);
}
#[test]
fn next_checked_returns_none_when_exhausted() {
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();
// Consume the single descriptor.
let _ = chain.next_checked(None).unwrap().unwrap();
// The chain is now exhausted; expect Ok(None).
let res = chain.next_checked(None);
assert!(matches!(res, Ok(None)));
}
}