Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 19db510

Browse files
committedMay 2, 2024·
Update test-runner
1 parent 9121ad1 commit 19db510

File tree

9 files changed

+150
-181
lines changed

9 files changed

+150
-181
lines changed
 

‎uefi-test-runner/src/bin/shell_launcher.rs

+21-27
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,14 @@ use uefi::proto::device_path::build::{self, DevicePathBuilder};
1818
use uefi::proto::device_path::{DevicePath, DeviceSubType, DeviceType, LoadedImageDevicePath};
1919
use uefi::proto::loaded_image::LoadedImage;
2020
use uefi::table::boot::LoadImageSource;
21+
use uefi::{boot, Result};
2122

2223
/// Get the device path of the shell app. This is the same as the
2324
/// currently-loaded image's device path, but with the file path part changed.
24-
fn get_shell_app_device_path<'a>(
25-
boot_services: &BootServices,
26-
storage: &'a mut Vec<u8>,
27-
) -> &'a DevicePath {
28-
let loaded_image_device_path = boot_services
29-
.open_protocol_exclusive::<LoadedImageDevicePath>(boot_services.image_handle())
30-
.expect("failed to open LoadedImageDevicePath protocol");
25+
fn get_shell_app_device_path(storage: &mut Vec<u8>) -> &DevicePath {
26+
let loaded_image_device_path =
27+
boot::open_protocol_exclusive::<LoadedImageDevicePath>(boot::image_handle())
28+
.expect("failed to open LoadedImageDevicePath protocol");
3129

3230
let mut builder = DevicePathBuilder::with_vec(storage);
3331
for node in loaded_image_device_path.node_iter() {
@@ -44,29 +42,25 @@ fn get_shell_app_device_path<'a>(
4442
builder.finalize().unwrap()
4543
}
4644

47-
#[entry]
48-
fn efi_main(image: Handle, mut st: SystemTable<Boot>) -> Status {
49-
uefi::helpers::init(&mut st).unwrap();
50-
let boot_services = st.boot_services();
45+
fn main() -> Result {
46+
uefi::helpers::init_v2().unwrap();
5147

5248
let mut storage = Vec::new();
53-
let shell_image_path = get_shell_app_device_path(boot_services, &mut storage);
49+
let shell_image_path = get_shell_app_device_path(&mut storage);
5450

5551
// Load the shell app.
56-
let shell_image_handle = boot_services
57-
.load_image(
58-
image,
59-
LoadImageSource::FromDevicePath {
60-
device_path: shell_image_path,
61-
from_boot_manager: false,
62-
},
63-
)
64-
.expect("failed to load shell app");
52+
let shell_image_handle = boot::load_image(
53+
boot::image_handle(),
54+
LoadImageSource::FromDevicePath {
55+
device_path: shell_image_path,
56+
from_boot_manager: false,
57+
},
58+
)
59+
.expect("failed to load shell app");
6560

6661
// Set the command line passed to the shell app so that it will run the
6762
// test-runner app. This automatically turns off the five-second delay.
68-
let mut shell_loaded_image = boot_services
69-
.open_protocol_exclusive::<LoadedImage>(shell_image_handle)
63+
let mut shell_loaded_image = boot::open_protocol_exclusive::<LoadedImage>(shell_image_handle)
7064
.expect("failed to open LoadedImage protocol");
7165
let load_options = cstr16!(r"shell.efi test_runner.efi arg1 arg2");
7266
unsafe {
@@ -77,9 +71,9 @@ fn efi_main(image: Handle, mut st: SystemTable<Boot>) -> Status {
7771
}
7872

7973
info!("launching the shell app");
80-
boot_services
81-
.start_image(shell_image_handle)
82-
.expect("failed to launch the shell app");
74+
boot::start_image(shell_image_handle).expect("failed to launch the shell app");
8375

84-
Status::SUCCESS
76+
Ok(())
8577
}
78+
79+
uefi::set_main!(main);

‎uefi-test-runner/src/boot/memory.rs

+11-14
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
1-
use uefi::table::boot::{AllocateType, BootServices, MemoryType};
1+
use uefi::boot;
2+
use uefi::table::boot::{AllocateType, MemoryType};
23

34
use alloc::vec::Vec;
45

5-
pub fn test(bt: &BootServices) {
6+
pub fn test() {
67
info!("Testing memory functions");
78

8-
allocate_pages(bt);
9+
allocate_pages();
910
vec_alloc();
1011
alloc_alignment();
1112

12-
memory_map(bt);
13+
memory_map();
1314
}
1415

15-
fn allocate_pages(bt: &BootServices) {
16+
fn allocate_pages() {
1617
info!("Allocating some pages of memory");
1718

1819
let ty = AllocateType::AnyPages;
1920
let mem_ty = MemoryType::LOADER_DATA;
20-
let pgs = bt
21-
.allocate_pages(ty, mem_ty, 1)
22-
.expect("Failed to allocate a page of memory");
21+
let pgs = boot::allocate_pages(ty, mem_ty, 1).expect("Failed to allocate a page of memory");
2322

2423
assert_eq!(pgs % 4096, 0, "Page pointer is not page-aligned");
2524

@@ -31,7 +30,7 @@ fn allocate_pages(bt: &BootServices) {
3130
buf[4095] = 0x23;
3231

3332
// Clean up to avoid memory leaks.
34-
unsafe { bt.free_pages(pgs, 1) }.unwrap();
33+
unsafe { boot::free_pages(pgs, 1) }.unwrap();
3534
}
3635

3736
// Simple test to ensure our custom allocator works with the `alloc` crate.
@@ -60,21 +59,19 @@ fn alloc_alignment() {
6059
assert_eq!(value.as_ptr() as usize % 0x100, 0, "Wrong alignment");
6160
}
6261

63-
fn memory_map(bt: &BootServices) {
62+
fn memory_map() {
6463
info!("Testing memory map functions");
6564

6665
// Get the memory descriptor size and an estimate of the memory map size
67-
let sizes = bt.memory_map_size();
66+
let sizes = boot::memory_map_size();
6867

6968
// 2 extra descriptors should be enough.
7069
let buf_sz = sizes.map_size + 2 * sizes.entry_size;
7170

7271
// We will use vectors for convenience.
7372
let mut buffer = vec![0_u8; buf_sz];
7473

75-
let mut memory_map = bt
76-
.memory_map(&mut buffer)
77-
.expect("Failed to retrieve UEFI memory map");
74+
let mut memory_map = boot::memory_map(&mut buffer).expect("Failed to retrieve UEFI memory map");
7875

7976
memory_map.sort();
8077

‎uefi-test-runner/src/boot/misc.rs

+66-77
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,49 @@ use core::ptr::{self, NonNull};
44
use core::mem;
55
use uefi::proto::unsafe_protocol;
66
use uefi::table::boot::{
7-
BootServices, EventType, MemoryType, OpenProtocolAttributes, OpenProtocolParams, SearchType,
8-
TimerTrigger, Tpl,
7+
EventType, MemoryType, OpenProtocolAttributes, OpenProtocolParams, SearchType, TimerTrigger,
8+
Tpl,
99
};
10-
use uefi::table::{Boot, SystemTable};
10+
use uefi::{boot, system};
1111
use uefi::{guid, Event, Guid, Identify};
1212

13-
pub fn test(st: &SystemTable<Boot>) {
14-
let bt = st.boot_services();
13+
pub fn test() {
1514
info!("Testing timer...");
16-
test_timer(bt);
15+
test_timer();
1716
info!("Testing events...");
18-
test_event_callback(bt);
19-
test_callback_with_ctx(bt);
17+
test_event_callback();
18+
test_callback_with_ctx();
2019
info!("Testing watchdog...");
21-
test_watchdog(bt);
20+
test_watchdog();
2221
info!("Testing protocol handler services...");
23-
test_register_protocol_notify(bt);
24-
test_install_protocol_interface(bt);
25-
test_reinstall_protocol_interface(bt);
26-
test_uninstall_protocol_interface(bt);
27-
test_install_configuration_table(st);
22+
test_register_protocol_notify();
23+
test_install_protocol_interface();
24+
test_reinstall_protocol_interface();
25+
test_uninstall_protocol_interface();
26+
test_install_configuration_table();
2827
}
2928

30-
fn test_timer(bt: &BootServices) {
31-
let timer_event = unsafe { bt.create_event(EventType::TIMER, Tpl::APPLICATION, None, None) }
29+
fn test_timer() {
30+
let timer_event = unsafe { boot::create_event(EventType::TIMER, Tpl::APPLICATION, None, None) }
3231
.expect("Failed to create TIMER event");
3332
let mut events = unsafe { [timer_event.unsafe_clone()] };
34-
bt.set_timer(&timer_event, TimerTrigger::Relative(5_0 /*00 ns */))
33+
boot::set_timer(&timer_event, TimerTrigger::Relative(5_0 /*00 ns */))
3534
.expect("Failed to set timer");
36-
bt.wait_for_event(&mut events)
37-
.expect("Wait for event failed");
35+
boot::wait_for_event(&mut events).expect("Wait for event failed");
3836
}
3937

40-
fn test_event_callback(bt: &BootServices) {
38+
fn test_event_callback() {
4139
extern "efiapi" fn callback(_event: Event, _ctx: Option<NonNull<c_void>>) {
4240
info!("Inside the event callback");
4341
}
4442

4543
let event =
46-
unsafe { bt.create_event(EventType::NOTIFY_WAIT, Tpl::CALLBACK, Some(callback), None) }
44+
unsafe { boot::create_event(EventType::NOTIFY_WAIT, Tpl::CALLBACK, Some(callback), None) }
4745
.expect("Failed to create custom event");
48-
bt.check_event(event).expect("Failed to check event");
46+
boot::check_event(event).expect("Failed to check event");
4947
}
5048

51-
fn test_callback_with_ctx(bt: &BootServices) {
49+
fn test_callback_with_ctx() {
5250
let mut data = 123u32;
5351

5452
extern "efiapi" fn callback(_event: Event, ctx: Option<NonNull<c_void>>) {
@@ -65,7 +63,7 @@ fn test_callback_with_ctx(bt: &BootServices) {
6563
let ctx = NonNull::new(ctx.cast::<c_void>()).unwrap();
6664

6765
let event = unsafe {
68-
bt.create_event(
66+
boot::create_event(
6967
EventType::NOTIFY_WAIT,
7068
Tpl::CALLBACK,
7169
Some(callback),
@@ -74,16 +72,15 @@ fn test_callback_with_ctx(bt: &BootServices) {
7472
.expect("Failed to create event with context")
7573
};
7674

77-
bt.check_event(event).expect("Failed to check event");
75+
boot::check_event(event).expect("Failed to check event");
7876

7977
// Check that `data` was updated inside the event callback.
8078
assert_eq!(data, 456);
8179
}
8280

83-
fn test_watchdog(bt: &BootServices) {
81+
fn test_watchdog() {
8482
// Disable the UEFI watchdog timer
85-
bt.set_watchdog_timer(0, 0x10000, None)
86-
.expect("Could not set watchdog timer");
83+
boot::set_watchdog_timer(0, 0x10000, None).expect("Could not set watchdog timer");
8784
}
8885

8986
/// Dummy protocol for tests
@@ -96,10 +93,10 @@ unsafe extern "efiapi" fn _test_notify(_event: Event, _context: Option<NonNull<c
9693
info!("Protocol was (re)installed and this function notified.")
9794
}
9895

99-
fn test_register_protocol_notify(bt: &BootServices) {
96+
fn test_register_protocol_notify() {
10097
let protocol = &TestProtocol::GUID;
10198
let event = unsafe {
102-
bt.create_event(
99+
boot::create_event(
103100
EventType::NOTIFY_SIGNAL,
104101
Tpl::NOTIFY,
105102
Some(_test_notify),
@@ -108,40 +105,36 @@ fn test_register_protocol_notify(bt: &BootServices) {
108105
.expect("Failed to create an event")
109106
};
110107

111-
bt.register_protocol_notify(protocol, event)
112-
.expect("Failed to register protocol notify fn");
108+
boot::register_protocol_notify(protocol, event).expect("Failed to register protocol notify fn");
113109
}
114110

115-
fn test_install_protocol_interface(bt: &BootServices) {
111+
fn test_install_protocol_interface() {
116112
info!("Installing TestProtocol");
117113

118-
let alloc: *mut TestProtocol = bt
119-
.allocate_pool(
120-
MemoryType::BOOT_SERVICES_DATA,
121-
mem::size_of::<TestProtocol>(),
122-
)
123-
.unwrap()
124-
.cast();
114+
let alloc: *mut TestProtocol = boot::allocate_pool(
115+
MemoryType::BOOT_SERVICES_DATA,
116+
mem::size_of::<TestProtocol>(),
117+
)
118+
.unwrap()
119+
.cast();
125120
unsafe { alloc.write(TestProtocol { data: 123 }) };
126121

127122
let _ = unsafe {
128-
bt.install_protocol_interface(None, &TestProtocol::GUID, alloc.cast())
123+
boot::install_protocol_interface(None, &TestProtocol::GUID, alloc.cast())
129124
.expect("Failed to install protocol interface")
130125
};
131126

132-
let _ = bt
133-
.locate_handle_buffer(SearchType::from_proto::<TestProtocol>())
127+
let _ = boot::locate_handle_buffer(SearchType::from_proto::<TestProtocol>())
134128
.expect("Failed to find protocol after it was installed");
135129
}
136130

137-
fn test_reinstall_protocol_interface(bt: &BootServices) {
131+
fn test_reinstall_protocol_interface() {
138132
info!("Reinstalling TestProtocol");
139-
let handle = bt
140-
.locate_handle_buffer(SearchType::from_proto::<TestProtocol>())
133+
let handle = boot::locate_handle_buffer(SearchType::from_proto::<TestProtocol>())
141134
.expect("Failed to find protocol to uninstall")[0];
142135

143136
unsafe {
144-
let _ = bt.reinstall_protocol_interface(
137+
let _ = boot::reinstall_protocol_interface(
145138
handle,
146139
&TestProtocol::GUID,
147140
ptr::null_mut(),
@@ -150,60 +143,56 @@ fn test_reinstall_protocol_interface(bt: &BootServices) {
150143
}
151144
}
152145

153-
fn test_uninstall_protocol_interface(bt: &BootServices) {
146+
fn test_uninstall_protocol_interface() {
154147
info!("Uninstalling TestProtocol");
155148

156-
let handle = bt
157-
.locate_handle_buffer(SearchType::from_proto::<TestProtocol>())
149+
let handle = boot::locate_handle_buffer(SearchType::from_proto::<TestProtocol>())
158150
.expect("Failed to find protocol to uninstall")[0];
159151

160152
unsafe {
161153
// Uninstalling a protocol interface requires knowing the interface
162154
// pointer. Open the protocol to get that pointer, making sure to drop
163155
// the `ScopedProtocol` _before_ uninstalling the protocol interface.
164156
let interface_ptr: *mut TestProtocol = {
165-
let mut sp = bt
166-
.open_protocol::<TestProtocol>(
167-
OpenProtocolParams {
168-
handle,
169-
agent: bt.image_handle(),
170-
controller: None,
171-
},
172-
OpenProtocolAttributes::GetProtocol,
173-
)
174-
.unwrap();
157+
let mut sp = boot::open_protocol::<TestProtocol>(
158+
OpenProtocolParams {
159+
handle,
160+
agent: boot::image_handle(),
161+
controller: None,
162+
},
163+
OpenProtocolAttributes::GetProtocol,
164+
)
165+
.unwrap();
175166
assert_eq!(sp.data, 123);
176167
&mut *sp
177168
};
178169

179-
bt.uninstall_protocol_interface(handle, &TestProtocol::GUID, interface_ptr.cast())
170+
boot::uninstall_protocol_interface(handle, &TestProtocol::GUID, interface_ptr.cast())
180171
.expect("Failed to uninstall protocol interface");
181172

182-
bt.free_pool(interface_ptr.cast()).unwrap();
173+
boot::free_pool(interface_ptr.cast()).unwrap();
183174
}
184175
}
185176

186-
fn test_install_configuration_table(st: &SystemTable<Boot>) {
187-
let config = st
188-
.boot_services()
189-
.allocate_pool(MemoryType::ACPI_RECLAIM, 1)
190-
.expect("Failed to allocate config table");
177+
fn test_install_configuration_table() {
178+
let config =
179+
boot::allocate_pool(MemoryType::ACPI_RECLAIM, 1).expect("Failed to allocate config table");
191180
unsafe { config.write(42) };
192181

193-
let count = st.config_table().len();
182+
let count = system::with_config_table(|t| t.len());
194183
const ID: Guid = guid!("3bdb3089-5662-42df-840e-3922ed6467c9");
195184

196185
unsafe {
197-
st.boot_services()
198-
.install_configuration_table(&ID, config.cast())
186+
boot::install_configuration_table(&ID, config.cast())
199187
.expect("Failed to install configuration table");
200188
}
201189

202-
assert_eq!(count + 1, st.config_table().len());
203-
let config_entry = st
204-
.config_table()
205-
.iter()
206-
.find(|ct| ct.guid == ID)
207-
.expect("Failed to find test config table");
208-
assert_eq!(unsafe { *(config_entry.address as *const u8) }, 42);
190+
assert_eq!(count + 1, system::with_config_table(|t| t.len()));
191+
let entry_addr = system::with_config_table(|t| {
192+
t.iter()
193+
.find(|ct| ct.guid == ID)
194+
.expect("Failed to find test config table")
195+
.address
196+
});
197+
assert_eq!(unsafe { *(entry_addr as *const u8) }, 42);
209198
}

‎uefi-test-runner/src/boot/mod.rs

+14-15
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,33 @@ use uefi::fs::FileSystem;
33
use uefi::proto::console::text::Output;
44
use uefi::proto::device_path::media::FilePath;
55
use uefi::proto::device_path::{DevicePath, LoadedImageDevicePath};
6-
use uefi::table::boot::{BootServices, LoadImageSource, SearchType};
7-
use uefi::table::{Boot, SystemTable};
8-
use uefi::{CString16, Identify};
6+
use uefi::table::boot::{LoadImageSource, SearchType};
7+
use uefi::{boot, system, CString16, Identify};
98

109
mod memory;
1110
mod misc;
1211

13-
pub fn test(st: &SystemTable<Boot>) {
14-
let bt = st.boot_services();
12+
pub fn test() {
1513
info!("Testing boot services");
16-
memory::test(bt);
17-
misc::test(st);
18-
test_locate_handle_buffer(bt);
19-
test_load_image(bt);
14+
memory::test();
15+
misc::test();
16+
test_locate_handle_buffer();
17+
test_load_image();
2018
}
2119

22-
fn test_locate_handle_buffer(bt: &BootServices) {
20+
fn test_locate_handle_buffer() {
2321
info!("Testing the `locate_handle_buffer` function");
2422

2523
{
2624
// search all handles
27-
let handles = bt
28-
.locate_handle_buffer(SearchType::AllHandles)
25+
let handles = boot::locate_handle_buffer(SearchType::AllHandles)
2926
.expect("Failed to locate handle buffer");
3027
assert!(!handles.is_empty(), "Could not find any handles");
3128
}
3229

3330
{
3431
// search by protocol
35-
let handles = bt
36-
.locate_handle_buffer(SearchType::ByProtocol(&Output::GUID))
32+
let handles = boot::locate_handle_buffer(SearchType::ByProtocol(&Output::GUID))
3733
.expect("Failed to locate handle buffer");
3834
assert!(
3935
!handles.is_empty(),
@@ -47,7 +43,10 @@ fn test_locate_handle_buffer(bt: &BootServices) {
4743
///
4844
/// It transitively tests the protocol [`LoadedImageDevicePath`] which is
4945
/// required as helper.
50-
fn test_load_image(bt: &BootServices) {
46+
fn test_load_image() {
47+
let st = system::system_table_boot();
48+
let bt = st.boot_services();
49+
5150
/// The path of the loaded image executing this integration test.
5251
const LOADED_IMAGE_PATH: &str = r"\EFI\BOOT\TEST_RUNNER.EFI";
5352

‎uefi-test-runner/src/main.rs

+24-32
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@ use uefi::proto::console::serial::Serial;
1313
use uefi::proto::device_path::build::{self, DevicePathBuilder};
1414
use uefi::proto::device_path::messaging::Vendor;
1515
use uefi::table::boot::MemoryType;
16-
use uefi::Result;
17-
use uefi::{print, println};
16+
use uefi::{print, println, system, Result};
1817

1918
mod boot;
2019
mod fs;
2120
mod proto;
2221
mod runtime;
2322

24-
#[entry]
25-
fn efi_main(image: Handle, mut st: SystemTable<Boot>) -> Status {
23+
uefi::set_main!(main);
24+
25+
fn main() -> Result {
2626
// Initialize utilities (logging, memory allocation...)
27-
uefi::helpers::init(&mut st).expect("Failed to initialize utilities");
27+
uefi::helpers::init_v2().expect("Failed to initialize utilities");
2828

2929
// unit tests here
3030

31-
let firmware_vendor = st.firmware_vendor();
31+
let firmware_vendor = system::firmware_vendor();
3232
info!("Firmware Vendor: {}", firmware_vendor);
3333
assert_eq!(firmware_vendor.to_string(), "EDK II");
3434

@@ -41,30 +41,29 @@ fn efi_main(image: Handle, mut st: SystemTable<Boot>) -> Status {
4141
);
4242

4343
// Reset the console before running all the other tests.
44-
st.stdout().reset(false).expect("Failed to reset stdout");
44+
system::with_stdout(|stdout| stdout.reset(false).expect("Failed to reset stdout"));
4545

4646
// Ensure the tests are run on a version of UEFI we support.
47-
check_revision(st.uefi_revision());
48-
49-
// Test all the boot services.
50-
let bt = st.boot_services();
47+
check_revision(system::uefi_revision());
5148

5249
// Try retrieving a handle to the file system the image was booted from.
53-
bt.get_image_file_system(image)
50+
uefi::boot::get_image_file_system(uefi::boot::image_handle())
5451
.expect("Failed to retrieve boot file system");
5552

56-
boot::test(&st);
53+
boot::test();
54+
55+
let mut st = system::system_table_boot();
5756

5857
// Test all the supported protocols.
59-
proto::test(image, &mut st);
58+
proto::test(st.boot_services().image_handle(), &mut st);
6059

6160
// TODO: runtime services work before boot services are exited, but we'd
6261
// probably want to test them after exit_boot_services. However,
6362
// exit_boot_services is currently called during shutdown.
6463

6564
runtime::test(st.runtime_services());
6665

67-
shutdown(st);
66+
shutdown(system::system_table_boot());
6867
}
6968

7069
fn check_revision(rev: uefi::table::Revision) {
@@ -120,7 +119,7 @@ fn send_request_helper(serial: &mut Serial, request: HostRequest) -> Result {
120119
/// This must be called after opening the serial protocol in exclusive mode, as
121120
/// that breaks the connection to the console, which in turn prevents logs from
122121
/// getting to the host.
123-
fn reconnect_serial_to_console(boot_services: &BootServices, serial_handle: Handle) {
122+
fn reconnect_serial_to_console(serial_handle: Handle) {
124123
let mut storage = Vec::new();
125124
// Create a device path that specifies the terminal type.
126125
let terminal_guid = if cfg!(target_arch = "aarch64") {
@@ -137,18 +136,16 @@ fn reconnect_serial_to_console(boot_services: &BootServices, serial_handle: Hand
137136
.finalize()
138137
.unwrap();
139138

140-
boot_services
141-
.connect_controller(serial_handle, None, Some(terminal_device_path), true)
139+
uefi::boot::connect_controller(serial_handle, None, Some(terminal_device_path), true)
142140
.expect("failed to reconnect serial to console");
143141
}
144142

145143
/// Send the `request` string to the host via the `serial` device, then
146144
/// wait up to 10 seconds to receive a reply. Returns an error if the
147145
/// reply is not `"OK\n"`.
148-
fn send_request_to_host(bt: &BootServices, request: HostRequest) {
149-
let serial_handle = bt
150-
.get_handle_for_protocol::<Serial>()
151-
.expect("Failed to get serial handle");
146+
fn send_request_to_host(request: HostRequest) {
147+
let serial_handle =
148+
uefi::boot::get_handle_for_protocol::<Serial>().expect("Failed to get serial handle");
152149

153150
// Open the serial protocol in exclusive mode.
154151
//
@@ -161,8 +158,7 @@ fn send_request_to_host(bt: &BootServices, request: HostRequest) {
161158
// end with `connect_controller`.
162159
//
163160
// [console splitter driver]: https://github.com/tianocore/edk2/blob/HEAD/MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.c
164-
let mut serial = bt
165-
.open_protocol_exclusive::<Serial>(serial_handle)
161+
let mut serial = uefi::boot::open_protocol_exclusive::<Serial>(serial_handle)
166162
.expect("Could not open serial protocol");
167163

168164
// 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) {
175171
// device, which was broken when we opened the protocol in exclusive
176172
// mode above.
177173
drop(serial);
178-
reconnect_serial_to_console(bt, serial_handle);
174+
reconnect_serial_to_console(serial_handle);
179175

180176
if let Err(err) = res {
181177
panic!("request failed: \"{request:?}\": {:?}", err.status());
@@ -189,7 +185,7 @@ fn shutdown(mut st: SystemTable<Boot>) -> ! {
189185
// Tell the host that tests are done. We are about to exit boot
190186
// services, so we can't easily communicate with the host any later
191187
// than this.
192-
send_request_to_host(st.boot_services(), HostRequest::TestsComplete);
188+
send_request_to_host(HostRequest::TestsComplete);
193189

194190
// Send a special log to the host so that we can verify that logging works
195191
// up until exiting boot services. See `reconnect_serial_to_console` for the
@@ -199,13 +195,10 @@ fn shutdown(mut st: SystemTable<Boot>) -> ! {
199195
info!("Testing complete, shutting down...");
200196

201197
// Exit boot services as a proof that it works :)
202-
let (st, _iter) = st.exit_boot_services(MemoryType::LOADER_DATA);
198+
let _iter = uefi::boot::exit_boot_services(MemoryType::LOADER_DATA);
203199

204200
#[cfg(target_arch = "x86_64")]
205201
{
206-
// Prevent unused variable warning.
207-
let _ = st;
208-
209202
use qemu_exit::QEMUExit;
210203
let custom_exit_success = 3;
211204
let qemu_exit_handle = qemu_exit::X86::new(0xF4, custom_exit_success);
@@ -215,8 +208,7 @@ fn shutdown(mut st: SystemTable<Boot>) -> ! {
215208
#[cfg(not(target_arch = "x86_64"))]
216209
{
217210
// Shut down the system
218-
let rt = unsafe { st.runtime_services() };
219-
rt.reset(
211+
uefi::runtime::reset(
220212
uefi::table::runtime::ResetType::SHUTDOWN,
221213
Status::SUCCESS,
222214
None,

‎uefi-test-runner/src/proto/console/gop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub unsafe fn test(image: Handle, bt: &BootServices) {
2828

2929
// `draw_fb` is skipped on aarch64, so the screenshot doesn't match.
3030
if cfg!(not(target_arch = "aarch64")) {
31-
send_request_to_host(bt, HostRequest::Screenshot("gop_test"));
31+
send_request_to_host(HostRequest::Screenshot("gop_test"));
3232
}
3333
}
3434

‎uefi-test-runner/src/proto/console/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
use uefi::prelude::*;
2+
use uefi::system;
23

34
pub fn test(image: Handle, st: &mut SystemTable<Boot>) {
45
info!("Testing console protocols");
56

6-
stdout::test(st.stdout());
7+
system::with_stdout(stdout::test);
78

89
let bt = st.boot_services();
910
unsafe {
10-
serial::test(bt);
11+
serial::test();
1112
gop::test(image, bt);
1213
}
1314
pointer::test(bt);

‎uefi-test-runner/src/proto/console/serial.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::reconnect_serial_to_console;
22
use uefi::proto::console::serial::{ControlBits, Serial};
3-
use uefi::table::boot::BootServices;
4-
use uefi::{Result, ResultExt, Status};
3+
use uefi::{boot, Result, ResultExt, Status};
54

65
// For the duration of this function, the serial device is opened in
76
// exclusive mode. That means logs will not work, which means we should
@@ -41,21 +40,18 @@ fn serial_test_helper(serial: &mut Serial) -> Result {
4140
}
4241
}
4342

44-
pub unsafe fn test(bt: &BootServices) {
43+
pub unsafe fn test() {
4544
// The serial device under aarch64 doesn't support the software
4645
// loopback feature needed for this test.
4746
if cfg!(target_arch = "aarch64") {
4847
return;
4948
}
5049

5150
info!("Running serial protocol test");
52-
let handle = bt
53-
.get_handle_for_protocol::<Serial>()
54-
.expect("missing Serial protocol");
51+
let handle = boot::get_handle_for_protocol::<Serial>().expect("missing Serial protocol");
5552

56-
let mut serial = bt
57-
.open_protocol_exclusive::<Serial>(handle)
58-
.expect("failed to open serial protocol");
53+
let mut serial =
54+
boot::open_protocol_exclusive::<Serial>(handle).expect("failed to open serial protocol");
5955

6056
// Send the request, but don't check the result yet so that first
6157
// we can reconnect the console output for the logger.
@@ -67,7 +63,7 @@ pub unsafe fn test(bt: &BootServices) {
6763
// device, which was broken when we opened the protocol in exclusive
6864
// mode above.
6965
drop(serial);
70-
reconnect_serial_to_console(bt, handle);
66+
reconnect_serial_to_console(handle);
7167

7268
if let Err(err) = res {
7369
panic!("serial test failed: {:?}", err.status());

‎uefi-test-runner/src/proto/device_path.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use alloc::string::ToString;
22
use alloc::vec::Vec;
3+
use uefi::boot;
34
use uefi::prelude::*;
45
use uefi::proto::device_path::text::*;
56
use uefi::proto::device_path::{DevicePath, LoadedImageDevicePath};
@@ -68,9 +69,9 @@ pub fn test(image: Handle, bt: &BootServices) {
6869

6970
// test 2/2: test high-level to-string api
7071
{
71-
let loaded_image_device_path = bt
72-
.open_protocol_exclusive::<LoadedImageDevicePath>(image)
73-
.expect("Failed to open LoadedImageDevicePath protocol");
72+
let loaded_image_device_path =
73+
boot::open_protocol_exclusive::<LoadedImageDevicePath>(image)
74+
.expect("Failed to open LoadedImageDevicePath protocol");
7475
let device_path: &DevicePath = &loaded_image_device_path;
7576

7677
let path_components = device_path

0 commit comments

Comments
 (0)
Please sign in to comment.