From 91fa4b5336af726be2f8bdcd232d67d7b2f46e6c Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Fri, 20 Sep 2024 18:12:08 -0400 Subject: [PATCH] test-runner: Remove BootServices from proto tests --- uefi-test-runner/src/main.rs | 2 +- uefi-test-runner/src/proto/misc.rs | 12 ++++----- uefi-test-runner/src/proto/mod.rs | 12 ++++----- uefi-test-runner/src/proto/network/mod.rs | 8 +++--- uefi-test-runner/src/proto/network/pxe.rs | 11 +++----- uefi-test-runner/src/proto/network/snp.rs | 11 ++++---- uefi-test-runner/src/proto/pi/mod.rs | 6 ++--- uefi-test-runner/src/proto/pi/mp.rs | 31 +++++++++------------- uefi-test-runner/src/proto/shell_params.rs | 12 ++++----- 9 files changed, 43 insertions(+), 62 deletions(-) diff --git a/uefi-test-runner/src/main.rs b/uefi-test-runner/src/main.rs index 594b9cad5..d6dec41f5 100644 --- a/uefi-test-runner/src/main.rs +++ b/uefi-test-runner/src/main.rs @@ -57,7 +57,7 @@ fn efi_main(image: Handle, mut st: SystemTable) -> 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, diff --git a/uefi-test-runner/src/proto/misc.rs b/uefi-test-runner/src/proto/misc.rs index 6fd55b624..55419be92 100644 --- a/uefi-test-runner/src/proto/misc.rs +++ b/uefi-test-runner/src/proto/misc.rs @@ -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::() + let handle = boot::get_handle_for_protocol::() .expect("Failed to get handles for `ResetNotification` protocol"); - let mut reset_notif_proto = bt - .open_protocol_exclusive::(handle) + let mut reset_notif_proto = boot::open_protocol_exclusive::(handle) .expect("Founded ResetNotification Protocol but open failed"); // value efi_reset_fn is the type of ResetSystemFn, a function pointer diff --git a/uefi-test-runner/src/proto/mod.rs b/uefi-test-runner/src/proto/mod.rs index bbbe80975..747b9d33b 100644 --- a/uefi-test-runner/src/proto/mod.rs +++ b/uefi-test-runner/src/proto/mod.rs @@ -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) { +pub fn test() { info!("Testing various protocols"); console::test(); - let bt = st.boot_services(); find_protocol(); test_protocols_per_handle(); test_test_protocol(); @@ -19,12 +17,12 @@ pub fn test(st: &mut SystemTable) { 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", diff --git a/uefi-test-runner/src/proto/network/mod.rs b/uefi-test-runner/src/proto/network/mod.rs index 436d78635..17731a342 100644 --- a/uefi-test-runner/src/proto/network/mod.rs +++ b/uefi-test-runner/src/proto/network/mod.rs @@ -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; diff --git a/uefi-test-runner/src/proto/network/pxe.rs b/uefi-test-runner/src/proto/network/pxe.rs index d7ba09573..726dc77f8 100644 --- a/uefi-test-runner/src/proto/network/pxe.rs +++ b/uefi-test-runner/src/proto/network/pxe.rs @@ -1,9 +1,8 @@ -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; @@ -11,11 +10,9 @@ pub fn test(bt: &BootServices) { info!("Testing The PXE base code protocol"); - let handles = bt - .find_handles::() - .expect("failed to get PXE base code handles"); + let handles = boot::find_handles::().expect("failed to get PXE base code handles"); for handle in handles { - let mut base_code = bt.open_protocol_exclusive::(handle).unwrap(); + let mut base_code = boot::open_protocol_exclusive::(handle).unwrap(); info!("Starting PXE Base Code"); base_code diff --git a/uefi-test-runner/src/proto/network/snp.rs b/uefi-test-runner/src/proto/network/snp.rs index 196fd5cc5..a552a8033 100644 --- a/uefi-test-runner/src/proto/network/snp.rs +++ b/uefi-test-runner/src/proto/network/snp.rs @@ -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::().unwrap_or_default(); + let handles = boot::find_handles::().unwrap_or_default(); for handle in handles { - let simple_network = bt.open_protocol_exclusive::(handle); + let simple_network = boot::open_protocol_exclusive::(handle); if simple_network.is_err() { continue; } @@ -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) diff --git a/uefi-test-runner/src/proto/pi/mod.rs b/uefi-test-runner/src/proto/pi/mod.rs index 85c7ff2d6..3b0637176 100644 --- a/uefi-test-runner/src/proto/pi/mod.rs +++ b/uefi-test-runner/src/proto/pi/mod.rs @@ -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; diff --git a/uefi-test-runner/src/proto/pi/mp.rs b/uefi-test-runner/src/proto/pi/mp.rs index f40fe5ea4..f1ddb7741 100644 --- a/uefi-test-runner/src/proto/pi/mp.rs +++ b/uefi-test-runner/src/proto/pi/mp.rs @@ -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. @@ -17,17 +17,15 @@ pub fn test(bt: &BootServices) { } info!("Running UEFI multi-processor services protocol test"); - let handle = bt - .get_handle_for_protocol::() + let handle = boot::get_handle_for_protocol::() .expect("failed to get multi-processor services handle"); - let mp_support = &bt - .open_protocol_exclusive::(handle) + let mp_support = &boot::open_protocol_exclusive::(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); } @@ -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 _; @@ -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 _; @@ -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)), ); diff --git a/uefi-test-runner/src/proto/shell_params.rs b/uefi-test-runner/src/proto/shell_params.rs index 935e9660b..6e2a2697f 100644 --- a/uefi-test-runner/src/proto/shell_params.rs +++ b/uefi-test-runner/src/proto/shell_params.rs @@ -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::() - .expect("No ShellParameters handles"); - let shell_params = bt - .open_protocol_exclusive::(image) + let image = + boot::get_handle_for_protocol::().expect("No ShellParameters handles"); + let shell_params = boot::open_protocol_exclusive::(image) .expect("Failed to open ShellParameters protocol"); assert_eq!(shell_params.args_len(), 4);