Skip to content

Commit 6d01ed3

Browse files
authored
Merge pull request #651 from nicholasbishop/bishop-fix-windows-tests
Various fixes for tests under Windows
2 parents 8fa4645 + df4eef9 commit 6d01ed3

File tree

7 files changed

+57
-36
lines changed

7 files changed

+57
-36
lines changed

.github/workflows/rust.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,19 @@ jobs:
141141
name: Check that the build works on a Windows target
142142
runs-on: windows-latest
143143
steps:
144+
- name: Install QEMU
145+
run: choco install qemu
146+
144147
- name: Checkout sources
145148
uses: actions/checkout@v3
146149

147150
- name: Build
148151
run: cargo xtask build
149152

153+
- name: Run VM tests
154+
run: cargo xtask run --target x86_64 --ci
155+
timeout-minutes: 2
156+
150157
# Run the build with our current nightly MSRV (specified in
151158
# ./msrv_toolchain.toml). This serves to check that we don't
152159
# accidentally start relying on a new feature without intending

uefi-test-runner/Cargo.toml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ log = { version = "0.4.17", default-features = false }
1515
qemu-exit = "3.0.0"
1616

1717
[features]
18-
# This feature should only be enabled in our CI, it disables some tests
19-
# which currently fail in that environment (see #103 for discussion).
20-
ci = []
18+
# Enable the multiprocessor test. This only works if KVM is enabled.
19+
multi_processor = []
2120

21+
# Enable the TPM v1 test.
22+
tpm_v1 = []
23+
24+
# Enable the TPM v2 test.
25+
tpm_v2 = []

uefi-test-runner/src/proto/pi/mp.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ use uefi::Status;
99
const NUM_CPUS: usize = 4;
1010

