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