#[path = "../../../os-pci-discovery/src/headers.rs"] mod pci_headers; use pci_headers::{Error, Header, HeaderKind, Inventory}; #[test] fn os_pci_discovery_headers_positive() { let single = Header::parse(0x1005_1af4, 0).unwrap(); assert_eq!((single.vendor_id, single.device_id, single.kind), (0x1af4, 0x1005, HeaderKind::Endpoint)); assert!(!single.multifunction); assert_eq!(single.function_count(), 1); assert!(single.allows(0)); assert!(!single.allows(1)); let multi = Header::parse(0x1005_1af4, 0x0080_0000).unwrap(); assert!(multi.multifunction); assert_eq!(multi.function_count(), 8); assert!(multi.allows(7)); assert!(!multi.allows(8)); let mut inventory = Inventory::<3>::new(); let first = inventory.publish(single, 0, 1, 0, 0x1005_1af4, 0).unwrap(); let second = inventory.publish(multi, 0, 2, 0, 0x1005_1af4, 0x0080_0000).unwrap(); let third = inventory.publish(multi, 0, 2, 7, 0x1006_1af4, 0).unwrap(); assert_eq!(inventory.snapshot().entries, [Some(first), Some(second), Some(third)]); assert_eq!(inventory.count(), 3); assert_eq!(Header::parse(0x1234_1af4, 0x0001_0000).unwrap().kind, HeaderKind::Bridge); assert_eq!(Header::parse(0x1234_1af4, 0x0002_0000).unwrap().kind, HeaderKind::CardBus); } #[test] fn os_pci_discovery_headers_negative() { let single = Header::parse(0x1005_1af4, 0).unwrap(); let mut inventory = Inventory::<2>::new(); let healthy = inventory.publish(single, 0, 1, 0, 0x1005_1af4, 0).unwrap(); let before = inventory.snapshot(); assert_eq!(inventory.publish(single, 0, 31, 0, 0xffff_ffff, 0xffff_ffff), Err(Error::Absent)); assert_eq!(inventory.snapshot(), before); assert_eq!(inventory.publish(single, 0, 1, 1, 0x1006_1af4, 0), Err(Error::FunctionOutOfScope)); assert_eq!(inventory.publish(single, 0, 1, 0, 0x1005_1af4, 0), Err(Error::Duplicate)); assert_eq!(inventory.publish(single, 0, 2, 0, 0x1005_1af4, 0x007f_0000), Err(Error::InvalidHeaderType)); assert_eq!(inventory.snapshot(), before); assert_eq!(inventory.snapshot().entries[0], Some(healthy)); assert_eq!(inventory.count(), 1); }