1111
pub fn test(bt: &BootServices) {
12-
// These tests break CI. See #103.
13-
if cfg!(feature = "ci") {
12+
// Skip the test if the `multi_processing` feature is not
13+
// enabled. This toggle is needed because the test only works with
14+
// KVM, which is not available in CI or on Windows.
15+
if cfg!(not(feature = "multi_processor")) {
1416
return;
1517
}
1618

uefi-test-runner/src/proto/tcg.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,16 @@ fn tcg_v1_read_pcr(tcg: &mut v1::Tcg, pcr_index: PcrIndex) -> v1::Sha1Digest {
4646
}
4747

4848
fn test_tcg_v1(bt: &BootServices) {
49+
// Skip the test of the `tpm_v1` feature is not enabled.
50+
if cfg!(not(feature = "tpm_v1")) {
51+
return;
52+
}
53+
4954
info!("Running TCG v1 test");
5055

51-
let handle = if let Ok(handle) = bt.get_handle_for_protocol::<v1::Tcg>() {
52-
handle
53-
} else if cfg!(all(feature = "ci", target_arch = "x86_64")) {
54-
panic!("TPM v1 is required on x86_64 CI");
55-
} else {
56-
info!("No TCG handle found");
57-
return;
58-
};
56+
let handle = bt
57+
.get_handle_for_protocol::<v1::Tcg>()
58+
.expect("no TCG handle found");
5959

6060
let mut tcg = bt
6161
.open_protocol_exclusive::<v1::Tcg>(handle)
@@ -215,16 +215,16 @@ fn tcg_v2_read_pcr_8(tcg: &mut v2::Tcg) -> v1::Sha1Digest {
215215
}
216216

217217
pub fn test_tcg_v2(bt: &BootServices) {
218+
// Skip the test of the `tpm_v2` feature is not enabled.
219+
if cfg!(not(feature = "tpm_v2")) {
220+
return;
221+
}
222+
218223
info!("Running TCG v2 test");
219224

220-
let handle = if let Ok(handle) = bt.get_handle_for_protocol::<v2::Tcg>() {
221-
handle
222-
} else if cfg!(all(feature = "ci", target_arch = "x86")) {
223-
panic!("TPM v2 is required on x86 (32-bit) CI");
224-
} else {
225-
info!("No TCG handle found");
226-
return;
227-
};
225+
let handle = bt
226+
.get_handle_for_protocol::<v2::Tcg>()
227+
.expect("no TCG handle found");
228228

229229
let mut tcg = bt
230230
.open_protocol_exclusive::<v2::Tcg>(handle)

xtask/src/cargo.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ pub enum Feature {
5858
ServicesLogger,
5959

6060
// `uefi-test-runner` features.
61-
Ci,
61+
MultiProcessor,
62+
TpmV1,
63+
TpmV2,
6264
}
6365

6466
impl Feature {
@@ -74,7 +76,9 @@ impl Feature {
7476
Self::Qemu => "uefi-services/qemu",
7577
Self::ServicesLogger => "uefi-services/logger",
7678

77-
Self::Ci => "uefi-test-runner/ci",
79+
Self::MultiProcessor => "uefi-test-runner/multi_processor",
80+
Self::TpmV1 => "uefi-test-runner/tpm_v1",
81+
Self::TpmV2 => "uefi-test-runner/tpm_v2",
7882
}
7983
}
8084

@@ -89,7 +93,7 @@ impl Feature {
8993
Self::Unstable,
9094
],
9195
Package::UefiServices => vec![Self::PanicHandler, Self::Qemu, Self::ServicesLogger],
92-
Package::UefiTestRunner => vec![Self::Ci],
96+
Package::UefiTestRunner => vec![Self::MultiProcessor, Self::TpmV1, Self::TpmV2],
9397
_ => vec![],
9498
}
9599
}

xtask/src/main.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use anyhow::Result;
1515
use cargo::{fix_nested_cargo_env, Cargo, CargoAction, Feature, Package, TargetTypes};
1616
use clap::Parser;
1717
use itertools::Itertools;
18-
use opt::{Action, BuildOpt, ClippyOpt, DocOpt, Opt, QemuOpt};
18+
use opt::{Action, BuildOpt, ClippyOpt, DocOpt, Opt, QemuOpt, TpmVersion};
1919
use std::process::Command;
2020
use tempfile::TempDir;
2121
use util::{command_to_string, run_cmd};
@@ -122,11 +122,17 @@ fn run_miri() -> Result<()> {
122122
fn run_vm_tests(opt: &QemuOpt) -> Result<()> {
123123
let mut features = vec![];
124124

125-
// Always enable the ci feature when not building on Linux so that
126-
// the MP test is skipped. That test doesn't work with kvm disabled
127-
// (see https://github.com/rust-osdev/uefi-rs/issues/103).
128-
if opt.ci || !platform::is_linux() {
129-
features.push(Feature::Ci);
125+
// Enable TPM tests if a TPM device is present.
126+
match opt.tpm {
127+
Some(TpmVersion::V1) => features.push(Feature::TpmV1),
128+
Some(TpmVersion::V2) => features.push(Feature::TpmV2),
129+
None => {}
130+
}
131+
132+
// Enable the multi-processor test if KVM is available. KVM is
133+
// available on Linux generally, but not in our CI.
134+
if platform::is_linux() && !opt.ci {
135+
features.push(Feature::MultiProcessor);
130136
}
131137

132138
// Build uefi-test-runner.

xtask/src/qemu.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -520,10 +520,11 @@ pub fn run_qemu(arch: UefiArch, opt: &QemuOpt) -> Result<()> {
520520
cmd.arg(drive_arg);
521521

522522
let qemu_monitor_pipe = Pipe::new(tmp_dir, "qemu-monitor")?;
523+
let serial_pipe = Pipe::new(tmp_dir, "serial")?;
523524

524525
// Open a serial device connected to stdio. This is used for
525526
// printing logs and to receive and reply to commands.
526-
cmd.args(["-serial", "stdio"]);
527+
cmd.args(["-serial", serial_pipe.qemu_arg()]);
527528

528529
// Map the QEMU monitor to a pair of named pipes
529530
cmd.args(["-qmp", qemu_monitor_pipe.qemu_arg()]);
@@ -556,14 +557,11 @@ pub fn run_qemu(arch: UefiArch, opt: &QemuOpt) -> Result<()> {
556557
let mut child = ChildWrapper(cmd.spawn().context("failed to launch qemu")?);
557558

558559
let monitor_io = qemu_monitor_pipe.open_io()?;
559-
let child_io = Io::new(
560-
child.0.stdout.take().unwrap(),
561-
child.0.stdin.take().unwrap(),
562-
);
560+
let serial_io = serial_pipe.open_io()?;
563561

564562
// Capture the result to check it, but first wait for the child to
565563
// exit.
566-
let res = process_qemu_io(monitor_io, child_io, tmp_dir);
564+
let res = process_qemu_io(monitor_io, serial_io, tmp_dir);
567565
let status = child.0.wait()?;
568566

569567
if let Some(echo_service) = echo_service {

0 commit comments

Comments
 (0)