Skip to content

Commit c35afad

Browse files
committed
integration-test: SNP: improve setup and teardown routine
1 parent ae2e17e commit c35afad

File tree

2 files changed

+19
-23
lines changed
  • uefi-test-runner/src/proto/network
  • uefi/src/proto/network

2 files changed

+19
-23
lines changed

uefi-test-runner/src/proto/network/snp.rs

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use core::time::Duration;
44

5-
use uefi::proto::network::snp::{InterruptStatus, ReceiveFlags, SimpleNetwork};
5+
use uefi::proto::network::snp::{InterruptStatus, NetworkState, ReceiveFlags, SimpleNetwork};
66
use uefi::proto::network::MacAddress;
77
use uefi::{boot, Status};
88

@@ -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\
@@ -135,5 +129,7 @@ pub fn test() {
135129
}
136130
}
137131
}
132+
133+
simple_network.shutdown().unwrap();
138134
}
139135
}

uefi/src/proto/network/snp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ impl SimpleNetwork {
267267
unsafe { &*(ptr::from_ref(&self.0.wait_for_packet).cast::<Event>()) }
268268
}
269269

270-
/// Returns a reference to the Simple Network mode.
270+
/// Returns a reference to the [`NetworkMode`].
271271
#[must_use]
272272
pub fn mode(&self) -> &NetworkMode {
273273
unsafe { &*self.0.mode }

0 commit comments

Comments
 (0)