From 143d63c88e4b13295844aeff4203d911646d2a3f Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Thu, 2 Apr 2020 16:52:58 +0100 Subject: [PATCH] vmm: config: Add unit test for console parsing Signed-off-by: Rob Bradford --- vmm/src/config.rs | 55 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/vmm/src/config.rs b/vmm/src/config.rs index c78166a30..ef8fd5570 100644 --- a/vmm/src/config.rs +++ b/vmm/src/config.rs @@ -1585,4 +1585,59 @@ mod tests { Ok(()) } + + #[test] + fn test_console_parsing() -> Result<()> { + assert!(ConsoleConfig::parse("").is_err()); + assert!(ConsoleConfig::parse("badmode").is_err()); + assert_eq!( + ConsoleConfig::parse("off")?, + ConsoleConfig { + mode: ConsoleOutputMode::Off, + iommu: false, + file: None, + } + ); + assert_eq!( + ConsoleConfig::parse("tty")?, + ConsoleConfig { + mode: ConsoleOutputMode::Tty, + iommu: false, + file: None, + } + ); + assert_eq!( + ConsoleConfig::parse("null")?, + ConsoleConfig { + mode: ConsoleOutputMode::Null, + iommu: false, + file: None, + } + ); + assert_eq!( + ConsoleConfig::parse("file=/tmp/console")?, + ConsoleConfig { + mode: ConsoleOutputMode::File, + iommu: false, + file: Some(PathBuf::from("/tmp/console")) + } + ); + assert_eq!( + ConsoleConfig::parse("null,iommu=on")?, + ConsoleConfig { + mode: ConsoleOutputMode::Null, + iommu: true, + file: None, + } + ); + assert_eq!( + ConsoleConfig::parse("file=/tmp/console,iommu=on")?, + ConsoleConfig { + mode: ConsoleOutputMode::File, + iommu: true, + file: Some(PathBuf::from("/tmp/console")) + } + ); + Ok(()) + } }