Skip to content

Commit 1fbc54b

Browse files
committed
uefi-test-runner: SNP: use smoltcp to UDP packet
Properly deconstruct the response. This improves the maintainability of this test and to better understand what is going on.
1 parent 5cf9fd5 commit 1fbc54b

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

Cargo.lock

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

uefi-test-runner/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ edition = "2024"
88
[dependencies]
99
uefi-raw = { path = "../uefi-raw" }
1010
uefi = { path = "../uefi", features = ["alloc", "global_allocator", "panic_handler", "logger", "qemu", "log-debugcon"] }
11+
smoltcp = { version = "0.12.0", default-features = false, features = ["medium-ethernet", "proto-ipv4", "socket-udp"] }
1112

1213
log.workspace = true
1314

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,19 @@ pub fn test() {
179179
let n = receive(simple_network.deref_mut(), &mut buffer).unwrap();
180180
debug!("Reply has {n} bytes");
181181

182+
let recv_frame = smoltcp::wire::EthernetFrame::new_checked(&buffer).unwrap();
183+
// Check the packet was sent to the MAC that we expected.
184+
assert_eq!(
185+
recv_frame.dst_addr(),
186+
smoltcp::wire::EthernetAddress::from_bytes(&EXPECTED_MAC)
187+
);
188+
182189
// Check payload in UDP packet that was reversed by our EchoService.
183-
assert_eq!(buffer[42..47], [4, 4, 3, 2, 1]);
190+
{
191+
let recv_ipv4 = smoltcp::wire::Ipv4Packet::new_checked(recv_frame.payload()).unwrap();
192+
let udp_packet = smoltcp::wire::UdpPacket::new_checked(recv_ipv4.payload()).unwrap();
193+
assert_eq!(udp_packet.payload(), &[4, 4, 3, 2, 1]);
194+
}
184195

185196
// Get stats
186197
let res = simple_network.collect_statistics();

0 commit comments

Comments
 (0)