Skip to content

Commit

Permalink
-Utilized Option instead of Vector to store IRQ lines for MMIO devices.
Browse files Browse the repository at this point in the history
-Add test to test this.
-Update existing tests

Signed-off-by: Andrew Yao <[email protected]>
Co-authored-by: Himanshu Reddy <[email protected]>
Co-authored-by: Goldin Vo <[email protected]>
  • Loading branch information
3 people committed May 7, 2024
1 parent 46005b0 commit fec52fa
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions src/vmm/src/device_manager/mmio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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!(
"{}",
Expand All @@ -854,8 +854,5 @@ mod tests {
"Invalid MMIO IRQ configuration."
.to_string()
);
device_manager
.allocate_mmio_resources(&mut resource_allocator, 0)
.unwrap();
}
}

0 comments on commit fec52fa

Please sign in to comment.