@@ -17,14 +17,12 @@ pub fn test() {
1717 let simple_network = simple_network. unwrap ( ) ;
1818
1919 // Check shutdown
20- simple_network
21- . shutdown ( )
22- . expect ( "Failed to shutdown Simple Network" ) ;
20+ let res = simple_network. shutdown ( ) ;
21+ assert ! ( res == Ok ( ( ) ) || res == Err ( Status :: NOT_STARTED . into( ) ) ) ;
2322
2423 // Check stop
25- simple_network
26- . stop ( )
27- . expect ( "Failed to stop Simple Network" ) ;
24+ let res = simple_network. stop ( ) ;
25+ assert ! ( res == Ok ( ( ) ) || res == Err ( Status :: NOT_STARTED . into( ) ) ) ;
2826
2927 // Check start
3028 simple_network
@@ -36,15 +34,18 @@ pub fn test() {
3634 . initialize ( 0 , 0 )
3735 . expect ( "Failed to initialize Simple Network" ) ;
3836
39- simple_network. reset_statistics ( ) . unwrap ( ) ;
37+ // edk2 virtio-net driver does not support statistics, so
38+ // allow UNSUPPORTED (same for collect_statistics below).
39+ let res = simple_network. reset_statistics ( ) ;
40+ assert ! ( res == Ok ( ( ) ) || res == Err ( Status :: UNSUPPORTED . into( ) ) ) ;
4041
4142 // Reading the interrupt status clears it
4243 simple_network. get_interrupt_status ( ) . unwrap ( ) ;
4344
4445 // Set receive filters
4546 simple_network
4647 . receive_filters (
47- ReceiveFlags :: UNICAST | ReceiveFlags :: MULTICAST | ReceiveFlags :: BROADCAST ,
48+ ReceiveFlags :: UNICAST | ReceiveFlags :: BROADCAST ,
4849 ReceiveFlags :: empty ( ) ,
4950 false ,
5051 None ,
@@ -113,13 +114,22 @@ pub fn test() {
113114 assert_eq ! ( buffer[ 42 ..47 ] , [ 4 , 4 , 3 , 2 , 1 ] ) ;
114115
115116 // Get stats
116- let stats = simple_network
117- . collect_statistics ( )
118- . expect ( "Failed to collect statistics" ) ;
119- info ! ( "Stats: {:?}" , stats) ;
120-
121- // One frame should have been transmitted and one received
122- assert_eq ! ( stats. tx_total_frames( ) . unwrap( ) , 1 ) ;
123- assert_eq ! ( stats. rx_total_frames( ) . unwrap( ) , 1 ) ;
117+ let res = simple_network. collect_statistics ( ) ;
118+ match res {
119+ Ok ( stats) => {
120+ info ! ( "Stats: {:?}" , stats) ;
121+
122+ // One frame should have been transmitted and one received
123+ assert_eq ! ( stats. tx_total_frames( ) . unwrap( ) , 1 ) ;
124+ assert_eq ! ( stats. rx_total_frames( ) . unwrap( ) , 1 ) ;
125+ }
126+ Err ( e) => {
127+ if e == Status :: UNSUPPORTED . into ( ) {
128+ info ! ( "Stats: unsupported." ) ;
129+ } else {
130+ panic ! ( "{e}" ) ;
131+ }
132+ }
133+ }
124134 }
125135}
0 commit comments