Skip to content

Commit 3f8352f

Browse files
committed
add a test
Signed-off-by: Egor Lazarchuk <[email protected]>
1 parent 9b52af9 commit 3f8352f

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/vmm/src/devices/virtio/iov_deque.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,4 +544,30 @@ mod tests {
544544
assert_eq!(iov.iov_len, 2 * copy[i].iov_len);
545545
}
546546
}
547+
548+
#[test]
549+
fn test_size_less_than_capacity() {
550+
const L: u16 = 16;
551+
let mut deque = super::IovDeque::<L>::new().unwrap();
552+
assert!(deque.as_mut_slice().is_empty());
553+
554+
// Number of times need to fill/empty the queue to reach the
555+
// pivot point.
556+
let fills = deque.capacity / L;
557+
// Almost reach the pivot.
558+
for _ in 0..(fills - 1) {
559+
for _ in 0..L {
560+
deque.push_back(make_iovec(0, 100));
561+
}
562+
deque.pop_front(L);
563+
}
564+
// Start filling the 'second' page
565+
for _ in 0..L {
566+
deque.push_back(make_iovec(1, 100));
567+
}
568+
// Pop one element to trigger the pivot.
569+
deque.pop_front(1);
570+
// Now the slice will
571+
assert_eq!(deque.as_slice(), vec![make_iovec(1, 100); L as usize - 1]);
572+
}
547573
}

0 commit comments

Comments
 (0)