From efe4d41ee27c5673003dadf39c9d81ab76277212 Mon Sep 17 00:00:00 2001 From: Xing Guo Date: Tue, 7 Oct 2025 20:12:52 +0800 Subject: [PATCH 1/2] Check QEMU process status before periodically checking socket files. Sometimes, the QEMU process exits early due to various reasons, e.g., the missing of kernel binary, providing incorrect qemu commandline arguments, ... and vmtest didn't check the exit status of QEMU and it will wait for 5 seconds to detect the error. This patch teaches vmtest exit earlier when the QEMU process exits unexpectedly. --- src/qemu.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/qemu.rs b/src/qemu.rs index 627a2d6..e223662 100644 --- a/src/qemu.rs +++ b/src/qemu.rs @@ -758,11 +758,26 @@ impl Qemu { } /// Waits for QMP and QGA sockets to appear - fn wait_for_qemu(&self) -> Result<()> { + fn wait_for_qemu(&self, child: &mut Child) -> Result<()> { let now = time::Instant::now(); let timeout = Duration::from_secs(5); while now.elapsed() < timeout { + // Before checking socket files, let's check if the child process fails to start. + match child + .try_wait() + .with_context(|| "Failed to inspect QEMU status".to_string())? + { + None => { /* QEMU is still running. */ } + Some(ec) => { + if ec.success() { + bail!("QEMU exits normally which is not expected") + } else { + bail!("QEMU fails to start: {}", Self::extract_child_stderr(child)) + } + } + } + let qga_ok = self .qga_sock .try_exists() @@ -1035,7 +1050,7 @@ impl Qemu { // Ensure child is cleaned up even if we bail early let mut child = scopeguard::guard(child, Self::child_cleanup); - if let Err(e) = self.wait_for_qemu() { + if let Err(e) = self.wait_for_qemu(&mut child) { return Err(e).context("Failed waiting for QEMU to be ready"); } From 4db9cac6e2cd69bf9cc8128501dd0b541a6d7b6e Mon Sep 17 00:00:00 2001 From: Xing Guo Date: Wed, 8 Oct 2025 21:30:32 +0800 Subject: [PATCH 2/2] Make tests happy. --- tests/test.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test.rs b/tests/test.rs index 26fc3a6..426fcd9 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -344,7 +344,7 @@ fn test_qemu_error_shown() { vmtest.run_one(0, send); let err = assert_get_err!(recv, Output::BootEnd); - let msg = err.to_string(); + let msg = format!("{:?}", err); assert!(msg.contains("qemu: could not open kernel file")); }