|  | 
| 1 | 1 | use crate::arch::UefiArch; | 
| 2 | 2 | use crate::opt::QemuOpt; | 
| 3 | 3 | use crate::util::command_to_string; | 
| 4 |  | -use anyhow::{bail, Result}; | 
|  | 4 | +use anyhow::{bail, Context, Result}; | 
| 5 | 5 | use fs_err::{File, OpenOptions}; | 
| 6 | 6 | use nix::sys::stat::Mode; | 
| 7 | 7 | use nix::unistd::mkfifo; | 
| @@ -366,12 +366,38 @@ pub fn run_qemu(arch: UefiArch, opt: &QemuOpt) -> Result<()> { | 
| 366 | 366 |  // Start a thread to process stdout from the child. | 
| 367 | 367 |  let stdout_thread = thread::spawn(|| echo_filtered_stdout(child_io)); | 
| 368 | 368 | 
 | 
| 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 | 
| 370 | 370 |  // 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()?; | 
| 373 | 373 | 
 | 
| 374 | 374 |  stdout_thread.join().expect("stdout thread panicked"); | 
| 375 | 375 | 
 | 
| 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(()) | 
| 377 | 403 | } | 
0 commit comments