#[path = "../../../os-pci-interrupts/src/lib.rs"] mod pci_interrupts; use pci_interrupts::{Error, RouteTable, Source, swizzle}; #[test] fn os_pci_interrupts_positive() { let pin_on_inner_bridge = swizzle(1, 2).unwrap(); let root_pin = swizzle(pin_on_inner_bridge, 1).unwrap(); assert_eq!((pin_on_inner_bridge, root_pin), (3, 4)); let root = Source::new(0, 3, 0, root_pin).unwrap(); let peer = Source::new(0, 4, 0, 1).unwrap(); let mut routes = RouteTable::<2>::new(); let first = routes.claim(root, 37).unwrap(); let shared = routes.claim(peer, 37).unwrap(); assert_eq!(routes.resolve(root), Ok(37)); assert_eq!(routes.resolve(peer), Ok(37)); assert_eq!(routes.count(), 2); routes.release(shared).unwrap(); routes.release(first).unwrap(); assert_eq!(routes.count(), 0); } #[test] fn os_pci_interrupts_negative() { assert_eq!(swizzle(0, 1), Err(Error::InvalidPin)); assert_eq!(Source::new(0, 32, 0, 1), Err(Error::InvalidSlot)); let root = Source::new(0, 3, 0, 1).unwrap(); let mut routes = RouteTable::<2>::new(); let first = routes.claim(root, 45).unwrap(); let before = routes.snapshot(); assert_eq!(routes.claim(root, 46), Err(Error::DuplicateSource)); assert_eq!(routes.claim(Source::new(0, 5, 0, 1).unwrap(), 31), Err(Error::InvalidSpi)); assert_eq!(routes.resolve(Source::new(0, 6, 0, 1).unwrap()), Err(Error::MissingRoute)); assert_eq!(routes.snapshot(), before); routes.release(first).unwrap(); assert_eq!(routes.count(), 0); }