1
1
use core:: ffi:: c_void;
2
2
use core:: ptr:: NonNull ;
3
3
4
- use uefi:: table:: boot:: { BootServices , EventType , TimerTrigger , Tpl } ;
5
- use uefi:: Event ;
4
+ use uefi:: proto:: Protocol ;
5
+ use uefi:: table:: boot:: { BootServices , EventType , SearchType , TimerTrigger , Tpl } ;
6
+ use uefi:: { unsafe_guid, Event , Identify } ;
6
7
7
8
pub fn test ( bt : & BootServices ) {
8
9
info ! ( "Testing timer..." ) ;
@@ -12,6 +13,11 @@ pub fn test(bt: &BootServices) {
12
13
test_callback_with_ctx ( bt) ;
13
14
info ! ( "Testing watchdog..." ) ;
14
15
test_watchdog ( bt) ;
16
+ info ! ( "Testing protocol handler services..." ) ;
17
+ test_register_protocol_notify ( bt) ;
18
+ test_install_protocol_interface ( bt) ;
19
+ test_reinstall_protocol_interface ( bt) ;
20
+ test_uninstall_protocol_interface ( bt) ;
15
21
}
16
22
17
23
fn test_timer ( bt : & BootServices ) {
@@ -72,3 +78,66 @@ fn test_watchdog(bt: &BootServices) {
72
78
bt. set_watchdog_timer ( 0 , 0x10000 , None )
73
79
. expect ( "Could not set watchdog timer" ) ;
74
80
}
81
+
82
+ /// Dummy protocol for tests
83
+ #[ unsafe_guid( "1a972918-3f69-4b5d-8cb4-cece2309c7f5" ) ]
84
+ #[ derive( Protocol ) ]
85
+ struct TestProtocol { }
86
+
87
+ unsafe extern "efiapi" fn _test_notify ( _event : Event , _context : Option < NonNull < c_void > > ) {
88
+ info ! ( "Protocol was (re)installed and this function notified." )
89
+ }
90
+
91
+ fn test_register_protocol_notify ( bt : & BootServices ) {
92
+ let protocol = & TestProtocol :: GUID ;
93
+ let event = unsafe {
94
+ bt. create_event (
95
+ EventType :: NOTIFY_SIGNAL ,
96
+ Tpl :: NOTIFY ,
97
+ Some ( _test_notify) ,
98
+ None ,
99
+ )
100
+ . expect ( "Failed to create an event" )
101
+ } ;
102
+
103
+ bt. register_protocol_notify ( protocol, event)
104
+ . expect ( "Failed to register protocol notify fn" ) ;
105
+ }
106
+
107
+ fn test_install_protocol_interface ( bt : & BootServices ) {
108
+ info ! ( "Installing TestProtocol" ) ;
109
+
110
+ let _ = unsafe {
111
+ bt. install_protocol_interface ( None , & TestProtocol :: GUID , None )
112
+ . expect ( "Failed to install protocol interface" )
113
+ } ;
114
+
115
+ let _ = bt
116
+ . locate_handle_buffer ( SearchType :: from_proto :: < TestProtocol > ( ) )
117
+ . expect ( "Failed to find protocol after it was installed" ) ;
118
+ }
119
+
120
+ fn test_reinstall_protocol_interface ( bt : & BootServices ) {
121
+ info ! ( "Reinstalling TestProtocol" ) ;
122
+ let handle = bt
123
+ . locate_handle_buffer ( SearchType :: from_proto :: < TestProtocol > ( ) )
124
+ . expect ( "Failed to find protocol to uninstall" )
125
+ . handles ( ) [ 0 ] ;
126
+
127
+ unsafe {
128
+ let _ = bt. reinstall_protocol_interface ( handle, & TestProtocol :: GUID , None , None ) ;
129
+ }
130
+ }
131
+
132
+ fn test_uninstall_protocol_interface ( bt : & BootServices ) {
133
+ info ! ( "Uninstalling TestProtocol" ) ;
134
+ let handle = bt
135
+ . locate_handle_buffer ( SearchType :: from_proto :: < TestProtocol > ( ) )
136
+ . expect ( "Failed to find protocol to uninstall" )
137
+ . handles ( ) [ 0 ] ;
138
+
139
+ unsafe {
140
+ bt. uninstall_protocol_interface ( handle, & TestProtocol :: GUID , None )
141
+ . expect ( "Failed to uninstall protocol interface" ) ;
142
+ }
143
+ }
0 commit comments