Skip to content

backport a test to see if timestamps are working in aarch64 #1837

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions test/sys/test_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,12 +533,7 @@ mod recvfrom {
assert_eq!(AddressFamily::Inet, from.unwrap().family().unwrap());
}

#[cfg(any(
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd",
))]
#[cfg(any(target_os = "linux",))]
#[test]
pub fn udp_recvmmsg() {
use nix::sys::socket::{recvmmsg, MsgFlags};
Expand All @@ -565,6 +560,9 @@ mod recvfrom {
None,
)
.expect("send socket failed");
setsockopt(rsock, sockopt::ReceiveTimestampns, &true).unwrap();
let mut cmsgspace1 = nix::cmsg_space!(nix::sys::time::TimeSpec);
let mut cmsgspace2 = nix::cmsg_space!(nix::sys::time::TimeSpec);

let send_thread = thread::spawn(move || {
for _ in 0..NUM_MESSAGES_SENT {
Expand All @@ -582,19 +580,31 @@ mod recvfrom {
.map(|buf| [IoSliceMut::new(&mut buf[..])])
.collect();

for iov in &iovs {
msgs.push_back(RecvMmsgData {
iov,
cmsg_buffer: None,
})
}
msgs.push_back(RecvMmsgData {
iov: &iovs[0],
cmsg_buffer: Some(&mut cmsgspace1),
});
msgs.push_back(RecvMmsgData {
iov: &iovs[1],
cmsg_buffer: Some(&mut cmsgspace2),
});

let res: Vec<RecvMsg<SockaddrIn>> =
recvmmsg(rsock, &mut msgs, MsgFlags::empty(), None)
.expect("recvmmsg");
assert_eq!(res.len(), DATA.len());

for RecvMsg { address, bytes, .. } in res.into_iter() {
// one
for r in res.into_iter() {
let rtime = match r.cmsgs().next() {
Some(ControlMessageOwned::ScmTimestampns(rtime)) => rtime,
Some(_) => panic!("Unexpected control message"),
None => panic!("No control message"),
};
assert!(rtime.tv_sec() > 10000);

let RecvMsg { address, bytes, .. } = r;

assert_eq!(AddressFamily::Inet, address.unwrap().family().unwrap());
assert_eq!(DATA.len(), bytes);
}
Expand Down