Skip to content

Commit 746fa42

Browse files
committed
refactor: cfg for test/*
1 parent 4e5f089 commit 746fa42

12 files changed

+38
-128
lines changed

test/common/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ macro_rules! skip {
1313
}
1414

1515
cfg_if! {
16-
if #[cfg(any(target_os = "android", target_os = "linux"))] {
16+
if #[cfg(linux_android)] {
1717
#[macro_export] macro_rules! require_capability {
1818
($name:expr, $capname:ident) => {
1919
use ::caps::{Capability, CapSet, has_cap};
@@ -87,7 +87,7 @@ macro_rules! skip_if_not_root {
8787
}
8888

8989
cfg_if! {
90-
if #[cfg(any(target_os = "android", target_os = "linux"))] {
90+
if #[cfg(linux_android)] {
9191
#[macro_export] macro_rules! skip_if_seccomp {
9292
($name:expr) => {
9393
if let Ok(s) = std::fs::read_to_string("/proc/self/status") {

test/sys/mod.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,7 @@ mod test_fanotify;
4747
#[cfg(target_os = "linux")]
4848
mod test_inotify;
4949
mod test_pthread;
50-
#[cfg(any(
51-
target_os = "android",
52-
target_os = "dragonfly",
53-
target_os = "freebsd",
54-
target_os = "linux",
55-
target_os = "macos",
56-
target_os = "netbsd",
57-
target_os = "openbsd"
58-
))]
50+
#[cfg(any(linux_android, freebsdlike, netbsdlike, target_os = "macos"))]
5951
mod test_ptrace;
6052
#[cfg(linux_android)]
6153
mod test_timerfd;

test/sys/test_socket.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -556,12 +556,7 @@ mod recvfrom {
556556
}
557557
}
558558

559-
#[cfg(any(
560-
target_os = "linux",
561-
target_os = "android",
562-
target_os = "freebsd",
563-
target_os = "netbsd",
564-
))]
559+
#[cfg(any(linux_android, target_os = "freebsd", target_os = "netbsd"))]
565560
#[test]
566561
pub fn udp_sendmmsg() {
567562
use std::io::IoSlice;

test/sys/test_sockopt.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ fn test_so_tcp_maxseg() {
127127
// platforms keep it even lower. This might fail if you've tuned your initial MSS to be larger
128128
// than 700
129129
cfg_if! {
130-
if #[cfg(any(target_os = "android", target_os = "linux"))] {
130+
if #[cfg(linux_android)] {
131131
let segsize: u32 = 873;
132132
assert!(initial < segsize);
133133
setsockopt(&rsock, sockopt::TcpMaxSeg, &segsize).unwrap();
@@ -152,7 +152,7 @@ fn test_so_tcp_maxseg() {
152152
// Actual max segment size takes header lengths into account, max IPv4 options (60 bytes) + max
153153
// TCP options (40 bytes) are subtracted from the requested maximum as a lower boundary.
154154
cfg_if! {
155-
if #[cfg(any(target_os = "android", target_os = "linux"))] {
155+
if #[cfg(linux_android)] {
156156
assert!((segsize - 100) <= actual);
157157
assert!(actual <= segsize);
158158
} else {
@@ -177,7 +177,7 @@ fn test_so_type() {
177177

178178
/// getsockopt(_, sockopt::SockType) should gracefully handle unknown socket
179179
/// types. Regression test for https://github.com/nix-rust/nix/issues/1819
180-
#[cfg(any(target_os = "android", target_os = "linux",))]
180+
#[cfg(linux_android)]
181181
#[test]
182182
fn test_so_type_unknown() {
183183
use nix::errno::Errno;
@@ -254,12 +254,7 @@ fn test_so_tcp_keepalive() {
254254
setsockopt(&fd, sockopt::KeepAlive, &true).unwrap();
255255
assert!(getsockopt(&fd, sockopt::KeepAlive).unwrap());
256256

257-
#[cfg(any(
258-
target_os = "android",
259-
target_os = "dragonfly",
260-
target_os = "freebsd",
261-
target_os = "linux"
262-
))]
257+
#[cfg(any(linux_android, freebsdlike))]
263258
{
264259
let x = getsockopt(&fd, sockopt::TcpKeepIdle).unwrap();
265260
setsockopt(&fd, sockopt::TcpKeepIdle, &(x + 1)).unwrap();
@@ -303,7 +298,7 @@ fn test_get_mtu() {
303298
}
304299

305300
#[test]
306-
#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))]
301+
#[cfg(any(linux_android, target_os = "freebsd"))]
307302
fn test_ttl_opts() {
308303
let fd4 = socket(
309304
AddressFamily::Inet,
@@ -356,7 +351,7 @@ fn test_dontfrag_opts() {
356351
}
357352

358353
#[test]
359-
#[cfg(any(target_os = "android", apple_targets, target_os = "linux",))]
354+
#[cfg(any(linux_android, apple_targets))]
360355
// Disable the test under emulation because it fails in Cirrus-CI. Lack
361356
// of QEMU support is suspected.
362357
#[cfg_attr(qemu, ignore)]

test/test.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ mod test_fcntl;
1111
#[cfg(linux_android)]
1212
mod test_kmod;
1313
#[cfg(any(
14-
target_os = "dragonfly",
15-
target_os = "freebsd",
14+
freebsdlike,
1615
target_os = "fushsia",
1716
target_os = "linux",
1817
target_os = "netbsd"
@@ -32,19 +31,12 @@ mod test_poll;
3231
mod test_pty;
3332
mod test_resource;
3433
#[cfg(any(
35-
target_os = "android",
34+
linux_android,
3635
target_os = "dragonfly",
3736
all(target_os = "freebsd", fbsd14),
38-
target_os = "linux"
3937
))]
4038
mod test_sched;
41-
#[cfg(any(
42-
target_os = "android",
43-
target_os = "dragonfly",
44-
target_os = "freebsd",
45-
apple_targets,
46-
target_os = "linux",
47-
))]
39+
#[cfg(any(linux_android, freebsdlike, apple_targets))]
4840
mod test_sendfile;
4941
mod test_stat;
5042
mod test_time;

test/test_fcntl.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,9 @@ fn test_readlink() {
234234
/// The from_offset should be updated by the call to reflect
235235
/// the 3 bytes read (6).
236236
#[cfg(any(
237-
target_os = "linux",
237+
linux_android,
238238
// Not available until FreeBSD 13.0
239239
all(target_os = "freebsd", fbsd14),
240-
target_os = "android"
241240
))]
242241
#[test]
243242
// QEMU does not support copy_file_range. Skip under qemu
@@ -473,8 +472,7 @@ mod linux_android {
473472
}
474473

475474
#[cfg(any(
476-
target_os = "linux",
477-
target_os = "android",
475+
linux_android,
478476
target_os = "emscripten",
479477
target_os = "fuchsia",
480478
target_os = "wasi",
@@ -511,13 +509,11 @@ mod test_posix_fadvise {
511509
}
512510

513511
#[cfg(any(
514-
target_os = "linux",
515-
target_os = "android",
516-
target_os = "dragonfly",
512+
linux_android,
513+
freebsdlike,
517514
target_os = "emscripten",
518515
target_os = "fuchsia",
519516
target_os = "wasi",
520-
target_os = "freebsd"
521517
))]
522518
mod test_posix_fallocate {
523519

test/test_net.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@ use nix::net::if_::*;
33
#[cfg(linux_android)]
44
const LOOPBACK: &[u8] = b"lo";
55

6-
#[cfg(not(any(
7-
target_os = "android",
8-
target_os = "linux",
9-
target_os = "haiku"
10-
)))]
6+
#[cfg(not(any(linux_android, target_os = "haiku")))]
117
const LOOPBACK: &[u8] = b"lo0";
128

139
#[cfg(target_os = "haiku")]

test/test_poll.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,7 @@ fn test_poll() {
3838
// ppoll(2) is the same as poll except for how it handles timeouts and signals.
3939
// Repeating the test for poll(2) should be sufficient to check that our
4040
// bindings are correct.
41-
#[cfg(any(
42-
target_os = "android",
43-
target_os = "dragonfly",
44-
target_os = "freebsd",
45-
target_os = "linux"
46-
))]
41+
#[cfg(any(linux_android, freebsdlike))]
4742
#[test]
4843
fn test_ppoll() {
4944
use nix::poll::ppoll;

test/test_sendfile.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,10 @@ use nix::sys::sendfile::*;
55
use tempfile::tempfile;
66

77
cfg_if! {
8-
if #[cfg(any(target_os = "android", target_os = "linux"))] {
8+
if #[cfg(linux_android)] {
99
use nix::unistd::{pipe, read};
1010
use std::os::unix::io::AsRawFd;
11-
} else if #[cfg(any(
12-
target_os = "dragonfly",
13-
target_os = "freebsd",
14-
apple_targets,
15-
))] {
11+
} else if #[cfg(any(freebsdlike, apple_targets))] {
1612
use std::net::Shutdown;
1713
use std::os::unix::net::UnixStream;
1814
}

test/test_stat.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,7 @@ fn test_mkdirat_fail() {
361361

362362
#[test]
363363
#[cfg(not(any(
364-
target_os = "dragonfly",
365-
target_os = "freebsd",
364+
freebsdlike,
366365
apple_targets,
367366
target_os = "haiku",
368367
target_os = "redox"
@@ -381,8 +380,7 @@ fn test_mknod() {
381380

382381
#[test]
383382
#[cfg(not(any(
384-
target_os = "dragonfly",
385-
target_os = "freebsd",
383+
freebsdlike,
386384
target_os = "illumos",
387385
apple_targets,
388386
target_os = "haiku",

test/test_time.rs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
#[cfg(any(
2-
target_os = "freebsd",
3-
target_os = "dragonfly",
4-
target_os = "linux",
5-
target_os = "android",
6-
target_os = "emscripten",
7-
))]
1+
#[cfg(any(freebsdlike, linux_android, target_os = "emscripten"))]
82
use nix::time::clock_getcpuclockid;
93
use nix::time::{clock_gettime, ClockId};
104

@@ -19,13 +13,7 @@ pub fn test_clock_gettime() {
1913
clock_gettime(ClockId::CLOCK_REALTIME).expect("assertion failed");
2014
}
2115

22-
#[cfg(any(
23-
target_os = "freebsd",
24-
target_os = "dragonfly",
25-
target_os = "linux",
26-
target_os = "android",
27-
target_os = "emscripten",
28-
))]
16+
#[cfg(any(freebsdlike, linux_android, target_os = "emscripten"))]
2917
#[test]
3018
pub fn test_clock_getcpuclockid() {
3119
let clock_id = clock_getcpuclockid(nix::unistd::Pid::this()).unwrap();
@@ -43,13 +31,7 @@ pub fn test_clock_id_now() {
4331
ClockId::CLOCK_REALTIME.now().unwrap();
4432
}
4533

46-
#[cfg(any(
47-
target_os = "freebsd",
48-
target_os = "dragonfly",
49-
target_os = "linux",
50-
target_os = "android",
51-
target_os = "emscripten",
52-
))]
34+
#[cfg(any(freebsdlike, linux_android, target_os = "emscripten"))]
5335
#[test]
5436
pub fn test_clock_id_pid_cpu_clock_id() {
5537
ClockId::pid_cpu_clock_id(nix::unistd::Pid::this())

test/test_unistd.rs

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -399,18 +399,15 @@ cfg_if! {
399399
if #[cfg(target_os = "android")] {
400400
execve_test_factory!(test_execve, execve, CString::new("/system/bin/sh").unwrap().as_c_str());
401401
execve_test_factory!(test_fexecve, fexecve, File::open("/system/bin/sh").unwrap().into_raw_fd());
402-
} else if #[cfg(any(target_os = "dragonfly",
403-
target_os = "freebsd",
404-
target_os = "linux"))] {
402+
} else if #[cfg(any(freebsdlike, target_os = "linux"))] {
405403
// These tests frequently fail on musl, probably due to
406404
// https://github.com/nix-rust/nix/issues/555
407405
execve_test_factory!(test_execve, execve, CString::new("/bin/sh").unwrap().as_c_str());
408406
execve_test_factory!(test_fexecve, fexecve, File::open("/bin/sh").unwrap().into_raw_fd());
409-
} else if #[cfg(any(target_os = "illumos",
407+
} else if #[cfg(any(solarish,
410408
apple_targets,
411409
target_os = "netbsd",
412-
target_os = "openbsd",
413-
target_os = "solaris"))] {
410+
target_os = "openbsd"))] {
414411
execve_test_factory!(test_execve, execve, CString::new("/bin/sh").unwrap().as_c_str());
415412
// No fexecve() on ios, macos, NetBSD, OpenBSD.
416413
}
@@ -573,7 +570,7 @@ fn test_lseek64() {
573570
}
574571

575572
cfg_if! {
576-
if #[cfg(any(target_os = "android", target_os = "linux"))] {
573+
if #[cfg(linux_android)] {
577574
macro_rules! require_acct{
578575
() => {
579576
require_capability!("test_acct", CAP_SYS_PACCT);
@@ -672,13 +669,7 @@ fn test_sysconf_unsupported() {
672669
assert!(open_max.expect("sysconf failed").is_none())
673670
}
674671

675-
#[cfg(any(
676-
target_os = "android",
677-
target_os = "dragonfly",
678-
target_os = "freebsd",
679-
target_os = "linux",
680-
target_os = "openbsd"
681-
))]
672+
#[cfg(any(linux_android, freebsdlike, target_os = "openbsd"))]
682673
#[test]
683674
fn test_getresuid() {
684675
let resuids = getresuid().unwrap();
@@ -687,13 +678,7 @@ fn test_getresuid() {
687678
assert_ne!(resuids.saved.as_raw(), libc::uid_t::MAX);
688679
}
689680

690-
#[cfg(any(
691-
target_os = "android",
692-
target_os = "dragonfly",
693-
target_os = "freebsd",
694-
target_os = "linux",
695-
target_os = "openbsd"
696-
))]
681+
#[cfg(any(linux_android, freebsdlike, target_os = "openbsd"))]
697682
#[test]
698683
fn test_getresgid() {
699684
let resgids = getresgid().unwrap();
@@ -721,16 +706,12 @@ fn test_pipe() {
721706
// pipe2(2) is the same as pipe(2), except it allows setting some flags. Check
722707
// that we can set a flag.
723708
#[cfg(any(
724-
target_os = "android",
725-
target_os = "dragonfly",
709+
linux_android,
710+
freebsdlike,
711+
solarish,
712+
netbsdlike,
726713
target_os = "emscripten",
727-
target_os = "freebsd",
728-
target_os = "illumos",
729-
target_os = "linux",
730-
target_os = "netbsd",
731-
target_os = "openbsd",
732714
target_os = "redox",
733-
target_os = "solaris"
734715
))]
735716
#[test]
736717
fn test_pipe2() {
@@ -1327,11 +1308,7 @@ fn test_faccessat_file_exists() {
13271308
}
13281309

13291310
#[test]
1330-
#[cfg(any(
1331-
all(target_os = "linux", not(target_env = "uclibc")),
1332-
target_os = "freebsd",
1333-
target_os = "dragonfly"
1334-
))]
1311+
#[cfg(any(all(target_os = "linux", not(target_env = "uclibc")), freebsdlike))]
13351312
fn test_eaccess_not_existing() {
13361313
let tempdir = tempdir().unwrap();
13371314
let dir = tempdir.path().join("does_not_exist.txt");
@@ -1342,11 +1319,7 @@ fn test_eaccess_not_existing() {
13421319
}
13431320

13441321
#[test]
1345-
#[cfg(any(
1346-
all(target_os = "linux", not(target_env = "uclibc")),
1347-
target_os = "freebsd",
1348-
target_os = "dragonfly"
1349-
))]
1322+
#[cfg(any(all(target_os = "linux", not(target_env = "uclibc")), freebsdlike))]
13501323
fn test_eaccess_file_exists() {
13511324
let tempdir = tempdir().unwrap();
13521325
let path = tempdir.path().join("does_exist.txt");

0 commit comments

Comments
 (0)