#[path = "../../../os-pci-resources/src/device_map.rs"] mod pci_device_map; use pci_device_map::{Aperture, Attribute, Error, PageMapTable, PAGE_SIZE}; #[test] fn os_pci_device_map_positive() { let low = Aperture::new(0x1000_0000, 0x2000_0000).unwrap(); let high = Aperture::new(0x80_0000_0000, 0x80_1000_0000).unwrap(); let mut maps = PageMapTable::<2>::new(); let first = maps.claim(0x1000_0000, PAGE_SIZE, low).unwrap(); let second = maps.claim(0x80_0000_0000, 4 * PAGE_SIZE, high).unwrap(); assert_eq!(first.attribute, Attribute::DeviceNgRnE); assert_eq!(second.attribute, Attribute::DeviceNgRnE); assert_eq!(maps.snapshot().entries, [Some(first), Some(second)]); maps.release(second).unwrap(); maps.release(first).unwrap(); assert_eq!(maps.count(), 0); } #[test] fn os_pci_device_map_negative() { assert_eq!(Aperture::new(0x1000_0001, 0x2000_0000), Err(Error::InvalidAperture)); let aperture = Aperture::new(0x1000_0000, 0x2000_0000).unwrap(); let mut maps = PageMapTable::<1>::new(); let prior = maps.claim(0x1000_0000, PAGE_SIZE, aperture).unwrap(); let before = maps.snapshot(); assert_eq!(maps.claim(0x3000_0000, PAGE_SIZE, aperture), Err(Error::OutsideAperture)); assert_eq!(maps.claim(0x1fff_f000, 2 * PAGE_SIZE, aperture), Err(Error::OutsideAperture)); assert_eq!(maps.claim(0x1000_0001, PAGE_SIZE, aperture), Err(Error::Unaligned)); assert_eq!(maps.claim(0x1000_0000, PAGE_SIZE, aperture), Err(Error::Overlap)); assert_eq!(maps.snapshot(), before); maps.release(prior).unwrap(); assert_eq!(maps.count(), 0); }