Skip to content

Commit

Permalink
Fix a test failures on illumos.
Browse files Browse the repository at this point in the history
See the comments in the code for details.
  • Loading branch information
sunfishcode committed Oct 25, 2023
1 parent 1ab21e6 commit 44ef9f9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
8 changes: 4 additions & 4 deletions src/backend/libc/net/read_sockaddr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,10 @@ unsafe fn inner_read_sockaddr_os(
assert_eq!(decode.sun_path[len - 1 - offsetof_sun_path], 0);
let path_bytes = &decode.sun_path[..len - 1 - offsetof_sun_path];

// FreeBSD sometimes sets the length to longer than the length
// of the NUL-terminated string. Find the NUL and truncate the
// string accordingly.
#[cfg(target_os = "freebsd")]
// FreeBSD and illumos sometimes set the length to longer than
// the length of the NUL-terminated string. Find the NUL and
// truncate the string accordingly.
#[cfg(any(solarish, target_os = "freebsd"))]
let path_bytes = &path_bytes[..path_bytes.iter().position(|b| *b == 0).unwrap()];

SocketAddrAny::Unix(
Expand Down
27 changes: 16 additions & 11 deletions tests/io/read_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,17 +321,22 @@ fn test_p_offsets() {
Ok(_) => panic!("pwrite unexpectedly succeeded"),
Err(e) => panic!("pwrite failed with an unexpected error: {:?}", e),
}
match preadv(&f, &mut [IoSliceMut::new(&mut buf)], invalid_offset) {
Err(rustix::io::Errno::OPNOTSUPP | rustix::io::Errno::NOSYS) => {}
Err(rustix::io::Errno::INVAL) => {}
Ok(_) => panic!("preadv unexpectedly succeeded"),
Err(e) => panic!("preadv failed with an unexpected error: {:?}", e),
}
match pwritev(&f, &[IoSlice::new(&buf)], invalid_offset) {
Err(rustix::io::Errno::OPNOTSUPP | rustix::io::Errno::NOSYS) => {}
Err(rustix::io::Errno::INVAL) => {}
Ok(_) => panic!("pwritev unexpectedly succeeded"),
Err(e) => panic!("pwritev failed with an unexpected error: {:?}", e),
// illumos doesn't seem to diagnose a negative offset in
// `preadv`/`pwritev`.
#[cfg(not(target_os = "illumos"))]
{
match preadv(&f, &mut [IoSliceMut::new(&mut buf)], invalid_offset) {
Err(rustix::io::Errno::OPNOTSUPP | rustix::io::Errno::NOSYS) => {}
Err(rustix::io::Errno::INVAL) => {}
Ok(_) => panic!("preadv unexpectedly succeeded"),
Err(e) => panic!("preadv failed with an unexpected error: {:?}", e),
}
match pwritev(&f, &[IoSlice::new(&buf)], invalid_offset) {
Err(rustix::io::Errno::OPNOTSUPP | rustix::io::Errno::NOSYS) => {}
Err(rustix::io::Errno::INVAL) => {}
Ok(_) => panic!("pwritev unexpectedly succeeded"),
Err(e) => panic!("pwritev failed with an unexpected error: {:?}", e),
}
}
#[cfg(linux_kernel)]
{
Expand Down
13 changes: 11 additions & 2 deletions tests/net/sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ fn test_sockopts_tcp(s: &OwnedFd) {
// Set keepalive values:
sockopt::set_tcp_keepcnt(&s, 42).unwrap();
sockopt::set_tcp_keepidle(&s, Duration::from_secs(3601)).unwrap();
sockopt::set_tcp_keepintvl(&s, Duration::from_secs(61)).unwrap();
sockopt::set_tcp_keepintvl(&s, Duration::from_secs(60)).unwrap();

// Check keepalive values:
assert_eq!(sockopt::get_tcp_keepcnt(&s).unwrap(), 42);
Expand All @@ -226,8 +226,17 @@ fn test_sockopts_tcp(s: &OwnedFd) {
);
assert_eq!(
sockopt::get_tcp_keepintvl(&s).unwrap(),
Duration::from_secs(61)
Duration::from_secs(60)
);

#[cfg(not(target_os = "illumos"))]
{
sockopt::set_tcp_keepintvl(&s, Duration::from_secs(61)).unwrap();
assert_eq!(
sockopt::get_tcp_keepintvl(&s).unwrap(),
Duration::from_secs(61)
);
}
}

// Check the initial value of TCP_QUICKACK, set it, and check it.
Expand Down

0 comments on commit 44ef9f9

Please sign in to comment.