diff --git a/uefi-test-runner/src/proto/console/gop.rs b/uefi-test-runner/src/proto/console/gop.rs index 26a71b6d0..8731f9894 100644 --- a/uefi-test-runner/src/proto/console/gop.rs +++ b/uefi-test-runner/src/proto/console/gop.rs @@ -1,26 +1,23 @@ use crate::{send_request_to_host, HostRequest}; -use uefi::prelude::*; +use uefi::boot::{self, OpenProtocolAttributes, OpenProtocolParams}; use uefi::proto::console::gop::{BltOp, BltPixel, FrameBuffer, GraphicsOutput, PixelFormat}; -use uefi::table::boot::{OpenProtocolAttributes, OpenProtocolParams}; -pub unsafe fn test(bt: &BootServices) { +pub unsafe fn test() { info!("Running graphics output protocol test"); - let handle = bt - .get_handle_for_protocol::() - .expect("missing GraphicsOutput protocol"); - let gop = &mut bt - .open_protocol::( - OpenProtocolParams { - handle, - agent: bt.image_handle(), - controller: None, - }, - // For this test, don't open in exclusive mode. That - // would break the connection between stdout and the - // video console. - OpenProtocolAttributes::GetProtocol, - ) - .expect("failed to open Graphics Output Protocol"); + let handle = + boot::get_handle_for_protocol::().expect("missing GraphicsOutput protocol"); + let gop = &mut boot::open_protocol::( + OpenProtocolParams { + handle, + agent: boot::image_handle(), + controller: None, + }, + // For this test, don't open in exclusive mode. That + // would break the connection between stdout and the + // video console. + OpenProtocolAttributes::GetProtocol, + ) + .expect("failed to open Graphics Output Protocol"); set_graphics_mode(gop); fill_color(gop); diff --git a/uefi-test-runner/src/proto/console/mod.rs b/uefi-test-runner/src/proto/console/mod.rs index 8dd7392ec..2f16ac679 100644 --- a/uefi-test-runner/src/proto/console/mod.rs +++ b/uefi-test-runner/src/proto/console/mod.rs @@ -1,16 +1,15 @@ use uefi::prelude::*; -pub fn test(st: &mut SystemTable) { +pub fn test() { info!("Testing console protocols"); - stdout::test(st.stdout()); + system::with_stdout(stdout::test); - let bt = st.boot_services(); unsafe { - serial::test(bt); - gop::test(bt); + serial::test(); + gop::test(); } - pointer::test(bt); + pointer::test(); } mod gop; diff --git a/uefi-test-runner/src/proto/console/pointer.rs b/uefi-test-runner/src/proto/console/pointer.rs index f239c42cb..fce0ab578 100644 --- a/uefi-test-runner/src/proto/console/pointer.rs +++ b/uefi-test-runner/src/proto/console/pointer.rs @@ -1,14 +1,11 @@ +use uefi::boot; use uefi::proto::console::pointer::Pointer; -use uefi::table::boot::BootServices; -pub fn test(bt: &BootServices) { +pub fn test() { info!("Running pointer protocol test"); - let handle = bt - .get_handle_for_protocol::() - .expect("missing Pointer protocol"); - let mut pointer = bt - .open_protocol_exclusive::(handle) - .expect("failed to open pointer protocol"); + let handle = boot::get_handle_for_protocol::().expect("missing Pointer protocol"); + let mut pointer = + boot::open_protocol_exclusive::(handle).expect("failed to open pointer protocol"); pointer .reset(false) diff --git a/uefi-test-runner/src/proto/console/serial.rs b/uefi-test-runner/src/proto/console/serial.rs index 6c20f6568..2db7d36ff 100644 --- a/uefi-test-runner/src/proto/console/serial.rs +++ b/uefi-test-runner/src/proto/console/serial.rs @@ -1,6 +1,6 @@ use crate::reconnect_serial_to_console; +use uefi::boot; use uefi::proto::console::serial::{ControlBits, Serial}; -use uefi::table::boot::BootServices; use uefi::{Result, ResultExt, Status}; // For the duration of this function, the serial device is opened in @@ -41,7 +41,7 @@ fn serial_test_helper(serial: &mut Serial) -> Result { } } -pub unsafe fn test(bt: &BootServices) { +pub unsafe fn test() { // The serial device under aarch64 doesn't support the software // loopback feature needed for this test. if cfg!(target_arch = "aarch64") { @@ -49,13 +49,10 @@ pub unsafe fn test(bt: &BootServices) { } info!("Running serial protocol test"); - let handle = bt - .get_handle_for_protocol::() - .expect("missing Serial protocol"); + let handle = boot::get_handle_for_protocol::().expect("missing Serial protocol"); - let mut serial = bt - .open_protocol_exclusive::(handle) - .expect("failed to open serial protocol"); + let mut serial = + boot::open_protocol_exclusive::(handle).expect("failed to open serial protocol"); // Send the request, but don't check the result yet so that first // we can reconnect the console output for the logger. diff --git a/uefi-test-runner/src/proto/debug.rs b/uefi-test-runner/src/proto/debug.rs index 6980c2e31..7f542f5b3 100644 --- a/uefi-test-runner/src/proto/debug.rs +++ b/uefi-test-runner/src/proto/debug.rs @@ -1,51 +1,51 @@ use alloc::vec::Vec; use core::ffi::c_void; +use uefi::boot; use uefi::proto::debug::{DebugPort, DebugSupport, ExceptionType, ProcessorArch, SystemContext}; -use uefi::table::boot::BootServices; -pub fn test(bt: &BootServices) { - test_debug_support(bt); - test_debug_port(bt); +pub fn test() { + test_debug_support(); + test_debug_port(); } -fn test_debug_port(bt: &BootServices) { +fn test_debug_port() { info!("Running UEFI debug port protocol test"); - if let Ok(handles) = bt.find_handles::() { + if let Ok(handles) = boot::find_handles::() { for handle in handles { - if let Ok(debug_port) = bt.open_protocol_exclusive::(handle) { + if let Ok(debug_port) = boot::open_protocol_exclusive::(handle) { let timeout = 1000; debug_port .reset() .expect("Error while resetting debug port"); let data: Vec<_> = r##" - .. .=- . - . :##+ .*##= -*#+ .. - =#*=:.*####+#####**####-.-*## - .=-. *############################: :-: - -###**##############################*###* - :. -#######################################* .:: - =################################################## - .#################################################= - -====#################################################+====. - =##########################################################. - +########################################################. - -==+#########################################################*+=-. - +######################=:=@@%#########+:-%@%####################*: - =####################+ +@@@%######%. -@@@##################*. - :+#####################@-.:%@@@@#####%@*::#@@@%###################+: - +#######################@@@@@@@@@######@@@@@@@@%#####################- - -#########################@@@@@@@########@@@@@@%####################### - -#######%%%##################%##############################%%%%######* - +########%%%%############################################*%%%%#######: - =######+=%%%#####***##%%#####################%#**++####=:%%%#######: - :*#####:.*%#-####+==*########+-::::::=*#######*=+###*- *%*:-####*. - -####* .+. -*###############= .*#############*- .*: *###+ - =###: *##############+ .##############+ .###= - .+#* -######*=+++**** =###***++######- :#*. - .- -######- .*#####- .- - =*####*. =####+- - .:--: ::::. + .. .=- . + . :##+ .*##= -*#+ .. + =#*=:.*####+#####**####-.-*## + .=-. *############################: :-: + -###**##############################*###* + :. -#######################################* .:: + =################################################## + .#################################################= + -====#################################################+====. + =##########################################################. + +########################################################. + -==+#########################################################*+=-. + +######################=:=@@%#########+:-%@%####################*: + =####################+ +@@@%######%. -@@@##################*. + :+#####################@-.:%@@@@#####%@*::#@@@%###################+: + +#######################@@@@@@@@@######@@@@@@@@%#####################- + -#########################@@@@@@@########@@@@@@%####################### + -#######%%%##################%##############################%%%%######* + +########%%%%############################################*%%%%#######: + =######+=%%%#####***##%%#####################%#**++####=:%%%#######: + :*#####:.*%#-####+==*########+-::::::=*#######*=+###*- *%*:-####*. + -####* .+. -*###############= .*#############*- .*: *###+ + =###: *##############+ .##############+ .###= + .+#* -######*=+++**** =###***++######- :#*. + .- -######- .*#####- .- + =*####*. =####+- + .:--: ::::. "## .bytes() .collect(); @@ -66,17 +66,15 @@ fn test_debug_port(bt: &BootServices) { } } -fn test_debug_support(bt: &BootServices) { +fn test_debug_support() { if cfg!(not(feature = "debug_support")) { return; } info!("Running UEFI debug connection protocol test"); - let handles = bt - .find_handles::() - .expect("missing DebugSupport protocol"); + let handles = boot::find_handles::().expect("missing DebugSupport protocol"); for handle in handles { - if let Ok(mut debug_support) = bt.open_protocol_exclusive::(handle) { + if let Ok(mut debug_support) = boot::open_protocol_exclusive::(handle) { // make sure that the max processor index is a sane value, i.e. it works let maximum_processor_index = debug_support.get_maximum_processor_index(); assert_ne!( diff --git a/uefi-test-runner/src/proto/device_path.rs b/uefi-test-runner/src/proto/device_path.rs index b9f1ee0c0..3a08d482f 100644 --- a/uefi-test-runner/src/proto/device_path.rs +++ b/uefi-test-runner/src/proto/device_path.rs @@ -1,38 +1,34 @@ use alloc::string::ToString; use alloc::vec::Vec; use uefi::boot; -use uefi::prelude::*; use uefi::proto::device_path::text::*; use uefi::proto::device_path::{DevicePath, LoadedImageDevicePath}; use uefi::proto::loaded_image::LoadedImage; use uefi::proto::media::disk::DiskIo; -pub fn test(bt: &BootServices) { +pub fn test() { info!("Running device path protocol test"); // test 1/2: test low-level API by directly opening all protocols { - let loaded_image = bt - .open_protocol_exclusive::(bt.image_handle()) + let loaded_image = boot::open_protocol_exclusive::(boot::image_handle()) .expect("Failed to open LoadedImage protocol"); - let device_path = bt - .open_protocol_exclusive::(loaded_image.device().unwrap()) - .expect("Failed to open DevicePath protocol"); + let device_path = + boot::open_protocol_exclusive::(loaded_image.device().unwrap()) + .expect("Failed to open DevicePath protocol"); - let device_path_to_text = bt - .open_protocol_exclusive::( - bt.get_handle_for_protocol::() - .expect("Failed to get DevicePathToText handle"), - ) - .expect("Failed to open DevicePathToText protocol"); + let device_path_to_text = boot::open_protocol_exclusive::( + boot::get_handle_for_protocol::() + .expect("Failed to get DevicePathToText handle"), + ) + .expect("Failed to open DevicePathToText protocol"); - let device_path_from_text = bt - .open_protocol_exclusive::( - bt.get_handle_for_protocol::() - .expect("Failed to get DevicePathFromText handle"), - ) - .expect("Failed to open DevicePathFromText protocol"); + let device_path_from_text = boot::open_protocol_exclusive::( + boot::get_handle_for_protocol::() + .expect("Failed to get DevicePathFromText handle"), + ) + .expect("Failed to open DevicePathFromText protocol"); for path in device_path.node_iter() { info!( @@ -56,9 +52,9 @@ pub fn test(bt: &BootServices) { // Get the `LoadedImageDevicePath`. Verify it start with the same nodes as // `device_path`. - let loaded_image_device_path = bt - .open_protocol_exclusive::(bt.image_handle()) - .expect("Failed to open LoadedImageDevicePath protocol"); + let loaded_image_device_path = + boot::open_protocol_exclusive::(boot::image_handle()) + .expect("Failed to open LoadedImageDevicePath protocol"); for (n1, n2) in device_path .node_iter() @@ -74,9 +70,9 @@ pub fn test(bt: &BootServices) { // test 2/2: test high-level to-string api { - let loaded_image_device_path = bt - .open_protocol_exclusive::(bt.image_handle()) - .expect("Failed to open LoadedImageDevicePath protocol"); + let loaded_image_device_path = + boot::open_protocol_exclusive::(boot::image_handle()) + .expect("Failed to open LoadedImageDevicePath protocol"); let device_path: &DevicePath = &loaded_image_device_path; let path_components = device_path diff --git a/uefi-test-runner/src/proto/load.rs b/uefi-test-runner/src/proto/load.rs index 1a694d31c..928e6abd1 100644 --- a/uefi-test-runner/src/proto/load.rs +++ b/uefi-test-runner/src/proto/load.rs @@ -5,11 +5,10 @@ use core::ffi::c_void; use core::pin::Pin; use core::ptr; use core::ptr::addr_of; -use uefi::prelude::BootServices; use uefi::proto::device_path::build::DevicePathBuilder; use uefi::proto::media::load_file::{LoadFile, LoadFile2}; use uefi::proto::BootPolicy; -use uefi::{Guid, Handle}; +use uefi::{boot, Guid, Handle}; use uefi_raw::protocol::device_path::DevicePathProtocol; use uefi_raw::protocol::media::{LoadFile2Protocol, LoadFileProtocol}; use uefi_raw::Status; @@ -58,24 +57,12 @@ impl CustomLoadFile2Protocol { } } -unsafe fn install_protocol( - bt: &BootServices, - handle: Handle, - guid: Guid, - protocol: &mut CustomLoadFile2Protocol, -) { - bt.install_protocol_interface(Some(handle), &guid, addr_of!(*protocol).cast()) - .unwrap(); +unsafe fn install_protocol(handle: Handle, guid: Guid, protocol: &mut CustomLoadFile2Protocol) { + boot::install_protocol_interface(Some(handle), &guid, addr_of!(*protocol).cast()).unwrap(); } -unsafe fn uninstall_protocol( - bt: &BootServices, - handle: Handle, - guid: Guid, - protocol: &mut CustomLoadFile2Protocol, -) { - bt.uninstall_protocol_interface(handle, &guid, addr_of!(*protocol).cast()) - .unwrap(); +unsafe fn uninstall_protocol(handle: Handle, guid: Guid, protocol: &mut CustomLoadFile2Protocol) { + boot::uninstall_protocol_interface(handle, &guid, addr_of!(*protocol).cast()).unwrap(); } /// This tests the LoadFile and LoadFile2 protocols. As this protocol is not @@ -88,8 +75,8 @@ unsafe fn uninstall_protocol( /// /// [0] https://github.com/u-boot/u-boot/commit/ec80b4735a593961fe701cc3a5d717d4739b0fd0#diff-1f940face4d1cf74f9d2324952759404d01ee0a81612b68afdcba6b49803bdbbR171 /// [1] https://github.com/torvalds/linux/blob/ee9a43b7cfe2d8a3520335fea7d8ce71b8cabd9d/drivers/firmware/efi/libstub/efi-stub-helper.c#L550 -pub fn test(bt: &BootServices) { - let image = bt.image_handle(); +pub fn test() { + let image = boot::image_handle(); let load_data_msg = "Example file content."; let load_data = load_data_msg.to_string().into_bytes(); @@ -100,21 +87,21 @@ pub fn test(bt: &BootServices) { // Install our custom protocol implementation as LoadFile and LoadFile2 // protocol. unsafe { - install_protocol(bt, image, LoadFileProtocol::GUID, proto_load_file_ptr); - install_protocol(bt, image, LoadFile2Protocol::GUID, proto_load_file_ptr); + install_protocol(image, LoadFileProtocol::GUID, proto_load_file_ptr); + install_protocol(image, LoadFile2Protocol::GUID, proto_load_file_ptr); } let mut dvp_vec = Vec::new(); let dummy_dvp = DevicePathBuilder::with_vec(&mut dvp_vec); let dummy_dvp = dummy_dvp.finalize().unwrap(); - let mut load_file_protocol = bt.open_protocol_exclusive::(image).unwrap(); + let mut load_file_protocol = boot::open_protocol_exclusive::(image).unwrap(); let loadfile_file = load_file_protocol .load_file(dummy_dvp, BootPolicy::BootSelection) .unwrap(); let loadfile_file_string = String::from_utf8(loadfile_file.to_vec()).unwrap(); - let mut load_file2_protocol = bt.open_protocol_exclusive::(image).unwrap(); + let mut load_file2_protocol = boot::open_protocol_exclusive::(image).unwrap(); let loadfile2_file = load_file2_protocol.load_file(dummy_dvp).unwrap(); let loadfile2_file_string = String::from_utf8(loadfile2_file.to_vec()).unwrap(); @@ -125,18 +112,18 @@ pub fn test(bt: &BootServices) { drop(load_file_protocol); drop(load_file2_protocol); unsafe { - uninstall_protocol(bt, image, LoadFileProtocol::GUID, proto_load_file_ptr); - uninstall_protocol(bt, image, LoadFile2Protocol::GUID, proto_load_file_ptr); + uninstall_protocol(image, LoadFileProtocol::GUID, proto_load_file_ptr); + uninstall_protocol(image, LoadFile2Protocol::GUID, proto_load_file_ptr); } // Ensure protocols have been uninstalled: assert_eq!( - bt.open_protocol_exclusive::(image) + boot::open_protocol_exclusive::(image) .map(|_| ()) // make Result Eq'able .map_err(|e| e.status()), Err(Status::UNSUPPORTED) ); assert_eq!( - bt.open_protocol_exclusive::(image) + boot::open_protocol_exclusive::(image) .map(|_| ()) // make Result Eq'able .map_err(|e| e.status()), Err(Status::UNSUPPORTED) diff --git a/uefi-test-runner/src/proto/loaded_image.rs b/uefi-test-runner/src/proto/loaded_image.rs index 648db3ac5..c192bb5f3 100644 --- a/uefi-test-runner/src/proto/loaded_image.rs +++ b/uefi-test-runner/src/proto/loaded_image.rs @@ -1,11 +1,10 @@ use uefi::prelude::*; use uefi::proto::loaded_image::LoadedImage; -pub fn test(bt: &BootServices) { +pub fn test() { info!("Running loaded image protocol test"); - let loaded_image = bt - .open_protocol_exclusive::(bt.image_handle()) + let loaded_image = boot::open_protocol_exclusive::(boot::image_handle()) .expect("Failed to open LoadedImage protocol"); let load_options = loaded_image.load_options_as_bytes(); diff --git a/uefi-test-runner/src/proto/media.rs b/uefi-test-runner/src/proto/media.rs index 3ba3a00e7..3c9338b3b 100644 --- a/uefi-test-runner/src/proto/media.rs +++ b/uefi-test-runner/src/proto/media.rs @@ -244,34 +244,32 @@ fn test_create_directory(root_dir: &mut Directory) { } /// Get the media ID via the BlockIO protocol. -fn get_block_media_id(handle: Handle, bt: &BootServices) -> u32 { +fn get_block_media_id(handle: Handle) -> u32 { // This cannot be opened in `EXCLUSIVE` mode, as doing so // unregisters the `DiskIO` protocol from the handle. unsafe { - let block_io = bt - .open_protocol::( - OpenProtocolParams { - handle, - agent: bt.image_handle(), - controller: None, - }, - OpenProtocolAttributes::GetProtocol, - ) - .expect("Failed to get block I/O protocol"); + let block_io = boot::open_protocol::( + OpenProtocolParams { + handle, + agent: boot::image_handle(), + controller: None, + }, + OpenProtocolAttributes::GetProtocol, + ) + .expect("Failed to get block I/O protocol"); block_io.media().media_id() } } /// Tests raw disk I/O. -fn test_raw_disk_io(handle: Handle, bt: &BootServices) { +fn test_raw_disk_io(handle: Handle) { info!("Testing raw disk I/O"); - let media_id = get_block_media_id(handle, bt); + let media_id = get_block_media_id(handle); // Open the disk I/O protocol on the input handle - let disk_io = bt - .open_protocol_exclusive::(handle) - .expect("Failed to get disk I/O protocol"); + let disk_io = + boot::open_protocol_exclusive::(handle).expect("Failed to get disk I/O protocol"); // Read from the first sector of the disk into the buffer let mut buf = vec![0; 512]; @@ -296,12 +294,12 @@ struct DiskIoTask { } /// Tests raw disk I/O through the DiskIo2 protocol. -fn test_raw_disk_io2(handle: Handle, bt: &BootServices) { +fn test_raw_disk_io2(handle: Handle) { info!("Testing raw disk I/O 2"); // Open the disk I/O protocol on the input handle - if let Ok(disk_io2) = bt.open_protocol_exclusive::(handle) { - let media_id = get_block_media_id(handle, bt); + if let Ok(disk_io2) = boot::open_protocol_exclusive::(handle) { + let media_id = get_block_media_id(handle); unsafe { // Create the completion event @@ -329,7 +327,7 @@ fn test_raw_disk_io2(handle: Handle, bt: &BootServices) { .expect("Failed to initiate asynchronous disk I/O read"); // Wait for the transaction to complete - bt.wait_for_event(core::slice::from_mut(&mut event)) + boot::wait_for_event(core::slice::from_mut(&mut event)) .expect("Failed to wait on completion event"); // Verify that the disk's MBR signature is correct @@ -343,9 +341,8 @@ fn test_raw_disk_io2(handle: Handle, bt: &BootServices) { } /// Check that `disk_handle` points to the expected MBR partition. -fn test_partition_info(bt: &BootServices, disk_handle: Handle) { - let pi = bt - .open_protocol_exclusive::(disk_handle) +fn test_partition_info(disk_handle: Handle) { + let pi = boot::open_protocol_exclusive::(disk_handle) .expect("Failed to get partition info"); let mbr = pi.mbr_partition_record().expect("Not an MBR disk"); @@ -362,9 +359,8 @@ fn test_partition_info(bt: &BootServices, disk_handle: Handle) { /// Find the disk with the "MbrTestDisk" label. Return the handle and opened /// `SimpleFileSystem` protocol for that disk. -fn find_test_disk(bt: &BootServices) -> (Handle, ScopedProtocol) { - let handles = bt - .find_handles::() +fn find_test_disk() -> (Handle, ScopedProtocol) { + let handles = boot::find_handles::() .expect("Failed to get handles for `SimpleFileSystem` protocol"); assert_eq!(handles.len(), 2); @@ -387,8 +383,8 @@ fn find_test_disk(bt: &BootServices) -> (Handle, ScopedProtocol) { info!("Testing various protocols"); - console::test(st); + console::test(); let bt = st.boot_services(); - find_protocol(bt); - test_protocols_per_handle(bt); - test_protocols_per_handle_freestanding(); - test_test_protocol_freestanding(); + find_protocol(); + test_protocols_per_handle(); + test_test_protocol(); - debug::test(bt); - device_path::test(bt); + debug::test(); + device_path::test(); driver::test(); - load::test(bt); - loaded_image::test(bt); - media::test(bt); + load::test(); + loaded_image::test(); + media::test(); network::test(bt); pi::test(bt); - rng::test(bt); + rng::test(); shell_params::test(bt); - string::test(bt); + string::test(); misc::test(bt); #[cfg(any( @@ -33,13 +32,12 @@ pub fn test(st: &mut SystemTable) { target_arch = "arm", target_arch = "aarch64" ))] - shim::test(bt); - tcg::test(bt); + shim::test(); + tcg::test(); } -fn find_protocol(bt: &BootServices) { - let handles = bt - .find_handles::() +fn find_protocol() { + let handles = boot::find_handles::() .expect("Failed to retrieve list of handles"); assert!( @@ -48,25 +46,14 @@ fn find_protocol(bt: &BootServices) { ); } -fn test_protocols_per_handle(bt: &BootServices) { - let pph = bt - .protocols_per_handle(bt.image_handle()) - .expect("Failed to get protocols for image handle"); - - info!("Image handle has {} protocols", pph.len()); - - // Check that one of the image's protocols is `LoadedImage`. - assert!(pph.iter().any(|guid| **guid == LoadedImage::GUID)); -} - -fn test_protocols_per_handle_freestanding() { +fn test_protocols_per_handle() { let pph = boot::protocols_per_handle(boot::image_handle()).unwrap(); info!("Image handle has {} protocols", pph.len()); // Check that one of the image's protocols is `LoadedImage`. assert!(pph.iter().any(|guid| **guid == LoadedImage::GUID)); } -fn test_test_protocol_freestanding() { +fn test_test_protocol() { assert!(boot::test_protocol::(OpenProtocolParams { handle: boot::image_handle(), agent: boot::image_handle(), diff --git a/uefi-test-runner/src/proto/rng.rs b/uefi-test-runner/src/proto/rng.rs index 572588396..4eb7a414d 100644 --- a/uefi-test-runner/src/proto/rng.rs +++ b/uefi-test-runner/src/proto/rng.rs @@ -1,14 +1,13 @@ +use uefi::boot; use uefi::proto::rng::{Rng, RngAlgorithmType}; -use uefi::table::boot::BootServices; -pub fn test(bt: &BootServices) { +pub fn test() { info!("Running rng protocol test"); - let handle = bt.get_handle_for_protocol::().expect("No Rng handles"); + let handle = boot::get_handle_for_protocol::().expect("No Rng handles"); - let mut rng = bt - .open_protocol_exclusive::(handle) - .expect("Failed to open Rng protocol"); + let mut rng = + boot::open_protocol_exclusive::(handle).expect("Failed to open Rng protocol"); let mut list = [RngAlgorithmType::EMPTY_ALGORITHM; 4]; diff --git a/uefi-test-runner/src/proto/shim.rs b/uefi-test-runner/src/proto/shim.rs index 333c1da86..a4d7a3523 100644 --- a/uefi-test-runner/src/proto/shim.rs +++ b/uefi-test-runner/src/proto/shim.rs @@ -1,12 +1,11 @@ +use uefi::boot; use uefi::proto::shim::ShimLock; -use uefi::table::boot::BootServices; -pub fn test(bt: &BootServices) { +pub fn test() { info!("Running shim lock protocol test"); - if let Ok(handle) = bt.get_handle_for_protocol::() { - let shim_lock = bt - .open_protocol_exclusive::(handle) + if let Ok(handle) = boot::get_handle_for_protocol::() { + let shim_lock = boot::open_protocol_exclusive::(handle) .expect("failed to open shim lock protocol"); // An empty buffer should definitely be invalid, so expect diff --git a/uefi-test-runner/src/proto/string/mod.rs b/uefi-test-runner/src/proto/string/mod.rs index 79e751e3c..b98b34218 100644 --- a/uefi-test-runner/src/proto/string/mod.rs +++ b/uefi-test-runner/src/proto/string/mod.rs @@ -1,9 +1,7 @@ -use uefi::prelude::*; - -pub fn test(bt: &BootServices) { +pub fn test() { info!("Testing String protocols"); - unicode_collation::test(bt); + unicode_collation::test(); } mod unicode_collation; diff --git a/uefi-test-runner/src/proto/string/unicode_collation.rs b/uefi-test-runner/src/proto/string/unicode_collation.rs index 0c889c56f..4670c15c0 100644 --- a/uefi-test-runner/src/proto/string/unicode_collation.rs +++ b/uefi-test-runner/src/proto/string/unicode_collation.rs @@ -1,18 +1,14 @@ use core::cmp::Ordering; -use uefi::prelude::*; use uefi::proto::string::unicode_collation::{StrConversionError, UnicodeCollation}; -use uefi::{CStr16, CStr8}; +use uefi::{boot, CStr16, CStr8}; -pub fn test(bt: &BootServices) { +pub fn test() { info!("Testing the Unicode Collation protocol"); - let handles = bt - .find_handles::() - .expect("missing UnicodeCollation protocol"); + let handles = + boot::find_handles::().expect("missing UnicodeCollation protocol"); for handle in handles { - let uc = bt - .open_protocol_exclusive::(handle) - .unwrap(); + let uc = boot::open_protocol_exclusive::(handle).unwrap(); let mut buf1 = [0; 30]; let mut buf2 = [0; 30]; diff --git a/uefi-test-runner/src/proto/tcg.rs b/uefi-test-runner/src/proto/tcg.rs index b74772578..55bf3e359 100644 --- a/uefi-test-runner/src/proto/tcg.rs +++ b/uefi-test-runner/src/proto/tcg.rs @@ -1,6 +1,6 @@ use alloc::vec::Vec; +use uefi::boot; use uefi::proto::tcg::{v1, v2, AlgorithmId, EventType, HashAlgorithm, PcrIndex}; -use uefi::table::boot::BootServices; // Environmental note: // @@ -44,7 +44,7 @@ fn tcg_v1_read_pcr(tcg: &mut v1::Tcg, pcr_index: PcrIndex) -> v1::Sha1Digest { output[10..].try_into().unwrap() } -fn test_tcg_v1(bt: &BootServices) { +fn test_tcg_v1() { // Skip the test of the `tpm_v1` feature is not enabled. if cfg!(not(feature = "tpm_v1")) { return; @@ -52,13 +52,10 @@ fn test_tcg_v1(bt: &BootServices) { info!("Running TCG v1 test"); - let handle = bt - .get_handle_for_protocol::() - .expect("no TCG handle found"); + let handle = boot::get_handle_for_protocol::().expect("no TCG handle found"); - let mut tcg = bt - .open_protocol_exclusive::(handle) - .expect("failed to open TCG protocol"); + let mut tcg = + boot::open_protocol_exclusive::(handle).expect("failed to open TCG protocol"); let pcr_index = PcrIndex(8); @@ -213,7 +210,7 @@ fn tcg_v2_read_pcr_8(tcg: &mut v2::Tcg) -> v1::Sha1Digest { output[30..].try_into().unwrap() } -pub fn test_tcg_v2(bt: &BootServices) { +pub fn test_tcg_v2() { // Skip the test of the `tpm_v2` feature is not enabled. if cfg!(not(feature = "tpm_v2")) { return; @@ -221,13 +218,10 @@ pub fn test_tcg_v2(bt: &BootServices) { info!("Running TCG v2 test"); - let handle = bt - .get_handle_for_protocol::() - .expect("no TCG handle found"); + let handle = boot::get_handle_for_protocol::().expect("no TCG handle found"); - let mut tcg = bt - .open_protocol_exclusive::(handle) - .expect("failed to open TCG protocol"); + let mut tcg = + boot::open_protocol_exclusive::(handle).expect("failed to open TCG protocol"); let expected_banks = HashAlgorithm::SHA1 | HashAlgorithm::SHA256 | HashAlgorithm::SHA384 | HashAlgorithm::SHA512; @@ -360,7 +354,7 @@ pub fn test_tcg_v2(bt: &BootServices) { ); } -pub fn test(bt: &BootServices) { - test_tcg_v1(bt); - test_tcg_v2(bt); +pub fn test() { + test_tcg_v1(); + test_tcg_v2(); }