From 17d99d8045f76e11aed2b16a37c340668d3e9d77 Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Sun, 6 Feb 2022 16:41:42 -0500 Subject: [PATCH 1/2] ci: install a newer version of qemu for the aarch64/ia32 tests This fixes a segfault on exit. https://github.com/rust-osdev/uefi-rs/issues/259 --- .github/workflows/rust.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 08bb93b5a..062dc6225 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -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 @@ -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 From 3a5ad1db18a99e52f9b0b56b76613ab7635da001 Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Sun, 6 Feb 2022 15:49:44 -0500 Subject: [PATCH 2/2] 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. --- xtask/src/qemu.rs | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/xtask/src/qemu.rs b/xtask/src/qemu.rs index 6647a4040..39f727f66 100644 --- a/xtask/src/qemu.rs +++ b/xtask/src/qemu.rs @@ -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; @@ -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(()) }