Skip to content

Commit fb5c097

Browse files
committed
integration-test: SNP: improve setup and teardown routine
1 parent 12e8406 commit fb5c097

File tree

2 files changed

+17
-21
lines changed
  • uefi/src/proto/network
  • uefi-test-runner/src/proto/network

2 files changed

+17
-21
lines changed

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

Lines changed: 16 additions & 20 deletions
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,28 @@ 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 can be used
24+
if !simple_network.mode().media_present_supported || !simple_network.mode().media_present {
25+
continue;
26+
}
2627

27-
// Check start
2828
simple_network
2929
.start()
30-
.expect("Failed to start Simple Network");
30+
.expect("Network should not be started yet");
3131

32-
// Check initialize
3332
simple_network
3433
.initialize(0, 0)
35-
.expect("Failed to initialize Simple Network");
34+
.expect("Network should not be initialized yet");
3635

3736
// edk2 virtio-net driver does not support statistics, so
3837
// allow UNSUPPORTED (same for collect_statistics below).
@@ -52,11 +51,6 @@ pub fn test() {
5251
)
5352
.expect("Failed to set receive filters");
5453

55-
// Check media
56-
if !simple_network.mode().media_present_supported || !simple_network.mode().media_present {
57-
continue;
58-
}
59-
6054
let payload = b"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\
6155
\x45\x00\
6256
\x00\x21\
@@ -131,5 +125,7 @@ pub fn test() {
131125
}
132126
}
133127
}
128+
129+
simple_network.shutdown().unwrap();
134130
}
135131
}

uefi/src/proto/network/snp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ impl SimpleNetwork {
290290
&self.wait_for_packet
291291
}
292292

293-
/// Returns a reference to the Simple Network mode.
293+
/// Returns a reference to the [`NetworkMode`].
294294
#[must_use]
295295
pub const fn mode(&self) -> &NetworkMode {
296296
unsafe { &*self.mode }

0 commit comments

Comments
 (0)