From 515a508979e9e64e02fcd569914bbde8e0c016d3 Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Sun, 14 Apr 2024 14:36:51 -0400 Subject: [PATCH] Update test-runner --- uefi-test-runner/src/bin/shell_launcher.rs | 48 +++---- uefi-test-runner/src/boot/memory.rs | 25 ++-- uefi-test-runner/src/boot/misc.rs | 143 +++++++++---------- uefi-test-runner/src/boot/mod.rs | 29 ++-- uefi-test-runner/src/main.rs | 56 ++++---- uefi-test-runner/src/proto/console/gop.rs | 2 +- uefi-test-runner/src/proto/console/mod.rs | 5 +- uefi-test-runner/src/proto/console/serial.rs | 16 +-- uefi-test-runner/src/proto/device_path.rs | 7 +- 9 files changed, 150 insertions(+), 181 deletions(-) diff --git a/uefi-test-runner/src/bin/shell_launcher.rs b/uefi-test-runner/src/bin/shell_launcher.rs index 4accdca6f..3c9871826 100644 --- a/uefi-test-runner/src/bin/shell_launcher.rs +++ b/uefi-test-runner/src/bin/shell_launcher.rs @@ -18,16 +18,14 @@ use uefi::proto::device_path::build::{self, DevicePathBuilder}; use uefi::proto::device_path::{DevicePath, DeviceSubType, DeviceType, LoadedImageDevicePath}; use uefi::proto::loaded_image::LoadedImage; use uefi::table::boot::LoadImageSource; +use uefi::{boot, Result}; /// Get the device path of the shell app. This is the same as the /// currently-loaded image's device path, but with the file path part changed. -fn get_shell_app_device_path<'a>( - boot_services: &BootServices, - storage: &'a mut Vec, -) -> &'a DevicePath { - let loaded_image_device_path = boot_services - .open_protocol_exclusive::(boot_services.image_handle()) - .expect("failed to open LoadedImageDevicePath protocol"); +fn get_shell_app_device_path(storage: &mut Vec) -> &DevicePath { + let loaded_image_device_path = + boot::open_protocol_exclusive::(boot::image_handle()) + .expect("failed to open LoadedImageDevicePath protocol"); let mut builder = DevicePathBuilder::with_vec(storage); for node in loaded_image_device_path.node_iter() { @@ -44,29 +42,25 @@ fn get_shell_app_device_path<'a>( builder.finalize().unwrap() } -#[entry] -fn efi_main(image: Handle, mut st: SystemTable) -> Status { - uefi::helpers::init(&mut st).unwrap(); - let boot_services = st.boot_services(); +fn main() -> Result { + uefi::helpers::init_v2().unwrap(); let mut storage = Vec::new(); - let shell_image_path = get_shell_app_device_path(boot_services, &mut storage); + let shell_image_path = get_shell_app_device_path(&mut storage); // Load the shell app. - let shell_image_handle = boot_services - .load_image( - image, - LoadImageSource::FromDevicePath { - device_path: shell_image_path, - from_boot_manager: false, - }, - ) - .expect("failed to load shell app"); + let shell_image_handle = boot::load_image( + boot::image_handle(), + LoadImageSource::FromDevicePath { + device_path: shell_image_path, + from_boot_manager: false, + }, + ) + .expect("failed to load shell app"); // Set the command line passed to the shell app so that it will run the // test-runner app. This automatically turns off the five-second delay. - let mut shell_loaded_image = boot_services - .open_protocol_exclusive::(shell_image_handle) + let mut shell_loaded_image = boot::open_protocol_exclusive::(shell_image_handle) .expect("failed to open LoadedImage protocol"); let load_options = cstr16!(r"shell.efi test_runner.efi arg1 arg2"); unsafe { @@ -77,9 +71,9 @@ fn efi_main(image: Handle, mut st: SystemTable) -> Status { } info!("launching the shell app"); - boot_services - .start_image(shell_image_handle) - .expect("failed to launch the shell app"); + boot::start_image(shell_image_handle).expect("failed to launch the shell app"); - Status::SUCCESS + Ok(()) } + +uefi::set_main!(main); diff --git a/uefi-test-runner/src/boot/memory.rs b/uefi-test-runner/src/boot/memory.rs index 078548991..04955e188 100644 --- a/uefi-test-runner/src/boot/memory.rs +++ b/uefi-test-runner/src/boot/memory.rs @@ -1,25 +1,24 @@ -use uefi::table::boot::{AllocateType, BootServices, MemoryType}; +use uefi::boot; +use uefi::table::boot::{AllocateType, MemoryType}; use alloc::vec::Vec; -pub fn test(bt: &BootServices) { +pub fn test() { info!("Testing memory functions"); - allocate_pages(bt); + allocate_pages(); vec_alloc(); alloc_alignment(); - memory_map(bt); + memory_map(); } -fn allocate_pages(bt: &BootServices) { +fn allocate_pages() { info!("Allocating some pages of memory"); let ty = AllocateType::AnyPages; let mem_ty = MemoryType::LOADER_DATA; - let pgs = bt - .allocate_pages(ty, mem_ty, 1) - .expect("Failed to allocate a page of memory"); + let pgs = boot::allocate_pages(ty, mem_ty, 1).expect("Failed to allocate a page of memory"); assert_eq!(pgs % 4096, 0, "Page pointer is not page-aligned"); @@ -31,7 +30,7 @@ fn allocate_pages(bt: &BootServices) { buf[4095] = 0x23; // Clean up to avoid memory leaks. - unsafe { bt.free_pages(pgs, 1) }.unwrap(); + unsafe { boot::free_pages(pgs, 1) }.unwrap(); } // Simple test to ensure our custom allocator works with the `alloc` crate. @@ -60,11 +59,11 @@ fn alloc_alignment() { assert_eq!(value.as_ptr() as usize % 0x100, 0, "Wrong alignment"); } -fn memory_map(bt: &BootServices) { +fn memory_map() { info!("Testing memory map functions"); // Get the memory descriptor size and an estimate of the memory map size - let sizes = bt.memory_map_size(); + let sizes = boot::memory_map_size(); // 2 extra descriptors should be enough. let buf_sz = sizes.map_size + 2 * sizes.entry_size; @@ -72,9 +71,7 @@ fn memory_map(bt: &BootServices) { // We will use vectors for convenience. let mut buffer = vec![0_u8; buf_sz]; - let mut memory_map = bt - .memory_map(&mut buffer) - .expect("Failed to retrieve UEFI memory map"); + let mut memory_map = boot::memory_map(&mut buffer).expect("Failed to retrieve UEFI memory map"); memory_map.sort(); diff --git a/uefi-test-runner/src/boot/misc.rs b/uefi-test-runner/src/boot/misc.rs index 0399ff2ba..238ecf118 100644 --- a/uefi-test-runner/src/boot/misc.rs +++ b/uefi-test-runner/src/boot/misc.rs @@ -4,51 +4,49 @@ use core::ptr::{self, NonNull}; use core::mem; use uefi::proto::unsafe_protocol; use uefi::table::boot::{ - BootServices, EventType, MemoryType, OpenProtocolAttributes, OpenProtocolParams, SearchType, - TimerTrigger, Tpl, + EventType, MemoryType, OpenProtocolAttributes, OpenProtocolParams, SearchType, TimerTrigger, + Tpl, }; -use uefi::table::{Boot, SystemTable}; +use uefi::{boot, system}; use uefi::{guid, Event, Guid, Identify}; -pub fn test(st: &SystemTable) { - let bt = st.boot_services(); +pub fn test() { info!("Testing timer..."); - test_timer(bt); + test_timer(); info!("Testing events..."); - test_event_callback(bt); - test_callback_with_ctx(bt); + test_event_callback(); + test_callback_with_ctx(); info!("Testing watchdog..."); - test_watchdog(bt); + test_watchdog(); info!("Testing protocol handler services..."); - test_register_protocol_notify(bt); - test_install_protocol_interface(bt); - test_reinstall_protocol_interface(bt); - test_uninstall_protocol_interface(bt); - test_install_configuration_table(st); + test_register_protocol_notify(); + test_install_protocol_interface(); + test_reinstall_protocol_interface(); + test_uninstall_protocol_interface(); + test_install_configuration_table(); } -fn test_timer(bt: &BootServices) { - let timer_event = unsafe { bt.create_event(EventType::TIMER, Tpl::APPLICATION, None, None) } +fn test_timer() { + let timer_event = unsafe { boot::create_event(EventType::TIMER, Tpl::APPLICATION, None, None) } .expect("Failed to create TIMER event"); let mut events = unsafe { [timer_event.unsafe_clone()] }; - bt.set_timer(&timer_event, TimerTrigger::Relative(5_0 /*00 ns */)) + boot::set_timer(&timer_event, TimerTrigger::Relative(5_0 /*00 ns */)) .expect("Failed to set timer"); - bt.wait_for_event(&mut events) - .expect("Wait for event failed"); + boot::wait_for_event(&mut events).expect("Wait for event failed"); } -fn test_event_callback(bt: &BootServices) { +fn test_event_callback() { extern "efiapi" fn callback(_event: Event, _ctx: Option>) { info!("Inside the event callback"); } let event = - unsafe { bt.create_event(EventType::NOTIFY_WAIT, Tpl::CALLBACK, Some(callback), None) } + unsafe { boot::create_event(EventType::NOTIFY_WAIT, Tpl::CALLBACK, Some(callback), None) } .expect("Failed to create custom event"); - bt.check_event(event).expect("Failed to check event"); + boot::check_event(event).expect("Failed to check event"); } -fn test_callback_with_ctx(bt: &BootServices) { +fn test_callback_with_ctx() { let mut data = 123u32; extern "efiapi" fn callback(_event: Event, ctx: Option>) { @@ -65,7 +63,7 @@ fn test_callback_with_ctx(bt: &BootServices) { let ctx = NonNull::new(ctx.cast::()).unwrap(); let event = unsafe { - bt.create_event( + boot::create_event( EventType::NOTIFY_WAIT, Tpl::CALLBACK, Some(callback), @@ -74,16 +72,15 @@ fn test_callback_with_ctx(bt: &BootServices) { .expect("Failed to create event with context") }; - bt.check_event(event).expect("Failed to check event"); + boot::check_event(event).expect("Failed to check event"); // Check that `data` was updated inside the event callback. assert_eq!(data, 456); } -fn test_watchdog(bt: &BootServices) { +fn test_watchdog() { // Disable the UEFI watchdog timer - bt.set_watchdog_timer(0, 0x10000, None) - .expect("Could not set watchdog timer"); + boot::set_watchdog_timer(0, 0x10000, None).expect("Could not set watchdog timer"); } /// Dummy protocol for tests @@ -96,10 +93,10 @@ unsafe extern "efiapi" fn _test_notify(_event: Event, _context: Option(), - ) - .unwrap() - .cast(); + let alloc: *mut TestProtocol = boot::allocate_pool( + MemoryType::BOOT_SERVICES_DATA, + mem::size_of::(), + ) + .unwrap() + .cast(); unsafe { alloc.write(TestProtocol { data: 123 }) }; let _ = unsafe { - bt.install_protocol_interface(None, &TestProtocol::GUID, alloc.cast()) + boot::install_protocol_interface(None, &TestProtocol::GUID, alloc.cast()) .expect("Failed to install protocol interface") }; - let _ = bt - .locate_handle_buffer(SearchType::from_proto::()) + let _ = boot::locate_handle_buffer(SearchType::from_proto::()) .expect("Failed to find protocol after it was installed"); } -fn test_reinstall_protocol_interface(bt: &BootServices) { +fn test_reinstall_protocol_interface() { info!("Reinstalling TestProtocol"); - let handle = bt - .locate_handle_buffer(SearchType::from_proto::()) + let handle = boot::locate_handle_buffer(SearchType::from_proto::()) .expect("Failed to find protocol to uninstall")[0]; unsafe { - let _ = bt.reinstall_protocol_interface( + let _ = boot::reinstall_protocol_interface( handle, &TestProtocol::GUID, ptr::null_mut(), @@ -150,11 +143,10 @@ fn test_reinstall_protocol_interface(bt: &BootServices) { } } -fn test_uninstall_protocol_interface(bt: &BootServices) { +fn test_uninstall_protocol_interface() { info!("Uninstalling TestProtocol"); - let handle = bt - .locate_handle_buffer(SearchType::from_proto::()) + let handle = boot::locate_handle_buffer(SearchType::from_proto::()) .expect("Failed to find protocol to uninstall")[0]; unsafe { @@ -162,48 +154,45 @@ fn test_uninstall_protocol_interface(bt: &BootServices) { // pointer. Open the protocol to get that pointer, making sure to drop // the `ScopedProtocol` _before_ uninstalling the protocol interface. let interface_ptr: *mut TestProtocol = { - let mut sp = bt - .open_protocol::( - OpenProtocolParams { - handle, - agent: bt.image_handle(), - controller: None, - }, - OpenProtocolAttributes::GetProtocol, - ) - .unwrap(); + let mut sp = boot::open_protocol::( + OpenProtocolParams { + handle, + agent: boot::image_handle(), + controller: None, + }, + OpenProtocolAttributes::GetProtocol, + ) + .unwrap(); assert_eq!(sp.data, 123); &mut *sp }; - bt.uninstall_protocol_interface(handle, &TestProtocol::GUID, interface_ptr.cast()) + boot::uninstall_protocol_interface(handle, &TestProtocol::GUID, interface_ptr.cast()) .expect("Failed to uninstall protocol interface"); - bt.free_pool(interface_ptr.cast()).unwrap(); + boot::free_pool(interface_ptr.cast()).unwrap(); } } -fn test_install_configuration_table(st: &SystemTable) { - let config = st - .boot_services() - .allocate_pool(MemoryType::ACPI_RECLAIM, 1) - .expect("Failed to allocate config table"); +fn test_install_configuration_table() { + let config = + boot::allocate_pool(MemoryType::ACPI_RECLAIM, 1).expect("Failed to allocate config table"); unsafe { config.write(42) }; - let count = st.config_table().len(); + let count = system::with_config_table(|t| t.len()); const ID: Guid = guid!("3bdb3089-5662-42df-840e-3922ed6467c9"); unsafe { - st.boot_services() - .install_configuration_table(&ID, config.cast()) + boot::install_configuration_table(&ID, config.cast()) .expect("Failed to install configuration table"); } - assert_eq!(count + 1, st.config_table().len()); - let config_entry = st - .config_table() - .iter() - .find(|ct| ct.guid == ID) - .expect("Failed to find test config table"); - assert_eq!(unsafe { *(config_entry.address as *const u8) }, 42); + assert_eq!(count + 1, system::with_config_table(|t| t.len())); + let entry_addr = system::with_config_table(|t| { + t.iter() + .find(|ct| ct.guid == ID) + .expect("Failed to find test config table") + .address + }); + assert_eq!(unsafe { *(entry_addr as *const u8) }, 42); } diff --git a/uefi-test-runner/src/boot/mod.rs b/uefi-test-runner/src/boot/mod.rs index 74e817afe..9320330d6 100644 --- a/uefi-test-runner/src/boot/mod.rs +++ b/uefi-test-runner/src/boot/mod.rs @@ -3,37 +3,33 @@ use uefi::fs::FileSystem; use uefi::proto::console::text::Output; use uefi::proto::device_path::media::FilePath; use uefi::proto::device_path::{DevicePath, LoadedImageDevicePath}; -use uefi::table::boot::{BootServices, LoadImageSource, SearchType}; -use uefi::table::{Boot, SystemTable}; -use uefi::{CString16, Identify}; +use uefi::table::boot::{LoadImageSource, SearchType}; +use uefi::{boot, system, CString16, Identify}; mod memory; mod misc; -pub fn test(st: &SystemTable) { - let bt = st.boot_services(); +pub fn test() { info!("Testing boot services"); - memory::test(bt); - misc::test(st); - test_locate_handle_buffer(bt); - test_load_image(bt); + memory::test(); + misc::test(); + test_locate_handle_buffer(); + test_load_image(); } -fn test_locate_handle_buffer(bt: &BootServices) { +fn test_locate_handle_buffer() { info!("Testing the `locate_handle_buffer` function"); { // search all handles - let handles = bt - .locate_handle_buffer(SearchType::AllHandles) + let handles = boot::locate_handle_buffer(SearchType::AllHandles) .expect("Failed to locate handle buffer"); assert!(!handles.is_empty(), "Could not find any handles"); } { // search by protocol - let handles = bt - .locate_handle_buffer(SearchType::ByProtocol(&Output::GUID)) + let handles = boot::locate_handle_buffer(SearchType::ByProtocol(&Output::GUID)) .expect("Failed to locate handle buffer"); assert!( !handles.is_empty(), @@ -47,7 +43,10 @@ fn test_locate_handle_buffer(bt: &BootServices) { /// /// It transitively tests the protocol [`LoadedImageDevicePath`] which is /// required as helper. -fn test_load_image(bt: &BootServices) { +fn test_load_image() { + let st = system::system_table_boot(); + let bt = st.boot_services(); + /// The path of the loaded image executing this integration test. const LOADED_IMAGE_PATH: &str = r"\EFI\BOOT\TEST_RUNNER.EFI"; diff --git a/uefi-test-runner/src/main.rs b/uefi-test-runner/src/main.rs index b3a3e7ad4..8bcf27930 100644 --- a/uefi-test-runner/src/main.rs +++ b/uefi-test-runner/src/main.rs @@ -13,22 +13,22 @@ use uefi::proto::console::serial::Serial; use uefi::proto::device_path::build::{self, DevicePathBuilder}; use uefi::proto::device_path::messaging::Vendor; use uefi::table::boot::MemoryType; -use uefi::Result; -use uefi::{print, println}; +use uefi::{print, println, system, Result}; mod boot; mod fs; mod proto; mod runtime; -#[entry] -fn efi_main(image: Handle, mut st: SystemTable) -> Status { +uefi::set_main!(main); + +fn main() -> Result { // Initialize utilities (logging, memory allocation...) - uefi::helpers::init(&mut st).expect("Failed to initialize utilities"); + uefi::helpers::init_v2().expect("Failed to initialize utilities"); // unit tests here - let firmware_vendor = st.firmware_vendor(); + let firmware_vendor = system::firmware_vendor(); info!("Firmware Vendor: {}", firmware_vendor); assert_eq!(firmware_vendor.to_string(), "EDK II"); @@ -41,22 +41,21 @@ fn efi_main(image: Handle, mut st: SystemTable) -> Status { ); // Reset the console before running all the other tests. - st.stdout().reset(false).expect("Failed to reset stdout"); + system::with_stdout(|stdout| stdout.reset(false).expect("Failed to reset stdout")); // Ensure the tests are run on a version of UEFI we support. - check_revision(st.uefi_revision()); - - // Test all the boot services. - let bt = st.boot_services(); + check_revision(system::uefi_revision()); // Try retrieving a handle to the file system the image was booted from. - bt.get_image_file_system(image) + uefi::boot::get_image_file_system(uefi::boot::image_handle()) .expect("Failed to retrieve boot file system"); - boot::test(&st); + boot::test(); + + let mut st = system::system_table_boot(); // Test all the supported protocols. - proto::test(image, &mut st); + proto::test(st.boot_services().image_handle(), &mut st); // TODO: runtime services work before boot services are exited, but we'd // probably want to test them after exit_boot_services. However, @@ -64,7 +63,7 @@ fn efi_main(image: Handle, mut st: SystemTable) -> Status { runtime::test(st.runtime_services()); - shutdown(st); + shutdown(system::system_table_boot()); } fn check_revision(rev: uefi::table::Revision) { @@ -120,7 +119,7 @@ fn send_request_helper(serial: &mut Serial, request: HostRequest) -> Result { /// This must be called after opening the serial protocol in exclusive mode, as /// that breaks the connection to the console, which in turn prevents logs from /// getting to the host. -fn reconnect_serial_to_console(boot_services: &BootServices, serial_handle: Handle) { +fn reconnect_serial_to_console(serial_handle: Handle) { let mut storage = Vec::new(); // Create a device path that specifies the terminal type. let terminal_guid = if cfg!(target_arch = "aarch64") { @@ -137,18 +136,16 @@ fn reconnect_serial_to_console(boot_services: &BootServices, serial_handle: Hand .finalize() .unwrap(); - boot_services - .connect_controller(serial_handle, None, Some(terminal_device_path), true) + uefi::boot::connect_controller(serial_handle, None, Some(terminal_device_path), true) .expect("failed to reconnect serial to console"); } /// Send the `request` string to the host via the `serial` device, then /// wait up to 10 seconds to receive a reply. Returns an error if the /// reply is not `"OK\n"`. -fn send_request_to_host(bt: &BootServices, request: HostRequest) { - let serial_handle = bt - .get_handle_for_protocol::() - .expect("Failed to get serial handle"); +fn send_request_to_host(request: HostRequest) { + let serial_handle = + uefi::boot::get_handle_for_protocol::().expect("Failed to get serial handle"); // Open the serial protocol in exclusive mode. // @@ -161,8 +158,7 @@ fn send_request_to_host(bt: &BootServices, request: HostRequest) { // end with `connect_controller`. // // [console splitter driver]: https://github.com/tianocore/edk2/blob/HEAD/MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.c - let mut serial = bt - .open_protocol_exclusive::(serial_handle) + let mut serial = uefi::boot::open_protocol_exclusive::(serial_handle) .expect("Could not open serial protocol"); // Send the request, but don't check the result yet so that first @@ -175,7 +171,7 @@ fn send_request_to_host(bt: &BootServices, request: HostRequest) { // device, which was broken when we opened the protocol in exclusive // mode above. drop(serial); - reconnect_serial_to_console(bt, serial_handle); + reconnect_serial_to_console(serial_handle); if let Err(err) = res { panic!("request failed: \"{request:?}\": {:?}", err.status()); @@ -189,7 +185,7 @@ fn shutdown(mut st: SystemTable) -> ! { // Tell the host that tests are done. We are about to exit boot // services, so we can't easily communicate with the host any later // than this. - send_request_to_host(st.boot_services(), HostRequest::TestsComplete); + send_request_to_host(HostRequest::TestsComplete); // Send a special log to the host so that we can verify that logging works // up until exiting boot services. See `reconnect_serial_to_console` for the @@ -199,13 +195,10 @@ fn shutdown(mut st: SystemTable) -> ! { info!("Testing complete, shutting down..."); // Exit boot services as a proof that it works :) - let (st, _iter) = st.exit_boot_services(MemoryType::LOADER_DATA); + let _iter = uefi::boot::exit_boot_services(MemoryType::LOADER_DATA); #[cfg(target_arch = "x86_64")] { - // Prevent unused variable warning. - let _ = st; - use qemu_exit::QEMUExit; let custom_exit_success = 3; let qemu_exit_handle = qemu_exit::X86::new(0xF4, custom_exit_success); @@ -215,8 +208,7 @@ fn shutdown(mut st: SystemTable) -> ! { #[cfg(not(target_arch = "x86_64"))] { // Shut down the system - let rt = unsafe { st.runtime_services() }; - rt.reset( + crate::runtime::reset( uefi::table::runtime::ResetType::SHUTDOWN, Status::SUCCESS, None, diff --git a/uefi-test-runner/src/proto/console/gop.rs b/uefi-test-runner/src/proto/console/gop.rs index 8ce714351..37658ef18 100644 --- a/uefi-test-runner/src/proto/console/gop.rs +++ b/uefi-test-runner/src/proto/console/gop.rs @@ -28,7 +28,7 @@ pub unsafe fn test(image: Handle, bt: &BootServices) { // `draw_fb` is skipped on aarch64, so the screenshot doesn't match. if cfg!(not(target_arch = "aarch64")) { - send_request_to_host(bt, HostRequest::Screenshot("gop_test")); + send_request_to_host(HostRequest::Screenshot("gop_test")); } } diff --git a/uefi-test-runner/src/proto/console/mod.rs b/uefi-test-runner/src/proto/console/mod.rs index f11b2ef01..3b278f045 100644 --- a/uefi-test-runner/src/proto/console/mod.rs +++ b/uefi-test-runner/src/proto/console/mod.rs @@ -1,13 +1,14 @@ use uefi::prelude::*; +use uefi::system; pub fn test(image: Handle, st: &mut SystemTable) { info!("Testing console protocols"); - stdout::test(st.stdout()); + system::with_stdout(stdout::test); let bt = st.boot_services(); unsafe { - serial::test(bt); + serial::test(); gop::test(image, bt); } pointer::test(bt); diff --git a/uefi-test-runner/src/proto/console/serial.rs b/uefi-test-runner/src/proto/console/serial.rs index a39d448ef..be20e0064 100644 --- a/uefi-test-runner/src/proto/console/serial.rs +++ b/uefi-test-runner/src/proto/console/serial.rs @@ -1,7 +1,6 @@ use crate::reconnect_serial_to_console; use uefi::proto::console::serial::{ControlBits, Serial}; -use uefi::table::boot::BootServices; -use uefi::{Result, ResultExt, Status}; +use uefi::{boot, Result, ResultExt, Status}; // For the duration of this function, the serial device is opened in // exclusive mode. That means logs will not work, which means we should @@ -41,7 +40,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 +48,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. @@ -67,7 +63,7 @@ pub unsafe fn test(bt: &BootServices) { // device, which was broken when we opened the protocol in exclusive // mode above. drop(serial); - reconnect_serial_to_console(bt, handle); + reconnect_serial_to_console(handle); if let Err(err) = res { panic!("serial test failed: {:?}", err.status()); diff --git a/uefi-test-runner/src/proto/device_path.rs b/uefi-test-runner/src/proto/device_path.rs index fb99d5792..023afb95d 100644 --- a/uefi-test-runner/src/proto/device_path.rs +++ b/uefi-test-runner/src/proto/device_path.rs @@ -1,5 +1,6 @@ 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}; @@ -68,9 +69,9 @@ pub fn test(image: Handle, bt: &BootServices) { // test 2/2: test high-level to-string api { - let loaded_image_device_path = bt - .open_protocol_exclusive::(image) - .expect("Failed to open LoadedImageDevicePath protocol"); + let loaded_image_device_path = + boot::open_protocol_exclusive::(image) + .expect("Failed to open LoadedImageDevicePath protocol"); let device_path: &DevicePath = &loaded_image_device_path; let path_components = device_path