Skip to content

Commit

Permalink
tests: Update to expect presence of UDP local address
Browse files Browse the repository at this point in the history
  • Loading branch information
chrysn committed Feb 2, 2024
1 parent 097b194 commit 3157e6e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 13 deletions.
5 changes: 4 additions & 1 deletion src/iface/interface/tests/ipv4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,10 @@ fn test_raw_socket_with_udp_socket(#[case] medium: Medium) {
socket.recv(),
Ok((
&UDP_PAYLOAD[..],
IpEndpoint::new(src_addr.into(), 67).into()
udp::UdpMetadata {
local_address: Some(dst_addr.into()),
..IpEndpoint::new(src_addr.into(), 67).into()
}
))
);
}
Expand Down
6 changes: 5 additions & 1 deletion src/iface/interface/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ fn test_handle_udp_broadcast(
payload_len: udp_repr.header_len() + UDP_PAYLOAD.len(),
hop_limit: 0x40,
});
let dst_addr = ip_repr.dst_addr();

// Bind the socket to port 68
let socket = sockets.get_mut::<udp::Socket>(socket_handle);
Expand Down Expand Up @@ -143,7 +144,10 @@ fn test_handle_udp_broadcast(
assert!(socket.can_recv());
assert_eq!(
socket.recv(),
Ok((&UDP_PAYLOAD[..], IpEndpoint::new(src_ip.into(), 67).into()))
Ok((&UDP_PAYLOAD[..], udp::UdpMetadata {
local_address: Some(dst_addr),
..IpEndpoint::new(src_ip.into(), 67).into()
}))
);
}

Expand Down
23 changes: 16 additions & 7 deletions src/iface/interface/tests/sixlowpan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,14 +368,23 @@ In at rhoncus tortor. Cras blandit tellus diam, varius vestibulum nibh commodo n
socket.recv(),
Ok((
&udp_data[..],
IpEndpoint {
addr: IpAddress::Ipv6(Ipv6Address([
0xfe, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x42, 0x42, 0x42, 0x42, 0x42,
0xb, 0x1a,
])),
port: 54217,
udp::UdpMetadata {
local_address: Some(
Ipv6Address([
0xfe, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x92, 0xfc, 0x48, 0xc2, 0xa4,
0x41, 0xfc, 0x76,
])
.into()
),
..IpEndpoint {
addr: IpAddress::Ipv6(Ipv6Address([
0xfe, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x42, 0x42, 0x42, 0x42,
0x42, 0xb, 0x1a,
])),
port: 54217,
}
.into()
}
.into()
))
);

Expand Down
24 changes: 20 additions & 4 deletions src/socket/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,13 @@ mod test {
addr: REMOTE_ADDR.into_address(),
port: REMOTE_PORT,
};
fn remote_metadata_with_local() -> UdpMetadata {
// Would be great as a const once we have const `.into()`.
UdpMetadata {
local_address: Some(LOCAL_ADDR.into()),
..REMOTE_END.into()
}
}

pub const LOCAL_IP_REPR: IpRepr = IpReprIpvX(IpvXRepr {
src_addr: LOCAL_ADDR,
Expand Down Expand Up @@ -823,7 +830,10 @@ mod test {
PAYLOAD,
);

assert_eq!(socket.recv(), Ok((&b"abcdef"[..], REMOTE_END.into())));
assert_eq!(
socket.recv(),
Ok((&b"abcdef"[..], remote_metadata_with_local()))
);
assert!(!socket.can_recv());
}

Expand Down Expand Up @@ -851,8 +861,14 @@ mod test {
&REMOTE_UDP_REPR,
PAYLOAD,
);
assert_eq!(socket.peek(), Ok((&b"abcdef"[..], &REMOTE_END.into(),)));
assert_eq!(socket.recv(), Ok((&b"abcdef"[..], REMOTE_END.into(),)));
assert_eq!(
socket.peek(),
Ok((&b"abcdef"[..], &remote_metadata_with_local(),))
);
assert_eq!(
socket.recv(),
Ok((&b"abcdef"[..], remote_metadata_with_local(),))
);
assert_eq!(socket.peek(), Err(RecvError::Exhausted));
}

Expand Down Expand Up @@ -1025,7 +1041,7 @@ mod test {
dst_port: LOCAL_PORT,
};
socket.process(cx, PacketMeta::default(), &REMOTE_IP_REPR, &repr, &[]);
assert_eq!(socket.recv(), Ok((&[][..], REMOTE_END.into())));
assert_eq!(socket.recv(), Ok((&[][..], remote_metadata_with_local())));
}

#[test]
Expand Down

0 comments on commit 3157e6e

Please sign in to comment.