Skip to content

Commit 843aed3

Browse files
committed
integration-test: SNP: improve setup and teardown routine
1 parent 3c2f5f3 commit 843aed3

File tree

2 files changed

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

2 files changed

+19
-23
lines changed

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

+18-22
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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};
44
use uefi::proto::network::MacAddress;
55
use 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
}

uefi/src/proto/network/snp.rs

+1-1
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)