Skip to content

test-runner: Remove BootServices from remaining proto tests #1406

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 1 commit into from
Sep 21, 2024
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
2 changes: 1 addition & 1 deletion uefi-test-runner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn efi_main(image: Handle, mut st: SystemTable<Boot>) -> Status {
boot::test(&st);

// Test all the supported protocols.
proto::test(&mut st);
proto::test();

// TODO: runtime services work before boot services are exited, but we'd
// probably want to test them after exit_boot_services. However,
Expand Down
12 changes: 5 additions & 7 deletions uefi-test-runner/src/proto/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@ use uefi::prelude::*;
use uefi::proto::misc::ResetNotification;
use uefi::runtime::ResetType;

pub fn test(bt: &BootServices) {
test_reset_notification(bt);
pub fn test() {
test_reset_notification();
}

pub fn test_reset_notification(bt: &BootServices) {
pub fn test_reset_notification() {
info!("Running loaded ResetNotification protocol test");

let handle = bt
.get_handle_for_protocol::<ResetNotification>()
let handle = boot::get_handle_for_protocol::<ResetNotification>()
.expect("Failed to get handles for `ResetNotification` protocol");

let mut reset_notif_proto = bt
.open_protocol_exclusive::<ResetNotification>(handle)
let mut reset_notif_proto = boot::open_protocol_exclusive::<ResetNotification>(handle)
.expect("Founded ResetNotification Protocol but open failed");

// value efi_reset_fn is the type of ResetSystemFn, a function pointer
Expand Down
12 changes: 5 additions & 7 deletions uefi-test-runner/src/proto/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use uefi::boot::{self, OpenProtocolParams};
use uefi::prelude::*;
use uefi::proto::loaded_image::LoadedImage;
use uefi::{proto, Identify};

pub fn test(st: &mut SystemTable<Boot>) {
pub fn test() {
info!("Testing various protocols");

console::test();

let bt = st.boot_services();
find_protocol();
test_protocols_per_handle();
test_test_protocol();
Expand All @@ -19,12 +17,12 @@ pub fn test(st: &mut SystemTable<Boot>) {
load::test();
loaded_image::test();
media::test();
network::test(bt);
pi::test(bt);
network::test();
pi::test();
rng::test();
shell_params::test(bt);
shell_params::test();
string::test();
misc::test(bt);
misc::test();

#[cfg(any(
target_arch = "x86",
Expand Down
8 changes: 3 additions & 5 deletions uefi-test-runner/src/proto/network/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use uefi::prelude::*;

pub fn test(bt: &BootServices) {
pub fn test() {
info!("Testing Network protocols");

pxe::test(bt);
snp::test(bt);
pxe::test();
snp::test();
}

mod pxe;
Expand Down
11 changes: 4 additions & 7 deletions uefi-test-runner/src/proto/network/pxe.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
use uefi::prelude::BootServices;
use uefi::proto::network::pxe::{BaseCode, DhcpV4Packet, IpFilter, IpFilters, UdpOpFlags};
use uefi::proto::network::IpAddress;
use uefi::CStr8;
use uefi::{boot, CStr8};

pub fn test(bt: &BootServices) {
pub fn test() {
// Skip the test if the `pxe` feature is not enabled.
if cfg!(not(feature = "pxe")) {
return;
}

info!("Testing The PXE base code protocol");

let handles = bt
.find_handles::<BaseCode>()
.expect("failed to get PXE base code handles");
let handles = boot::find_handles::<BaseCode>().expect("failed to get PXE base code handles");
for handle in handles {
let mut base_code = bt.open_protocol_exclusive::<BaseCode>(handle).unwrap();
let mut base_code = boot::open_protocol_exclusive::<BaseCode>(handle).unwrap();

info!("Starting PXE Base Code");
base_code
Expand Down
11 changes: 5 additions & 6 deletions uefi-test-runner/src/proto/network/snp.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use uefi::prelude::BootServices;
use uefi::proto::network::snp::{InterruptStatus, ReceiveFlags, SimpleNetwork};
use uefi::proto::network::MacAddress;
use uefi::Status;
use uefi::{boot, Status};

pub fn test(bt: &BootServices) {
pub fn test() {
info!("Testing the simple network protocol");

let handles = bt.find_handles::<SimpleNetwork>().unwrap_or_default();
let handles = boot::find_handles::<SimpleNetwork>().unwrap_or_default();

for handle in handles {
let simple_network = bt.open_protocol_exclusive::<SimpleNetwork>(handle);
let simple_network = boot::open_protocol_exclusive::<SimpleNetwork>(handle);
if simple_network.is_err() {
continue;
}
Expand Down Expand Up @@ -102,7 +101,7 @@ pub fn test(bt: &BootServices) {
if simple_network.receive(&mut buffer, None, None, None, None)
== Err(Status::NOT_READY.into())
{
bt.stall(1_000_000);
boot::stall(1_000_000);

simple_network
.receive(&mut buffer, None, None, None, None)
Expand Down
6 changes: 2 additions & 4 deletions uefi-test-runner/src/proto/pi/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use uefi::prelude::*;

pub fn test(bt: &BootServices) {
pub fn test() {
info!("Testing Platform Initialization protocols");

mp::test(bt);
mp::test();
}

mod mp;
31 changes: 13 additions & 18 deletions uefi-test-runner/src/proto/pi/mp.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use core::ffi::c_void;
use core::ptr;
use core::sync::atomic::{AtomicUsize, Ordering};
use core::time::Duration;
use uefi::proto::pi::mp::MpServices;
use uefi::table::boot::BootServices;
use uefi::Status;
use uefi::{boot, Status};

/// Number of cores qemu is configured to have
const NUM_CPUS: usize = 4;

pub fn test(bt: &BootServices) {
pub fn test() {
// Skip the test if the `multi_processing` feature is not
// enabled. This toggle is needed because the test only works with
// KVM, which is not available in CI or on Windows.
Expand All @@ -17,17 +17,15 @@ pub fn test(bt: &BootServices) {
}

info!("Running UEFI multi-processor services protocol test");
let handle = bt
.get_handle_for_protocol::<MpServices>()
let handle = boot::get_handle_for_protocol::<MpServices>()
.expect("failed to get multi-processor services handle");
let mp_support = &bt
.open_protocol_exclusive::<MpServices>(handle)
let mp_support = &boot::open_protocol_exclusive::<MpServices>(handle)
.expect("failed to open multi-processor services protocol");

test_get_number_of_processors(mp_support);
test_get_processor_info(mp_support);
test_startup_all_aps(mp_support, bt);
test_startup_this_ap(mp_support, bt);
test_startup_all_aps(mp_support);
test_startup_this_ap(mp_support);
test_enable_disable_ap(mp_support);
test_switch_bsp_and_who_am_i(mp_support);
}
Expand Down Expand Up @@ -75,12 +73,11 @@ extern "efiapi" fn proc_increment_atomic(arg: *mut c_void) {
counter.fetch_add(1, Ordering::Relaxed);
}

extern "efiapi" fn proc_wait_100ms(arg: *mut c_void) {
let bt: &BootServices = unsafe { &*(arg as *const _) };
bt.stall(100_000);
extern "efiapi" fn proc_wait_100ms(_: *mut c_void) {
boot::stall(100_000);
}

fn test_startup_all_aps(mps: &MpServices, bt: &BootServices) {
fn test_startup_all_aps(mps: &MpServices) {
// Ensure that APs start up
let counter = AtomicUsize::new(0);
let counter_ptr: *mut c_void = &counter as *const _ as *mut _;
Expand All @@ -89,18 +86,17 @@ fn test_startup_all_aps(mps: &MpServices, bt: &BootServices) {
assert_eq!(counter.load(Ordering::Relaxed), NUM_CPUS - 1);

// Make sure that timeout works
let bt_ptr: *mut c_void = bt as *const _ as *mut _;
let ret = mps.startup_all_aps(
false,
proc_wait_100ms,
bt_ptr,
ptr::null_mut(),
None,
Some(Duration::from_millis(50)),
);
assert_eq!(ret.map_err(|err| err.status()), Err(Status::TIMEOUT));
}

fn test_startup_this_ap(mps: &MpServices, bt: &BootServices) {
fn test_startup_this_ap(mps: &MpServices) {
// Ensure that each AP starts up
let counter = AtomicUsize::new(0);
let counter_ptr: *mut c_void = &counter as *const _ as *mut _;
Expand All @@ -111,12 +107,11 @@ fn test_startup_this_ap(mps: &MpServices, bt: &BootServices) {
assert_eq!(counter.load(Ordering::Relaxed), NUM_CPUS - 1);

// Make sure that timeout works for each AP
let bt_ptr: *mut c_void = bt as *const _ as *mut _;
for i in 1..NUM_CPUS {
let ret = mps.startup_this_ap(
i,
proc_wait_100ms,
bt_ptr,
ptr::null_mut(),
None,
Some(Duration::from_millis(50)),
);
Expand Down
12 changes: 5 additions & 7 deletions uefi-test-runner/src/proto/shell_params.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
use uefi::boot;
use uefi::proto::shell_params::ShellParameters;
use uefi::table::boot::BootServices;

use alloc::string::ToString;
use alloc::vec::Vec;

pub fn test(bt: &BootServices) {
pub fn test() {
info!("Running loaded image protocol test");

let image = bt
.get_handle_for_protocol::<ShellParameters>()
.expect("No ShellParameters handles");
let shell_params = bt
.open_protocol_exclusive::<ShellParameters>(image)
let image =
boot::get_handle_for_protocol::<ShellParameters>().expect("No ShellParameters handles");
let shell_params = boot::open_protocol_exclusive::<ShellParameters>(image)
.expect("Failed to open ShellParameters protocol");

assert_eq!(shell_params.args_len(), 4);
Expand Down