summary refs log tree commit diff
diff options
context:
space:
mode:
authorTrent Begin <tbegin@google.com>2019-06-17 13:48:06 -0600
committerCommit Bot <commit-bot@chromium.org>2019-06-20 18:08:25 +0000
commit923bab011fad05dac0433f4ac1d36463c978cdd1 (patch)
treefeec47fe51cba1377ca4452b96092e2459b037c2
parentbb340d9a94d48514cbe310d05e1ce539aae31264 (diff)
downloadcrosvm-923bab011fad05dac0433f4ac1d36463c978cdd1.tar
crosvm-923bab011fad05dac0433f4ac1d36463c978cdd1.tar.gz
crosvm-923bab011fad05dac0433f4ac1d36463c978cdd1.tar.bz2
crosvm-923bab011fad05dac0433f4ac1d36463c978cdd1.tar.lz
crosvm-923bab011fad05dac0433f4ac1d36463c978cdd1.tar.xz
crosvm-923bab011fad05dac0433f4ac1d36463c978cdd1.tar.zst
crosvm-923bab011fad05dac0433f4ac1d36463c978cdd1.zip
crosvm: default serial parameter `num` field to 1 if not provided
If multiple serial parameters do not have `num` fields, or a different
parameter has already defined serial num 1, then crosvm will show an
error.

BUG=chromium:974885
TEST=cargo test; emerge-sarien crosvm && cros deploy dut crosvm;
Manual testing with and without num field in --serial parameter

Change-Id: Ia80247e8d055179adfd9e7471a98e8a2923cf1f1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1662773
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Trent Begin <tbegin@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Trent Begin <tbegin@chromium.org>
-rw-r--r--src/main.rs11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs
index 9e1bf31..64001a4 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -247,7 +247,7 @@ fn parse_serial_options(s: &str) -> argument::Result<SerialParameters> {
     let mut serial_setting = SerialParameters {
         type_: SerialType::Sink,
         path: None,
-        num: 0,
+        num: 1,
         console: false,
     };
 
@@ -832,11 +832,11 @@ fn run_vm(args: std::env::Args) -> std::result::Result<(), ()> {
           Argument::flag("cras-capture", "Enable capturing audio from CRAS server to the cras-audio device"),
           Argument::flag("null-audio", "Add an audio device to the VM that plays samples to /dev/null"),
           Argument::value("serial",
-                          "type=TYPE,[path=PATH,num=NUM,console]",
+                          "type=TYPE,[num=NUM,path=PATH,console]",
                           "Comma seperated key=value pairs for setting up serial devices. Can be given more than once.
                           Possible key values:
                           type=(stdout,syslog,sink,file) - Where to route the serial device
-                          num=(1,2,3,4) - Serial Device Number
+                          num=(1,2,3,4) - Serial Device Number. If not provided, num will default to 1.
                           path=PATH - The path to the file to write to when type=file
                           console - Use this serial device as the guest console. Can only be given once. Will default to first serial port if not provided.
                           "),
@@ -1418,6 +1418,11 @@ mod tests {
     }
 
     #[test]
+    fn parse_serial_valid_no_num() {
+        parse_serial_options("type=syslog").expect("parse should have succeded");
+    }
+
+    #[test]
     fn parse_serial_invalid_type() {
         parse_serial_options("type=wormhole,num=1").expect_err("parse should have failed");
     }