From d1ba50f10e15066eb70585df2efdba5557202e14 Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 31 Oct 2023 17:51:13 +0800 Subject: [PATCH] tests: Add a test simultaneously set serial and console as TTY mode Add a test that supports configuring serial and console as TTY mode at the same time. With this configuration, the VM can set up a legacy serial device as an early printk console device, and then change to a virito console device after the virito console device is initialized. In this case, we can capture the logs printed by legacy serial on early boot, and later by the virtio console. Signed-off-by: Yong He --- tests/integration.rs | 52 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/tests/integration.rs b/tests/integration.rs index 90932c961..7a0c5fb04 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -7093,6 +7093,58 @@ mod common_parallel { handle_child_output(r, &output); } + + #[test] + #[cfg(target_arch = "x86_64")] + fn test_double_tty() { + let focal = UbuntuDiskConfig::new(FOCAL_IMAGE_NAME.to_string()); + let guest = Guest::new(Box::new(focal)); + let mut cmd = GuestCommand::new(&guest); + let api_socket = temp_api_path(&guest.tmp_dir); + let tty_str: &str = "console=hvc0 earlyprintk=ttyS0 "; + // linux printk module enable console log. + let con_dis_str: &str = "console [hvc0] enabled"; + // linux printk module disable console log. + let con_enb_str: &str = "bootconsole [earlyser0] disabled"; + + let kernel_path = direct_kernel_boot_path(); + + cmd.args(["--cpus", "boot=1"]) + .args(["--memory", "size=512M"]) + .args(["--kernel", kernel_path.to_str().unwrap()]) + .args([ + "--cmdline", + DIRECT_KERNEL_BOOT_CMDLINE + .replace("console=hvc0 ", tty_str) + .as_str(), + ]) + .capture_output() + .default_disks() + .default_net() + .args(["--serial", "tty"]) + .args(["--console", "tty"]) + .args(["--api-socket", &api_socket]); + + let mut child = cmd.spawn().unwrap(); + + let mut r = std::panic::catch_unwind(|| { + guest.wait_vm_boot(None).unwrap(); + }); + + let _ = child.kill(); + let output = child.wait_with_output().unwrap(); + + if r.is_ok() { + r = std::panic::catch_unwind(|| { + let s = String::from_utf8_lossy(&output.stdout); + assert!(s.contains(tty_str)); + assert!(s.contains(con_dis_str)); + assert!(s.contains(con_enb_str)); + }); + } + + handle_child_output(r, &output); + } } mod dbus_api {