Skip to content

Commit 5b3578e

Browse files
authored
Fix test failures on NetBSD. (#746)
Fix test failures on NetBSD, which is mostly adding `target = "netbsd"` for areas where NetBSD is similar to other OS's, though NetBSD does have a few additional special cases; NetBSD doesn't appear to reject `SYMLINK_FOLLOW` on `faccessat`, it doesn't appear to reject invalid timespec values in `clock_nanosleep`, and `get_ipv6_multicasthops` appears to default to 1.
1 parent 676a29c commit 5b3578e

File tree

6 files changed

+36
-30
lines changed

6 files changed

+36
-30
lines changed

tests/fs/file.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ fn test_file() {
3434
Err(err) => Err(err).unwrap(),
3535
}
3636

37+
// Check that `SYMLINK_FOLLOW` is rejected. Except on NetBSD which seems
38+
// to permit it.
39+
#[cfg(not(target_os = "netbsd"))]
3740
assert_eq!(
3841
rustix::fs::accessat(
3942
rustix::fs::CWD,

tests/fs/makedev.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ use rustix::fs::{major, makedev, minor};
22

33
#[test]
44
fn makedev_roundtrip() {
5-
// Apple's, FreeBSD 11's, and DragonFly's `makedev` doesn't handle extra
6-
// bits set.
5+
// Apple's, FreeBSD 11's, DragonFly's, and NetBSD's `makedev` doesn't
6+
// handle extra bits set.
77
#[cfg(freebsdlike)]
88
let (maj, min) = (0x0000_0026, 0x6564_0061);
9-
#[cfg(not(any(apple, freebsdlike)))]
10-
let (maj, min) = (0x2324_2526, 0x6564_6361);
119
#[cfg(apple)]
1210
let (maj, min) = (0x0000_0026, 0x0064_6361);
11+
#[cfg(target_os = "netbsd")]
12+
let (maj, min) = (0x0000_0026, 0x0000_0061);
13+
#[cfg(not(any(apple, freebsdlike, target_os = "netbsd")))]
14+
let (maj, min) = (0x2324_2526, 0x6564_6361);
1315

1416
let dev = makedev(maj, min);
1517
assert_eq!(maj, major(dev));

tests/fs/mknodat.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,9 @@ 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, OpenBSD, or illumos.
12-
#[cfg(not(any(
13-
target_os = "freebsd",
14-
target_os = "illumos",
15-
target_os = "openbsd",
16-
target_os = "solaris"
17-
)))]
11+
// Create a regular file. Not supported on FreeBSD, OpenBSD, illumos,
12+
// or NetBSD.
13+
#[cfg(not(any(solarish, netbsdlike, target_os = "freebsd")))]
1814
{
1915
mknodat(&dir, "foo", FileType::RegularFile, Mode::empty(), 0).unwrap();
2016
let stat = statat(&dir, "foo", AtFlags::empty()).unwrap();

tests/net/sockopt.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ fn test_sockopts_ipv4() {
5151
.unwrap();
5252

5353
// Check that we have a timeout of at least the time we set.
54-
if cfg!(not(target_os = "freebsd")) {
54+
if cfg!(not(any(target_os = "freebsd", target_os = "netbsd"))) {
5555
assert!(
5656
rustix::net::sockopt::get_socket_timeout(&s, rustix::net::sockopt::Timeout::Recv)
5757
.unwrap()
5858
.unwrap()
5959
>= Duration::new(1, 1)
6060
);
6161
} else {
62-
// On FreeBSD <= 12, it appears the system rounds the timeout down.
62+
// On FreeBSD <= 12 and NetBSD, it appears the system rounds the timeout down.
6363
assert!(
6464
rustix::net::sockopt::get_socket_timeout(&s, rustix::net::sockopt::Timeout::Recv)
6565
.unwrap()
@@ -156,6 +156,10 @@ fn test_sockopts_ipv6() {
156156
Err(err) => Err(err).unwrap(),
157157
}
158158
assert_ne!(rustix::net::sockopt::get_ipv6_unicast_hops(&s).unwrap(), 0);
159+
160+
// On NetBSD, `get_ipv6_multicasthops` returns 1 here. It's not evident
161+
// why it differs from other OS's.
162+
#[cfg(not(target_os = "netbsd"))]
159163
match rustix::net::sockopt::get_ipv6_multicast_hops(&s) {
160164
Ok(hops) => assert_eq!(hops, 0),
161165
Err(rustix::io::Errno::NOPROTOOPT) => (),

tests/net/unix.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +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-
// illumos too.
220-
#[cfg(not(any(target_os = "freebsd", target_os = "illumos")))]
219+
// illumos and NetBSD too.
220+
#[cfg(not(any(target_os = "freebsd", target_os = "illumos", target_os = "netbsd")))]
221221
assert_eq!(
222222
Some(rustix::net::SocketAddrAny::Unix(addr.clone())),
223223
result.address

tests/thread/clocks.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,28 @@ fn test_invalid_nanosleep() {
2222
tv_nsec: 1_000_000_000,
2323
}) {
2424
NanosleepRelativeResult::Err(io::Errno::INVAL) => (),
25-
otherwise => panic!("unexpected resut: {:?}", otherwise),
25+
otherwise => panic!("unexpected result: {:?}", otherwise),
2626
}
2727
match nanosleep(&Timespec {
2828
tv_sec: 0,
2929
tv_nsec: !0,
3030
}) {
3131
NanosleepRelativeResult::Err(io::Errno::INVAL) => (),
32-
otherwise => panic!("unexpected resut: {:?}", otherwise),
32+
otherwise => panic!("unexpected result: {:?}", otherwise),
3333
}
3434
match nanosleep(&Timespec {
3535
tv_sec: !0,
3636
tv_nsec: 1_000_000_000,
3737
}) {
3838
NanosleepRelativeResult::Err(io::Errno::INVAL) => (),
39-
otherwise => panic!("unexpected resut: {:?}", otherwise),
39+
otherwise => panic!("unexpected result: {:?}", otherwise),
4040
}
4141
match nanosleep(&Timespec {
4242
tv_sec: !0,
4343
tv_nsec: !0,
4444
}) {
4545
NanosleepRelativeResult::Err(io::Errno::INVAL) => (),
46-
otherwise => panic!("unexpected resut: {:?}", otherwise),
46+
otherwise => panic!("unexpected result: {:?}", otherwise),
4747
}
4848
}
4949

@@ -56,6 +56,7 @@ fn test_invalid_nanosleep() {
5656
target_os = "redox",
5757
target_os = "wasi",
5858
)))]
59+
#[cfg(not(target_os = "netbsd"))] // NetBSD doesn't seem to enforce valid timespecs.
5960
#[test]
6061
fn test_invalid_nanosleep_absolute() {
6162
match clock_nanosleep_absolute(
@@ -66,7 +67,7 @@ fn test_invalid_nanosleep_absolute() {
6667
},
6768
) {
6869
Err(io::Errno::INVAL) => (),
69-
otherwise => panic!("unexpected resut: {:?}", otherwise),
70+
otherwise => panic!("unexpected result: {:?}", otherwise),
7071
}
7172
match clock_nanosleep_absolute(
7273
ClockId::Monotonic,
@@ -76,7 +77,7 @@ fn test_invalid_nanosleep_absolute() {
7677
},
7778
) {
7879
Err(io::Errno::INVAL) => (),
79-
otherwise => panic!("unexpected resut: {:?}", otherwise),
80+
otherwise => panic!("unexpected result: {:?}", otherwise),
8081
}
8182
match clock_nanosleep_absolute(
8283
ClockId::Monotonic,
@@ -86,7 +87,7 @@ fn test_invalid_nanosleep_absolute() {
8687
},
8788
) {
8889
Err(io::Errno::INVAL) => (),
89-
otherwise => panic!("unexpected resut: {:?}", otherwise),
90+
otherwise => panic!("unexpected result: {:?}", otherwise),
9091
}
9192
match clock_nanosleep_absolute(
9293
ClockId::Monotonic,
@@ -96,7 +97,7 @@ fn test_invalid_nanosleep_absolute() {
9697
},
9798
) {
9899
Err(io::Errno::INVAL) => (),
99-
otherwise => panic!("unexpected resut: {:?}", otherwise),
100+
otherwise => panic!("unexpected result: {:?}", otherwise),
100101
}
101102
}
102103

@@ -119,7 +120,7 @@ fn test_invalid_nanosleep_relative() {
119120
},
120121
) {
121122
NanosleepRelativeResult::Err(io::Errno::INVAL) => (),
122-
otherwise => panic!("unexpected resut: {:?}", otherwise),
123+
otherwise => panic!("unexpected result: {:?}", otherwise),
123124
}
124125
match clock_nanosleep_relative(
125126
ClockId::Monotonic,
@@ -129,7 +130,7 @@ fn test_invalid_nanosleep_relative() {
129130
},
130131
) {
131132
NanosleepRelativeResult::Err(io::Errno::INVAL) => (),
132-
otherwise => panic!("unexpected resut: {:?}", otherwise),
133+
otherwise => panic!("unexpected result: {:?}", otherwise),
133134
}
134135
match clock_nanosleep_relative(
135136
ClockId::Monotonic,
@@ -139,7 +140,7 @@ fn test_invalid_nanosleep_relative() {
139140
},
140141
) {
141142
NanosleepRelativeResult::Err(io::Errno::INVAL) => (),
142-
otherwise => panic!("unexpected resut: {:?}", otherwise),
143+
otherwise => panic!("unexpected result: {:?}", otherwise),
143144
}
144145
match clock_nanosleep_relative(
145146
ClockId::Monotonic,
@@ -149,7 +150,7 @@ fn test_invalid_nanosleep_relative() {
149150
},
150151
) {
151152
NanosleepRelativeResult::Err(io::Errno::INVAL) => (),
152-
otherwise => panic!("unexpected resut: {:?}", otherwise),
153+
otherwise => panic!("unexpected result: {:?}", otherwise),
153154
}
154155
}
155156

@@ -161,7 +162,7 @@ fn test_zero_nanosleep() {
161162
tv_nsec: 0,
162163
}) {
163164
NanosleepRelativeResult::Ok => (),
164-
otherwise => panic!("unexpected resut: {:?}", otherwise),
165+
otherwise => panic!("unexpected result: {:?}", otherwise),
165166
}
166167
}
167168

@@ -184,7 +185,7 @@ fn test_zero_nanosleep_absolute() {
184185
},
185186
) {
186187
Ok(()) => (),
187-
otherwise => panic!("unexpected resut: {:?}", otherwise),
188+
otherwise => panic!("unexpected result: {:?}", otherwise),
188189
}
189190
}
190191

@@ -207,6 +208,6 @@ fn test_zero_nanosleep_relative() {
207208
},
208209
) {
209210
NanosleepRelativeResult::Ok => (),
210-
otherwise => panic!("unexpected resut: {:?}", otherwise),
211+
otherwise => panic!("unexpected result: {:?}", otherwise),
211212
}
212213
}

0 commit comments

Comments
 (0)