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,28 @@ 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 can be used
24
+ if !simple_network. mode ( ) . media_present_supported || !simple_network. mode ( ) . media_present {
25
+ continue ;
26
+ }
26
27
27
- // Check start
28
28
simple_network
29
29
. start ( )
30
- . expect ( "Failed to start Simple Network " ) ;
30
+ . expect ( "Network should not be started yet " ) ;
31
31
32
- // Check initialize
33
32
simple_network
34
33
. initialize ( 0 , 0 )
35
- . expect ( "Failed to initialize Simple Network " ) ;
34
+ . expect ( "Network should not be initialized yet " ) ;
36
35
37
36
// edk2 virtio-net driver does not support statistics, so
38
37
// allow UNSUPPORTED (same for collect_statistics below).
@@ -52,11 +51,6 @@ pub fn test() {
52
51
)
53
52
. expect ( "Failed to set receive filters" ) ;
54
53
55
- // Check media
56
- if !simple_network. mode ( ) . media_present_supported || !simple_network. mode ( ) . media_present {
57
- continue ;
58
- }
59
-
60
54
let payload = b"\0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \
61
55
\x45 \x00 \
62
56
\x00 \x21 \
@@ -131,5 +125,7 @@ pub fn test() {
131
125
}
132
126
}
133
127
}
128
+
129
+ simple_network. shutdown ( ) . unwrap ( ) ;
134
130
}
135
131
}
0 commit comments