Skip to content

Commit 2cacbf4

Browse files
committed
refactor(queue): remove avail_event method from unit tests
We can directly access `used_ring.avail_event()` now. Signed-off-by: Egor Lazarchuk <[email protected]>
1 parent f4054c7 commit 2cacbf4

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

src/vmm/src/devices/virtio/queue.rs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,17 +1212,7 @@ mod tests {
12121212
use crate::devices::virtio::queue::QueueError::DescIndexOutOfBounds;
12131213
use crate::devices::virtio::test_utils::{default_mem, VirtQueue};
12141214
use crate::utilities::test_utils::{multi_region_mem, single_region_mem};
1215-
use crate::vstate::memory::{GuestAddress, GuestMemoryMmap};
1216-
1217-
impl Queue {
1218-
fn avail_event(&self, mem: &GuestMemoryMmap) -> u16 {
1219-
let avail_event_addr = self
1220-
.used_ring_address
1221-
.unchecked_add(u64::from(4 + 8 * self.actual_size()));
1222-
1223-
mem.read_obj::<u16>(avail_event_addr).unwrap()
1224-
}
1225-
}
1215+
use crate::vstate::memory::GuestAddress;
12261216

12271217
#[test]
12281218
fn test_checked_new_descriptor_chain() {
@@ -1416,15 +1406,15 @@ mod tests {
14161406

14171407
// There are no more descriptors, but notification suppression is disabled.
14181408
// Calling pop_or_enable_notification() should simply return None.
1419-
assert_eq!(q.avail_event(m), 0);
1409+
assert_eq!(*q.used_ring.avail_event(), 0);
14201410
assert!(q.pop_or_enable_notification().is_none());
1421-
assert_eq!(q.avail_event(m), 0);
1411+
assert_eq!(*q.used_ring.avail_event(), 0);
14221412

14231413
// There are no more descriptors and notification suppression is enabled. Calling
14241414
// pop_or_enable_notification() should enable notifications.
14251415
q.enable_notif_suppression();
14261416
assert!(q.pop_or_enable_notification().is_none());
1427-
assert_eq!(q.avail_event(m), 2);
1417+
assert_eq!(*q.used_ring.avail_event(), 2);
14281418
}
14291419

14301420
#[test]
@@ -1623,18 +1613,18 @@ mod tests {
16231613

16241614
// Notification suppression is disabled. try_enable_notification shouldn't do anything.
16251615
assert!(q.try_enable_notification());
1626-
assert_eq!(q.avail_event(m), 0);
1616+
assert_eq!(*q.used_ring.avail_event(), 0);
16271617

16281618
// Enable notification suppression and check again. There is 1 available descriptor chain.
16291619
// Again nothing should happen.
16301620
q.enable_notif_suppression();
16311621
assert!(!q.try_enable_notification());
1632-
assert_eq!(q.avail_event(m), 0);
1622+
assert_eq!(*q.used_ring.avail_event(), 0);
16331623

16341624
// Consume the descriptor. avail_event should be modified
16351625
assert!(q.pop().is_some());
16361626
assert!(q.try_enable_notification());
1637-
assert_eq!(q.avail_event(m), 1);
1627+
assert_eq!(*q.used_ring.avail_event(), 1);
16381628
}
16391629

16401630
#[test]

0 commit comments

Comments
 (0)