vm-virtio: checked_descriptor: Add unit test for zero length descriptor

Add passes_through_zero_length_descriptor which submits a descriptor
with len 0 and verifies CheckedDescriptorIter yields it without
performing a guest memory range check.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
Anatol Belski
2026-05-14 21:33:53 +02:00
committed by Rob Bradford
parent 782ce21c1a
commit 3ced92702a

View File

@@ -238,4 +238,17 @@ mod unit_tests {
let result = it.next().expect("iterator must yield an item");
result.unwrap_err();
}
#[test]
fn passes_through_zero_length_descriptor() {
let (_mem, mem_atomic, mut queue) = setup_vq(128 * 1024, 0x4000, 0, 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 desc = it
.next()
.unwrap()
.expect("zero length descriptor must pass through");
assert_eq!(desc.len(), 0);
}
}