Skip to content

Commit e0af6b2

Browse files
nicholasbishopGabrielMajeri
authored andcommitted
Simplify event callback with context test
Rather than opening the Output protocol, which isn't important for this test, just write through the context pointer and assert that the expected data was written.
1 parent c6829e3 commit e0af6b2

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use core::ffi::c_void;
22
use core::ptr::NonNull;
33

4-
use uefi::proto::console::text::Output;
54
use uefi::table::boot::{BootServices, EventType, TimerTrigger, Tpl};
65
use uefi::Event;
76

@@ -37,28 +36,35 @@ fn test_event_callback(bt: &BootServices) {
3736
}
3837

3938
fn test_callback_with_ctx(bt: &BootServices) {
39+
let mut data = 123u32;
40+
4041
extern "efiapi" fn callback(_event: Event, ctx: Option<NonNull<c_void>>) {
4142
info!("Inside the event callback with context");
43+
// Safety: this callback is run within the parent function's
44+
// scope, so the context pointer is still valid.
4245
unsafe {
43-
let ctx = &mut *(ctx.unwrap().as_ptr() as *mut Output);
44-
// Clear the screen as a quick test that we successfully passed context
45-
ctx.clear().expect("Failed to clear screen");
46+
let ctx = ctx.unwrap().as_ptr().cast::<u32>();
47+
*ctx = 456;
4648
}
4749
}
4850

49-
let ctx = unsafe { &mut *(bt.locate_protocol::<Output>().unwrap().get()) };
51+
let ctx: *mut u32 = &mut data;
52+
let ctx = NonNull::new(ctx.cast::<c_void>()).unwrap();
5053

5154
let event = unsafe {
5255
bt.create_event(
5356
EventType::NOTIFY_WAIT,
5457
Tpl::CALLBACK,
5558
Some(callback),
56-
Some(NonNull::new_unchecked(ctx as *mut _ as *mut c_void)),
59+
Some(ctx),
5760
)
5861
.expect("Failed to create event with context")
5962
};
6063

6164
bt.check_event(event).expect("Failed to check event");
65+
66+
// Check that `data` was updated inside the event callback.
67+
assert_eq!(data, 456);
6268
}
6369

6470
fn test_watchdog(bt: &BootServices) {

0 commit comments

Comments
 (0)