@@ -17,14 +17,12 @@ pub fn test() {
17
17
let simple_network = simple_network. unwrap ( ) ;
18
18
19
19
// 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( ) ) ) ;
23
22
24
23
// 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( ) ) ) ;
28
26
29
27
// Check start
30
28
simple_network
@@ -36,15 +34,18 @@ pub fn test() {
36
34
. initialize ( 0 , 0 )
37
35
. expect ( "Failed to initialize Simple Network" ) ;
38
36
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( ) ) ) ;
40
41
41
42
// Reading the interrupt status clears it
42
43
simple_network. get_interrupt_status ( ) . unwrap ( ) ;
43
44
44
45
// Set receive filters
45
46
simple_network
46
47
. receive_filters (
47
- ReceiveFlags :: UNICAST | ReceiveFlags :: MULTICAST | ReceiveFlags :: BROADCAST ,
48
+ ReceiveFlags :: UNICAST | ReceiveFlags :: BROADCAST ,
48
49
ReceiveFlags :: empty ( ) ,
49
50
false ,
50
51
None ,
@@ -113,13 +114,22 @@ pub fn test() {
113
114
assert_eq ! ( buffer[ 42 ..47 ] , [ 4 , 4 , 3 , 2 , 1 ] ) ;
114
115
115
116
// 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
+ }
124
134
}
125
135
}
0 commit comments