mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vm-virtio: checked_descriptor: Add unit test for accessors
Drive a two descriptor chain with a writable head and a zero length tail and verify the CheckedDescriptor accessors addr, len, is_empty, is_write_only and has_next agree with the descriptor flags and length on each entry. Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
committed by
Rob Bradford
parent
43ced114aa
commit
496ac197e6
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user