Skip to content

Commit 2e7a140

Browse files
committed
refactor: cfg for test/*
1 parent 2ab5558 commit 2e7a140

File tree

12 files changed

+38
-130
lines changed

12 files changed

+38
-130
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: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,8 @@ mod test_fanotify;
4848
#[cfg(target_os = "linux")]
4949
mod test_inotify;
5050
mod test_pthread;
51-
#[cfg(any(
52-
target_os = "android",
53-
target_os = "dragonfly",
54-
target_os = "freebsd",
55-
target_os = "linux",
56-
apple_targets,
57-
target_os = "netbsd",
58-
target_os = "openbsd"
59-
))]
51+
52+
#[cfg(any(linux_android, freebsdlike, netbsdlike, apple_targets))]
6053
mod test_ptrace;
6154
#[cfg(linux_android)]
6255
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,
@@ -369,7 +364,7 @@ fn test_dontfrag_opts() {
369364
}
370365

371366
#[test]
372-
#[cfg(any(target_os = "android", apple_targets, target_os = "linux",))]
367+
#[cfg(any(linux_android, apple_targets))]
373368
// Disable the test under emulation because it fails in Cirrus-CI. Lack
374369
// of QEMU support is suspected.
375370
#[cfg_attr(qemu, ignore)]

test/test.rs

Lines changed: 3 additions & 12 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,20 +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-
solarish
48-
))]
39+
#[cfg(any(linux_android, freebsdlike, apple_targets, solarish))]
4940
mod test_sendfile;
5041
mod test_stat;
5142
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 & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +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-
solarish
16-
))] {
11+
} else if #[cfg(any(freebsdlike, apple_targets, solarish))] {
1712
use std::net::Shutdown;
1813
use std::os::unix::net::UnixStream;
1914
}

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,9 +380,8 @@ fn test_mknod() {
381380

382381
#[test]
383382
#[cfg(not(any(
384-
target_os = "dragonfly",
385-
target_os = "freebsd",
386383
solarish,
384+
freebsdlike,
387385
apple_targets,
388386
target_os = "haiku",
389387
target_os = "redox"

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: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -430,19 +430,15 @@ cfg_if! {
430430
if #[cfg(target_os = "android")] {
431431
execve_test_factory!(test_execve, execve, CString::new("/system/bin/sh").unwrap().as_c_str());
432432
execve_test_factory!(test_fexecve, fexecve, File::open("/system/bin/sh").unwrap().into_raw_fd());
433-
} else if #[cfg(any(target_os = "dragonfly",
434-
target_os = "freebsd",
435-
target_os = "hurd",
436-
target_os = "linux"))] {
433+
} else if #[cfg(any(freebsdlike, target_os = "linux", target_os = "hurd"))] {
437434
// These tests frequently fail on musl, probably due to
438435
// https://github.com/nix-rust/nix/issues/555
439436
execve_test_factory!(test_execve, execve, CString::new("/bin/sh").unwrap().as_c_str());
440437
execve_test_factory!(test_fexecve, fexecve, File::open("/bin/sh").unwrap().into_raw_fd());
441438
} else if #[cfg(any(solarish,
442439
apple_targets,
443440
target_os = "netbsd",
444-
target_os = "openbsd",
445-
target_os = "solaris"))] {
441+
target_os = "openbsd"))] {
446442
execve_test_factory!(test_execve, execve, CString::new("/bin/sh").unwrap().as_c_str());
447443
// No fexecve() on ios, macos, NetBSD, OpenBSD.
448444
}
@@ -610,7 +606,7 @@ fn test_lseek64() {
610606
}
611607

612608
cfg_if! {
613-
if #[cfg(any(target_os = "android", target_os = "linux"))] {
609+
if #[cfg(linux_android)] {
614610
macro_rules! require_acct{
615611
() => {
616612
require_capability!("test_acct", CAP_SYS_PACCT);
@@ -712,13 +708,7 @@ fn test_sysconf_unsupported() {
712708
assert!(open_max.expect("sysconf failed").is_none())
713709
}
714710

715-
#[cfg(any(
716-
target_os = "android",
717-
target_os = "dragonfly",
718-
target_os = "freebsd",
719-
target_os = "linux",
720-
target_os = "openbsd"
721-
))]
711+
#[cfg(any(linux_android, freebsdlike, target_os = "openbsd"))]
722712
#[test]
723713
fn test_getresuid() {
724714
let resuids = getresuid().unwrap();
@@ -727,13 +717,7 @@ fn test_getresuid() {
727717
assert_ne!(resuids.saved.as_raw(), libc::uid_t::MAX);
728718
}
729719

730-
#[cfg(any(
731-
target_os = "android",
732-
target_os = "dragonfly",
733-
target_os = "freebsd",
734-
target_os = "linux",
735-
target_os = "openbsd"
736-
))]
720+
#[cfg(any(linux_android, freebsdlike, target_os = "openbsd"))]
737721
#[test]
738722
fn test_getresgid() {
739723
let resgids = getresgid().unwrap();
@@ -761,16 +745,12 @@ fn test_pipe() {
761745
// pipe2(2) is the same as pipe(2), except it allows setting some flags. Check
762746
// that we can set a flag.
763747
#[cfg(any(
764-
target_os = "android",
765-
target_os = "dragonfly",
766-
target_os = "emscripten",
767-
target_os = "freebsd",
748+
linux_android,
749+
freebsdlike,
768750
solarish,
769-
target_os = "linux",
770-
target_os = "netbsd",
771-
target_os = "openbsd",
751+
netbsdlike,
752+
target_os = "emscripten",
772753
target_os = "redox",
773-
target_os = "solaris"
774754
))]
775755
#[test]
776756
fn test_pipe2() {
@@ -1367,11 +1347,7 @@ fn test_faccessat_file_exists() {
13671347
}
13681348

13691349
#[test]
1370-
#[cfg(any(
1371-
all(target_os = "linux", not(target_env = "uclibc")),
1372-
target_os = "freebsd",
1373-
target_os = "dragonfly"
1374-
))]
1350+
#[cfg(any(all(target_os = "linux", not(target_env = "uclibc")), freebsdlike))]
13751351
fn test_eaccess_not_existing() {
13761352
let tempdir = tempdir().unwrap();
13771353
let dir = tempdir.path().join("does_not_exist.txt");
@@ -1382,11 +1358,7 @@ fn test_eaccess_not_existing() {
13821358
}
13831359

13841360
#[test]
1385-
#[cfg(any(
1386-
all(target_os = "linux", not(target_env = "uclibc")),
1387-
target_os = "freebsd",
1388-
target_os = "dragonfly"
1389-
))]
1361+
#[cfg(any(all(target_os = "linux", not(target_env = "uclibc")), freebsdlike))]
13901362
fn test_eaccess_file_exists() {
13911363
let tempdir = tempdir().unwrap();
13921364
let path = tempdir.path().join("does_exist.txt");

0 commit comments

Comments
 (0)