11// SPDX-License-Identifier: MIT OR Apache-2.0
22
3- use uefi:: proto:: network:: snp:: { InterruptStatus , ReceiveFlags , SimpleNetwork } ;
3+ use uefi:: proto:: network:: snp:: { InterruptStatus , NetworkState , ReceiveFlags , SimpleNetwork } ;
44use uefi:: proto:: network:: MacAddress ;
55use uefi:: { boot, Status } ;
66
@@ -10,29 +10,30 @@ pub fn test() {
1010 let handles = boot:: find_handles :: < SimpleNetwork > ( ) . unwrap_or_default ( ) ;
1111
1212 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 {
1514 continue ;
16- }
17- let simple_network = simple_network. unwrap ( ) ;
15+ } ;
1816
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+ ) ;
2222
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+ }
2629
27- // Check start
2830 simple_network
2931 . start ( )
30- . expect ( "Failed to start Simple Network " ) ;
32+ . expect ( "Network should not be started yet " ) ;
3133
32- // Check initialize
3334 simple_network
3435 . initialize ( 0 , 0 )
35- . expect ( "Failed to initialize Simple Network " ) ;
36+ . expect ( "Network should not be initialized yet " ) ;
3637
3738 // edk2 virtio-net driver does not support statistics, so
3839 // allow UNSUPPORTED (same for collect_statistics below).
@@ -52,13 +53,6 @@ pub fn test() {
5253 )
5354 . expect ( "Failed to set receive filters" ) ;
5455
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-
6256 let payload = b"\0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \
6357 \x45 \x00 \
6458 \x00 \x21 \
@@ -133,5 +127,7 @@ pub fn test() {
133127 }
134128 }
135129 }
130+
131+ simple_network. shutdown ( ) . unwrap ( ) ;
136132 }
137133}
0 commit comments