33use core:: time:: Duration ;
44
55use uefi:: proto:: network:: MacAddress ;
6- use uefi:: proto:: network:: snp:: { InterruptStatus , ReceiveFlags , SimpleNetwork } ;
6+ use uefi:: proto:: network:: snp:: { InterruptStatus , NetworkState , ReceiveFlags , SimpleNetwork } ;
77use uefi:: { Status , boot} ;
88
99pub fn test ( ) {
@@ -12,29 +12,30 @@ pub fn test() {
1212 let handles = boot:: find_handles :: < SimpleNetwork > ( ) . unwrap_or_default ( ) ;
1313
1414 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 {
1716 continue ;
18- }
19- let simple_network = simple_network. unwrap ( ) ;
17+ } ;
2018
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+ ) ;
2424
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+ }
2831
29- // Check start
3032 simple_network
3133 . start ( )
32- . expect ( "Failed to start Simple Network " ) ;
34+ . expect ( "Network should not be started yet " ) ;
3335
34- // Check initialize
3536 simple_network
3637 . initialize ( 0 , 0 )
37- . expect ( "Failed to initialize Simple Network " ) ;
38+ . expect ( "Network should not be initialized yet " ) ;
3839
3940 // edk2 virtio-net driver does not support statistics, so
4041 // allow UNSUPPORTED (same for collect_statistics below).
@@ -54,13 +55,6 @@ pub fn test() {
5455 )
5556 . expect ( "Failed to set receive filters" ) ;
5657
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-
6458 let payload = b"\0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \
6559 \x45 \x00 \
6660 \x00 \x21 \
@@ -137,5 +131,7 @@ pub fn test() {
137131 }
138132 }
139133 }
134+
135+ simple_network. shutdown ( ) . unwrap ( ) ;
140136 }
141137}
0 commit comments