Skip to content

Commit 7914500

Browse files
authored
Fix some test failures on illumos. (#740)
`mlock` fails if the memory is not aligned. `tcgetattr` doesn't work on pseudoterminals. A few errno values are different. And disable some tests that are disabled on other platforms too.
1 parent 05681c8 commit 7914500

File tree

8 files changed

+44
-23
lines changed

8 files changed

+44
-23
lines changed

src/mm/mmap.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ pub unsafe fn mprotect(ptr: *mut c_void, len: usize, flags: MprotectFlags) -> io
222222
///
223223
/// Some implementations implicitly round the memory region out to the nearest
224224
/// page boundaries, so this function may lock more memory than explicitly
225-
/// requested if the memory isn't page-aligned.
225+
/// requested if the memory isn't page-aligned. Other implementations fail if
226+
/// the memory isn't page-aligned.
226227
///
227228
/// # References
228229
/// - [POSIX]

tests/fs/mknodat.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@ fn test_mknodat() {
88
let tmp = tempfile::tempdir().unwrap();
99
let dir = openat(CWD, tmp.path(), OFlags::RDONLY, Mode::empty()).unwrap();
1010

11-
// Create a regular file. Not supported on FreeBSD or OpenBSD.
12-
#[cfg(not(any(target_os = "freebsd", target_os = "openbsd", target_os = "solaris")))]
11+
// Create a regular file. Not supported on FreeBSD, OpenBSD, or illumos.
12+
#[cfg(not(any(
13+
target_os = "freebsd",
14+
target_os = "illumos",
15+
target_os = "openbsd",
16+
target_os = "solaris"
17+
)))]
1318
{
1419
mknodat(&dir, "foo", FileType::RegularFile, Mode::empty(), 0).unwrap();
1520
let stat = statat(&dir, "foo", AtFlags::empty()).unwrap();

tests/mm/mlock.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,16 @@ use std::ffi::c_void;
88
#[test]
99
fn test_mlock() {
1010
let mut buf = vec![0_u8; 4096];
11+
let ptr = buf.as_mut_ptr();
12+
13+
// On Linux, `mlock` automatically rounds the address down to the nearest
14+
// page size. On other platforms, we need to do it manually.
15+
#[cfg(not(linux_kernel))]
16+
let ptr = ((ptr as usize) & (-4096_isize) as usize) as *mut u8;
1117

1218
unsafe {
13-
match rustix::mm::mlock(buf.as_mut_ptr().cast::<c_void>(), buf.len()) {
14-
Ok(()) => rustix::mm::munlock(buf.as_mut_ptr().cast::<c_void>(), buf.len()).unwrap(),
19+
match rustix::mm::mlock(ptr.cast::<c_void>(), buf.len()) {
20+
Ok(()) => rustix::mm::munlock(ptr.cast::<c_void>(), buf.len()).unwrap(),
1521
// Tests won't always have enough memory or permissions, and that's ok.
1622
Err(rustix::io::Errno::PERM | rustix::io::Errno::NOMEM) => {}
1723
// But they shouldn't fail otherwise.

tests/mm/mmap.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,13 @@ fn test_mlock() {
100100
unsafe {
101101
let addr = mmap_anonymous(null_mut(), 8192, ProtFlags::READ, MapFlags::PRIVATE).unwrap();
102102

103-
mlock(addr, 8192).unwrap();
104-
munlock(addr, 8192).unwrap();
103+
match mlock(addr, 8192) {
104+
Ok(()) => munlock(addr, 8192).unwrap(),
105+
// Tests won't always have enough memory or permissions, and that's ok.
106+
Err(rustix::io::Errno::PERM | rustix::io::Errno::NOMEM) => (),
107+
// But they shouldn't fail otherwise.
108+
Err(other) => Err(other).unwrap(),
109+
}
105110

106111
#[cfg(linux_kernel)]
107112
{

tests/net/sockopt.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ fn test_sockopts_ipv4() {
2525
assert!(!rustix::net::sockopt::get_socket_passcred(&s).unwrap());
2626
assert_ne!(rustix::net::sockopt::get_ip_ttl(&s).unwrap(), 0);
2727
assert_ne!(rustix::net::sockopt::get_ip_ttl(&s).unwrap(), 77);
28-
#[cfg(not(any(bsd, windows)))]
28+
#[cfg(not(any(bsd, windows, target_os = "illumos")))]
2929
assert!(rustix::net::sockopt::get_ip_multicast_loop(&s).unwrap());
30-
#[cfg(not(any(bsd, windows)))]
30+
#[cfg(not(any(bsd, windows, target_os = "illumos")))]
3131
assert_eq!(rustix::net::sockopt::get_ip_multicast_ttl(&s).unwrap(), 1);
3232
assert!(!rustix::net::sockopt::get_tcp_nodelay(&s).unwrap());
3333
// On a new socket we shouldn't have an error yet.
@@ -111,7 +111,7 @@ fn test_sockopts_ipv4() {
111111
// Check the ip ttl.
112112
assert_eq!(rustix::net::sockopt::get_ip_ttl(&s).unwrap(), 77);
113113

114-
#[cfg(not(any(bsd, windows)))]
114+
#[cfg(not(any(bsd, windows, target_os = "illumos")))]
115115
{
116116
// Set the multicast loop flag;
117117
rustix::net::sockopt::set_ip_multicast_loop(&s, false).unwrap();
@@ -152,6 +152,7 @@ fn test_sockopts_ipv6() {
152152
Ok(multicast_loop) => assert!(multicast_loop),
153153
Err(rustix::io::Errno::OPNOTSUPP) => (),
154154
Err(rustix::io::Errno::INVAL) => (),
155+
Err(rustix::io::Errno::NOPROTOOPT) => (),
155156
Err(err) => Err(err).unwrap(),
156157
}
157158
assert_ne!(rustix::net::sockopt::get_ipv6_unicast_hops(&s).unwrap(), 0);
@@ -175,13 +176,12 @@ fn test_sockopts_ipv6() {
175176
// Check that the IPV6 multicast loop value is set.
176177
match rustix::net::sockopt::get_ipv6_multicast_loop(&s) {
177178
Ok(multicast_loop) => assert!(!multicast_loop),
178-
Err(rustix::io::Errno::OPNOTSUPP) => (),
179-
Err(rustix::io::Errno::INVAL) => (),
180179
Err(err) => Err(err).unwrap(),
181180
}
182181
}
183182
Err(rustix::io::Errno::OPNOTSUPP) => (),
184183
Err(rustix::io::Errno::INVAL) => (),
184+
Err(rustix::io::Errno::NOPROTOOPT) => (),
185185
Err(err) => Err(err).unwrap(),
186186
}
187187

tests/net/unix.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ fn do_test_unix_msg(addr: SocketAddrUnix) {
216216
);
217217
// Don't ask me why, but this was seen to fail on FreeBSD.
218218
// `SocketAddrUnix::path()` returned `None` for some reason.
219-
#[cfg(not(target_os = "freebsd"))]
219+
// illumos too.
220+
#[cfg(not(any(target_os = "freebsd", target_os = "illumos")))]
220221
assert_eq!(
221222
Some(rustix::net::SocketAddrAny::Unix(addr.clone())),
222223
result.address

tests/termios/termios.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Disable on illumos where `tcgetattr` doesn't appear to support
2+
// pseudoterminals.
3+
#[cfg(not(target_os = "illumos"))]
14
#[test]
25
fn test_termios_speeds() {
36
use rustix::pty::*;

tests/time/settime.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ use rustix::time::{clock_settime, ClockId, Timespec};
44
#[test]
55
fn test_settime() {
66
// Monotonic clocks are never settable.
7-
assert_eq!(
8-
clock_settime(
9-
ClockId::Monotonic,
10-
Timespec {
11-
tv_sec: 0,
12-
tv_nsec: 0
13-
}
14-
),
15-
Err(io::Errno::INVAL)
16-
);
7+
match clock_settime(
8+
ClockId::Monotonic,
9+
Timespec {
10+
tv_sec: 0,
11+
tv_nsec: 0,
12+
},
13+
) {
14+
Err(io::Errno::INVAL | io::Errno::PERM) => (),
15+
_otherwise => panic!(),
16+
}
1717
}

0 commit comments

Comments
 (0)