@@ -76,10 +76,23 @@ fn check_revision(rev: uefi::table::Revision) {
76
76
) ;
77
77
}
78
78
79
- /// Send the `request` string to the host via the `serial` device, then
80
- /// wait up to 10 seconds to receive a reply. Returns an error if the
81
- /// reply is not `"OK\n"`.
82
- fn send_request_helper ( serial : & mut Serial , request : & str ) -> Result {
79
+ #[ derive( Clone , Copy , Debug ) ]
80
+ enum HostRequest {
81
+ /// Tell the host to take a screenshot and compare against the
82
+ /// golden image.
83
+ Screenshot ( & ' static str ) ,
84
+
85
+ /// Tell the host that tests are complete. The host will consider
86
+ /// the tests failed if this message is not received.
87
+ TestsComplete ,
88
+ }
89
+
90
+ fn send_request_helper ( serial : & mut Serial , request : HostRequest ) -> Result {
91
+ let request = match request {
92
+ HostRequest :: Screenshot ( name) => format ! ( "SCREENSHOT: {name}\n " ) ,
93
+ HostRequest :: TestsComplete => "TESTS_COMPLETE\n " . to_string ( ) ,
94
+ } ;
95
+
83
96
// Set a 10 second timeout for the read and write operations.
84
97
let mut io_mode = * serial. io_mode ( ) ;
85
98
io_mode. timeout = 10_000_000 ;
@@ -99,10 +112,10 @@ fn send_request_helper(serial: &mut Serial, request: &str) -> Result {
99
112
}
100
113
}
101
114
102
- /// Ask the test runner to check the current screen output against a reference.
103
- fn check_screenshot ( bt : & BootServices , name : & str ) {
104
- let request = format ! ( "SCREENSHOT: {name} \n ") ;
105
-
115
+ /// Send the `request` string to the host via the `serial` device, then
116
+ /// wait up to 10 seconds to receive a reply. Returns an error if the
117
+ /// reply is not `"OK \n"`.
118
+ fn send_request_to_host ( bt : & BootServices , request : HostRequest ) {
106
119
let serial_handle = bt
107
120
. get_handle_for_protocol :: < Serial > ( )
108
121
. expect ( "Failed to get serial handle" ) ;
@@ -124,7 +137,7 @@ fn check_screenshot(bt: &BootServices, name: &str) {
124
137
125
138
// Send the request, but don't check the result yet so that first
126
139
// we can reconnect the console output for the logger.
127
- let res = send_request_helper ( & mut serial, & request) ;
140
+ let res = send_request_helper ( & mut serial, request) ;
128
141
129
142
// Release the serial device and reconnect all controllers to the
130
143
// serial handle. This is necessary to restore the connection
@@ -135,11 +148,7 @@ fn check_screenshot(bt: &BootServices, name: &str) {
135
148
let _ = bt. connect_controller ( serial_handle, None , None , true ) ;
136
149
137
150
if let Err ( err) = res {
138
- panic ! (
139
- "request failed: \" {}\" : {:?}" ,
140
- request. trim_end( ) ,
141
- err. status( )
142
- ) ;
151
+ panic ! ( "request failed: \" {request:?}\" : {:?}" , err. status( ) ) ;
143
152
}
144
153
}
145
154
@@ -149,6 +158,11 @@ fn shutdown(image: uefi::Handle, mut st: SystemTable<Boot>) -> ! {
149
158
150
159
info ! ( "Testing complete, shutting down..." ) ;
151
160
161
+ // Tell the host that tests are done. We are about to exit boot
162
+ // services, so we can't easily communicate with the host any later
163
+ // than this.
164
+ send_request_to_host ( st. boot_services ( ) , HostRequest :: TestsComplete ) ;
165
+
152
166
// Exit boot services as a proof that it works :)
153
167
let sizes = st. boot_services ( ) . memory_map_size ( ) ;
154
168
let max_mmap_size = sizes. map_size + 2 * sizes. entry_size ;
0 commit comments