Skip to content

Commit aa6d4b2

Browse files
committed
[test] expect test. Drop the Option so that the caller is forced to provide a valid input.
1 parent a067526 commit aa6d4b2

File tree

3 files changed

+37
-53
lines changed

3 files changed

+37
-53
lines changed

uefi-raw/src/protocol/misc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ pub struct TimestampProperties {
2929
#[repr(C)]
3030
pub struct ResetNotificationProtocol {
3131
pub register_reset_notify:
32-
unsafe extern "efiapi" fn(this: *mut Self, reset_function: Option<ResetSystemFn>) -> Status,
32+
unsafe extern "efiapi" fn(this: *mut Self, reset_function: ResetSystemFn) -> Status,
3333
pub unregister_reset_notify:
34-
unsafe extern "efiapi" fn(this: *mut Self, reset_function: Option<ResetSystemFn>) -> Status,
34+
unsafe extern "efiapi" fn(this: *mut Self, reset_function: ResetSystemFn) -> Status,
3535
}
3636

3737
impl ResetNotificationProtocol {
3838
pub const GUID: Guid = guid!("9da34ae0-eaf9-4bbf-8ec3-fd60226c44be");
3939
}
4040

41-
/// Raw reset notification function, to be called if you register it when a RestSystem() is executed.
41+
/// Raw reset notification function, to be called if you register it when a ResetSystem() is executed.
4242
pub type ResetSystemFn = unsafe extern "efiapi" fn(
4343
rt: runtime::ResetType,
4444
status: Status,

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

Lines changed: 31 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,52 +9,36 @@ pub fn test(bt: &BootServices) {
99
pub fn test_reset_notification(bt: &BootServices) {
1010
info!("Running loaded ResetNotification protocol test");
1111

12-
let handle = bt.get_handle_for_protocol::<ResetNotification>();
13-
14-
match handle {
15-
Ok(handle) => {
16-
let mut reset_notif_proto = bt
17-
.open_protocol_exclusive::<ResetNotification>(handle)
18-
.expect("Founded ResetNotification Protocol but open failed");
19-
let result = reset_notif_proto.register_reset_notify(None);
20-
info!(
21-
"ResetNotification Protocol register null test: {:?}",
22-
result
23-
);
24-
25-
let result = reset_notif_proto.unregister_reset_notify(None);
26-
info!(
27-
"ResetNotification Protocol unregister null test: {:?}",
28-
result
29-
);
30-
31-
// value efi_reset_fn is the type of ResetSystemFn, a function pointer
32-
unsafe extern "efiapi" fn efi_reset_fn(
33-
rt: runtime::ResetType,
34-
status: Status,
35-
data_size: usize,
36-
data: *const u8,
37-
) {
38-
info!("Inside the event callback, hi, efi_reset_fn");
39-
info!("rt: {:?} status: {:?}", rt, status);
40-
info!("size: {:?} data: {:?}", data_size, data);
41-
// do what you want
42-
}
43-
44-
let result = reset_notif_proto.register_reset_notify(Some(efi_reset_fn));
45-
info!(
46-
"ResetNotification Protocol register efi_reset_fn test: {:?}",
47-
result
48-
);
49-
50-
let result = reset_notif_proto.unregister_reset_notify(Some(efi_reset_fn));
51-
info!(
52-
"ResetNotification Protocol unregister efi_reset_fn test: {:?}",
53-
result
54-
);
55-
}
56-
Err(err) => {
57-
warn!("Failed to found ResetNotification Protocol: {:?}", err);
58-
}
12+
let handle = bt
13+
.get_handle_for_protocol::<ResetNotification>()
14+
.expect("Failed to get handles for `ResetNotification` protocol");
15+
16+
let mut reset_notif_proto = bt
17+
.open_protocol_exclusive::<ResetNotification>(handle)
18+
.expect("Founded ResetNotification Protocol but open failed");
19+
20+
// value efi_reset_fn is the type of ResetSystemFn, a function pointer
21+
unsafe extern "efiapi" fn efi_reset_fn(
22+
rt: runtime::ResetType,
23+
status: Status,
24+
data_size: usize,
25+
data: *const u8,
26+
) {
27+
info!("Inside the event callback, hi, efi_reset_fn");
28+
info!("rt: {:?} status: {:?}", rt, status);
29+
info!("size: {:?} data: {:?}", data_size, data);
30+
// do what you want
5931
}
32+
33+
let result = reset_notif_proto.register_reset_notify(efi_reset_fn);
34+
info!(
35+
"ResetNotification Protocol register efi_reset_fn test: {:?}",
36+
result
37+
);
38+
39+
let result = reset_notif_proto.unregister_reset_notify(efi_reset_fn);
40+
info!(
41+
"ResetNotification Protocol unregister efi_reset_fn test: {:?}",
42+
result
43+
);
6044
}

uefi/src/proto/misc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,16 @@ impl ResetNotification {
6868
/// .open_protocol_exclusive::<ResetNotification>(image)
6969
/// .expect("Failed to open Timestamp protocol");
7070
///
71-
/// rn.register_reset_notify(Some(efi_reset_fn))
71+
/// rn.register_reset_notify(efi_reset_fn)
7272
/// .expect("Failed to register a reset notification function!");
7373
/// }
7474
/// ```
75-
pub fn register_reset_notify(&mut self, reset_function: Option<ResetSystemFn>) -> Result {
75+
pub fn register_reset_notify(&mut self, reset_function: ResetSystemFn) -> Result {
7676
unsafe { (self.0.register_reset_notify)(&mut self.0, reset_function) }.to_result()
7777
}
7878

7979
/// Remove a reset notification function that was previously registered with [`ResetNotification::register_reset_notify`].
80-
pub fn unregister_reset_notify(&mut self, reset_function: Option<ResetSystemFn>) -> Result {
80+
pub fn unregister_reset_notify(&mut self, reset_function: ResetSystemFn) -> Result {
8181
unsafe { (self.0.unregister_reset_notify)(&mut self.0, reset_function) }.to_result()
8282
}
8383
}

0 commit comments

Comments
 (0)