Skip to content

xtask: fix status check at end of VM test #355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ jobs:

- name: Install qemu and OVMF
run: |
# Ubuntu 20.04 provides qemu 4.2, which crashes on exit in this
# test. Add a PPA to provide a more recent version of qemu.
sudo add-apt-repository ppa:canonical-server/server-backports
sudo apt-get update
sudo apt-get install qemu-system-aarch64 qemu-efi-aarch64 -y
sudo apt-get install qemu-system-arm qemu-efi-aarch64 -y
# Copy the files so that the vars file isn't read-only.
cp /usr/share/AAVMF/AAVMF_CODE.fd uefi-test-runner/QEMU_EFI-pflash.raw
cp /usr/share/AAVMF/AAVMF_VARS.fd uefi-test-runner/vars-template-pflash.raw
Expand Down Expand Up @@ -75,6 +78,9 @@ jobs:

- name: Install qemu
run: |
# Ubuntu 20.04 provides qemu 4.2, which crashes on exit in this
# test. Add a PPA to provide a more recent version of qemu.
sudo add-apt-repository ppa:canonical-server/server-backports
sudo apt-get update
sudo apt-get install qemu-system-x86 -y

Expand Down
36 changes: 31 additions & 5 deletions xtask/src/qemu.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::arch::UefiArch;
use crate::opt::QemuOpt;
use crate::util::command_to_string;
use anyhow::{bail, Result};
use anyhow::{bail, Context, Result};
use fs_err::{File, OpenOptions};
use nix::sys::stat::Mode;
use nix::unistd::mkfifo;
Expand Down Expand Up @@ -366,12 +366,38 @@ pub fn run_qemu(arch: UefiArch, opt: &QemuOpt) -> Result<()> {
// Start a thread to process stdout from the child.
let stdout_thread = thread::spawn(|| echo_filtered_stdout(child_io));

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

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

ret
// Propagate earlier error if necessary.
res?;

// Get qemu's exit code if possible, or return an error if
// terminated by a signal.
let qemu_exit_code = status
.code()
.context(format!("qemu was terminated by a signal: {:?}", status))?;

let successful_exit_code = match arch {
UefiArch::AArch64 | UefiArch::IA32 => 0,

// The x86_64 version of uefi-test-runner uses exit code 3 to
// indicate success. See the `shutdown` function in
// uefi-test-runner for more details.
UefiArch::X86_64 => 3,
};

if qemu_exit_code != successful_exit_code {
bail!(
"qemu exited with code {}, expected {}",
qemu_exit_code,
successful_exit_code
);
}

Ok(())
}