Skip to content

Commit efe4d41

Browse files
committed
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.
1 parent 9b6098a commit efe4d41

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/qemu.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,11 +758,26 @@ impl Qemu {
758758
}
759759

760760
/// Waits for QMP and QGA sockets to appear
761-
fn wait_for_qemu(&self) -> Result<()> {
761+
fn wait_for_qemu(&self, child: &mut Child) -> Result<()> {
762762
let now = time::Instant::now();
763763
let timeout = Duration::from_secs(5);
764764

765765
while now.elapsed() < timeout {
766+
// Before checking socket files, let's check if the child process fails to start.
767+
match child
768+
.try_wait()
769+
.with_context(|| "Failed to inspect QEMU status".to_string())?
770+
{
771+
None => { /* QEMU is still running. */ }
772+
Some(ec) => {
773+
if ec.success() {
774+
bail!("QEMU exits normally which is not expected")
775+
} else {
776+
bail!("QEMU fails to start: {}", Self::extract_child_stderr(child))
777+
}
778+
}
779+
}
780+
766781
let qga_ok = self
767782
.qga_sock
768783
.try_exists()
@@ -1035,7 +1050,7 @@ impl Qemu {
10351050
// Ensure child is cleaned up even if we bail early
10361051
let mut child = scopeguard::guard(child, Self::child_cleanup);
10371052

1038-
if let Err(e) = self.wait_for_qemu() {
1053+
if let Err(e) = self.wait_for_qemu(&mut child) {
10391054
return Err(e).context("Failed waiting for QEMU to be ready");
10401055
}
10411056

0 commit comments

Comments
 (0)