Skip to content

Commit 263a60e

Browse files
test-runner: Replace ci feature with fine grained features
Rather than a CI flag that did several things, add flags that enable specific tests. Specifically, `multi_processor`, `tpm_v1`, and `tpm_v2`. These three features control whether the corresponding test is enabled, and nothing else. This fixes an issue on Windows where the TPM tests were failing. We had those tests expect to always find a TPM if the CI feature was enabled, but we were also always enabling the CI feature on Windows in order to disable the multi-processing tests, due to KVM not being available. This all becomes a lot simpler by just having explicit flags for each test.
1 parent 4d8e9f9 commit 263a60e

File tree

5 files changed

+46
-30
lines changed

5 files changed

+46
-30
lines changed

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.

0 commit comments

Comments
 (0)