diff --git a/vm-virtio/src/checked_descriptor.rs b/vm-virtio/src/checked_descriptor.rs index 34f266e06..f2b3cba6b 100644 --- a/vm-virtio/src/checked_descriptor.rs +++ b/vm-virtio/src/checked_descriptor.rs @@ -470,4 +470,34 @@ mod unit_tests { it.next().unwrap().unwrap(); assert!(it.next().is_none()); } + + #[test] + fn accessors_reflect_underlying_descriptor() { + // Two descriptor chain: a non-empty writable head followed by a + // zero length tail. Verify the CheckedDescriptor accessors agree + // with the descriptor flags and length on each entry. + let (_mem, mem_atomic, mut queue) = setup_vq_chain( + 128 * 1024, + &[(0x4000, 256, VRING_DESC_F_WRITE as u16), (0x5000, 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 head = it.next().unwrap().expect("head must be Ok"); + assert_eq!(head.addr().0, 0x4000); + assert_eq!(head.len(), 256); + assert!(!head.is_empty()); + assert!(head.is_write_only()); + assert!(head.has_next()); + + let tail = it.next().unwrap().expect("tail must be Ok"); + assert_eq!(tail.addr().0, 0x5000); + assert_eq!(tail.len(), 0); + assert!(tail.is_empty()); + assert!(!tail.is_write_only()); + assert!(!tail.has_next()); + + assert!(it.next().is_none()); + } }