From fec52fab2327afae6705ac73ced9b29d63637c1e Mon Sep 17 00:00:00 2001 From: Andrew Yao Date: Sun, 5 May 2024 21:57:01 -0500 Subject: [PATCH] -Utilized Option instead of Vector to store IRQ lines for MMIO devices. -Add test to test this. -Update existing tests Signed-off-by: Andrew Yao Co-authored-by: Himanshu Reddy Co-authored-by: Goldin Vo --- src/vmm/src/device_manager/mmio.rs | 33 ++++++++++++++---------------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/vmm/src/device_manager/mmio.rs b/src/vmm/src/device_manager/mmio.rs index 82afa7f88db9..fb3a183eb9d9 100644 --- a/src/vmm/src/device_manager/mmio.rs +++ b/src/vmm/src/device_manager/mmio.rs @@ -741,7 +741,6 @@ mod tests { assert_eq!(dummy.queues().len(), QUEUE_SIZES.len()); } - // NOTE: we are also failing this test now #[test] fn test_device_info() { let start_addr1 = GuestAddress(0x0); @@ -820,30 +819,31 @@ mod tests { } #[test] - fn test_slot_irq_allocation() { + fn test_no_irq_allocation() { let mut device_manager = MMIODeviceManager::new(); let mut resource_allocator = ResourceAllocator::new().unwrap(); + let device_info = device_manager .allocate_mmio_resources(&mut resource_allocator, 0) .unwrap(); assert!(device_info.irq.is_none()); + } + + #[test] + fn test_irq_allocation() { + let mut device_manager = MMIODeviceManager::new(); + let mut resource_allocator = ResourceAllocator::new().unwrap(); + let device_info = device_manager .allocate_mmio_resources(&mut resource_allocator, 1) .unwrap(); assert_eq!(device_info.irq.unwrap().get(), crate::arch::IRQ_BASE); - assert_eq!( - format!( - "{}", - device_manager - .allocate_mmio_resources( - &mut resource_allocator, - crate::arch::IRQ_MAX - crate::arch::IRQ_BASE + 1 - ) - .unwrap_err() - ), - "Invalid MMIO IRQ configuration." - .to_string() - ); + } + + #[test] + fn test_allocation_failure() { + let mut device_manager = MMIODeviceManager::new(); + let mut resource_allocator = ResourceAllocator::new().unwrap(); assert_eq!( format!( "{}", @@ -854,8 +854,5 @@ mod tests { "Invalid MMIO IRQ configuration." .to_string() ); - device_manager - .allocate_mmio_resources(&mut resource_allocator, 0) - .unwrap(); } }