From a85e2fa735c5bf1ed9a30fa79f13a91a088613be Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Thu, 2 Apr 2020 18:16:18 +0100 Subject: [PATCH] vmm: config: Add unit test for VFIO device parsing Signed-off-by: Rob Bradford --- vmm/src/config.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/vmm/src/config.rs b/vmm/src/config.rs index ea334c907..0e71a25c2 100644 --- a/vmm/src/config.rs +++ b/vmm/src/config.rs @@ -1657,4 +1657,36 @@ mod tests { ); Ok(()) } + + #[test] + fn test_device_parsing() -> Result<()> { + assert_eq!( + DeviceConfig::parse("path=/path/to/device")?, + DeviceConfig { + path: PathBuf::from("/path/to/device"), + id: None, + iommu: false + } + ); + + assert_eq!( + DeviceConfig::parse("path=/path/to/device,iommu=on")?, + DeviceConfig { + path: PathBuf::from("/path/to/device"), + id: None, + iommu: true + } + ); + + assert_eq!( + DeviceConfig::parse("path=/path/to/device,iommu=on,id=mydevice0")?, + DeviceConfig { + path: PathBuf::from("/path/to/device"), + id: Some("mydevice0".to_owned()), + iommu: true + } + ); + + Ok(()) + } }