3
3
use core::time::Duration;
4
4
5
5
use uefi::proto::network::MacAddress;
6
- use uefi::proto::network::snp::{InterruptStatus, ReceiveFlags, SimpleNetwork};
6
+ use uefi::proto::network::snp::{InterruptStatus, NetworkState, ReceiveFlags, SimpleNetwork};
7
7
use uefi::{Status, boot};
8
8
9
9
pub fn test() {
@@ -12,29 +12,30 @@ pub fn test() {
12
12
let handles = boot::find_handles::<SimpleNetwork>().unwrap_or_default();
13
13
14
14
for handle in handles {
15
- let simple_network = boot::open_protocol_exclusive::<SimpleNetwork>(handle);
16
- if simple_network.is_err() {
15
+ let Ok(simple_network) = boot::open_protocol_exclusive::<SimpleNetwork>(handle) else {
17
16
continue;
18
- }
19
- let simple_network = simple_network.unwrap();
17
+ };
20
18
21
- // Check shutdown
22
- let res = simple_network.shutdown();
23
- assert!(res == Ok(()) || res == Err(Status::NOT_STARTED.into()));
19
+ assert_eq!(
20
+ simple_network.mode().state,
21
+ NetworkState::STOPPED,
22
+ "Should be in stopped state"
23
+ );
24
24
25
- // Check stop
26
- let res = simple_network.stop();
27
- assert!(res == Ok(()) || res == Err(Status::NOT_STARTED.into()));
25
+ // Check media
26
+ if !bool::from(simple_network.mode().media_present_supported)
27
+ || !bool::from(simple_network.mode().media_present)
28
+ {
29
+ continue;
30
+ }
28
31
29
- // Check start
30
32
simple_network
31
33
.start()
32
- .expect("Failed to start Simple Network ");
34
+ .expect("Network should not be started yet ");
33
35
34
- // Check initialize
35
36
simple_network
36
37
.initialize(0, 0)
37
- .expect("Failed to initialize Simple Network ");
38
+ .expect("Network should not be initialized yet ");
38
39
39
40
// edk2 virtio-net driver does not support statistics, so
40
41
// allow UNSUPPORTED (same for collect_statistics below).
@@ -54,13 +55,6 @@ pub fn test() {
54
55
)
55
56
.expect("Failed to set receive filters");
56
57
57
- // Check media
58
- if !bool::from(simple_network.mode().media_present_supported)
59
- || !bool::from(simple_network.mode().media_present)
60
- {
61
- continue;
62
- }
63
-
64
58
let payload = b"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\
65
59
\x45\x00\
66
60
\x00\x21\
@@ -137,5 +131,7 @@ pub fn test() {
137
131
}
138
132
}
139
133
}
134
+
135
+ simple_network.shutdown().unwrap();
140
136
}
141
137
}
0 commit comments