Skip to content

Commit 87d211a

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 9d8fdb5 commit 87d211a

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
@@ -1177,17 +1177,7 @@ mod tests {
11771177
use crate::devices::virtio::queue::QueueError::DescIndexOutOfBounds;
11781178
use crate::devices::virtio::test_utils::{default_mem, VirtQueue};
11791179
use crate::utilities::test_utils::{multi_region_mem, single_region_mem};
1180-
use crate::vstate::memory::{GuestAddress, GuestMemoryMmap};
1181-
1182-
impl Queue {
1183-
fn avail_event(&self, mem: &GuestMemoryMmap) -> u16 {
1184-
let avail_event_addr = self
1185-
.used_ring_address
1186-
.unchecked_add(u64::from(4 + 8 * self.actual_size()));
1187-
1188-
mem.read_obj::<u16>(avail_event_addr).unwrap()
1189-
}
1190-
}
1180+
use crate::vstate::memory::GuestAddress;
11911181

11921182
#[test]
11931183
fn test_checked_new_descriptor_chain() {
@@ -1369,15 +1359,15 @@ mod tests {
13691359

13701360
// There are no more descriptors, but notification suppression is disabled.
13711361
// Calling pop_or_enable_notification() should simply return None.
1372-
assert_eq!(q.avail_event(m), 0);
1362+
assert_eq!(q.used_ring_avail_event_get(), 0);
13731363
assert!(q.pop_or_enable_notification().is_none());
1374-
assert_eq!(q.avail_event(m), 0);
1364+
assert_eq!(q.used_ring_avail_event_get(), 0);
13751365

13761366
// There are no more descriptors and notification suppression is enabled. Calling
13771367
// pop_or_enable_notification() should enable notifications.
13781368
q.enable_notif_suppression();
13791369
assert!(q.pop_or_enable_notification().is_none());
1380-
assert_eq!(q.avail_event(m), 2);
1370+
assert_eq!(q.used_ring_avail_event_get(), 2);
13811371
}
13821372

13831373
#[test]
@@ -1576,18 +1566,18 @@ mod tests {
15761566

15771567
// Notification suppression is disabled. try_enable_notification shouldn't do anything.
15781568
assert!(q.try_enable_notification());
1579-
assert_eq!(q.avail_event(m), 0);
1569+
assert_eq!(q.used_ring_avail_event_get(), 0);
15801570

15811571
// Enable notification suppression and check again. There is 1 available descriptor chain.
15821572
// Again nothing should happen.
15831573
q.enable_notif_suppression();
15841574
assert!(!q.try_enable_notification());
1585-
assert_eq!(q.avail_event(m), 0);
1575+
assert_eq!(q.used_ring_avail_event_get(), 0);
15861576

15871577
// Consume the descriptor. avail_event should be modified
15881578
assert!(q.pop().is_some());
15891579
assert!(q.try_enable_notification());
1590-
assert_eq!(q.avail_event(m), 1);
1580+
assert_eq!(q.used_ring_avail_event_get(), 1);
15911581
}
15921582

15931583
#[test]

0 commit comments

Comments
 (0)