Skip to content

Commit eced5be

Browse files
nicholasbishopGabrielMajeri
authored andcommitted
xtask: fix status check at end of VM test
This was accidentally dropped when porting build.py to Rust. On AArch64, check that qemu exits 0, and on x86_64, expect an exit code of 3.
1 parent 7f50e48 commit eced5be

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

xtask/src/qemu.rs

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::arch::UefiArch;
22
use crate::opt::QemuOpt;
33
use crate::util::command_to_string;
4-
use anyhow::{bail, Result};
4+
use anyhow::{bail, Context, Result};
55
use fs_err::{File, OpenOptions};
66
use nix::sys::stat::Mode;
77
use nix::unistd::mkfifo;
@@ -366,12 +366,38 @@ pub fn run_qemu(arch: UefiArch, opt: &QemuOpt) -> Result<()> {
366366
// Start a thread to process stdout from the child.
367367
let stdout_thread = thread::spawn(|| echo_filtered_stdout(child_io));
368368

369-
// Capture the result to return it, but first wait for the child to
369+
// Capture the result to check it, but first wait for the child to
370370
// exit.
371-
let ret = process_qemu_io(monitor_io, serial_io, tmp_dir);
372-
child.wait()?;
371+
let res = process_qemu_io(monitor_io, serial_io, tmp_dir);
372+
let status = child.wait()?;
373373

374374
stdout_thread.join().expect("stdout thread panicked");
375375

376-
ret
376+
// Propagate earlier error if necessary.
377+
res?;
378+
379+
// Get qemu's exit code if possible, or return an error if
380+
// terminated by a signal.
381+
let qemu_exit_code = status
382+
.code()
383+
.context(format!("qemu was terminated by a signal: {:?}", status))?;
384+
385+
let successful_exit_code = match arch {
386+
UefiArch::AArch64 | UefiArch::IA32 => 0,
387+
388+
// The x86_64 version of uefi-test-runner uses exit code 3 to
389+
// indicate success. See the `shutdown` function in
390+
// uefi-test-runner for more details.
391+
UefiArch::X86_64 => 3,
392+
};
393+
394+
if qemu_exit_code != successful_exit_code {
395+
bail!(
396+
"qemu exited with code {}, expected {}",
397+
qemu_exit_code,
398+
successful_exit_code
399+
);
400+
}
401+
402+
Ok(())
377403
}

0 commit comments

Comments
 (0)