Skip to content

Commit 6961f0f

Browse files
authored
refactor: cfg for test/* (#2230)
* refactor: cfg for test/* * one more netbsdlike * more cfg
1 parent 2ab5558 commit 6961f0f

12 files changed

+48
-175
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: 11 additions & 48 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;
@@ -623,12 +618,7 @@ mod recvfrom {
623618
assert_eq!(AddressFamily::Inet, from.unwrap().family().unwrap());
624619
}
625620

626-
#[cfg(any(
627-
target_os = "linux",
628-
target_os = "android",
629-
target_os = "freebsd",
630-
target_os = "netbsd",
631-
))]
621+
#[cfg(any(linux_android, target_os = "freebsd", target_os = "netbsd"))]
632622
#[test]
633623
pub fn udp_recvmmsg() {
634624
use nix::sys::socket::{recvmmsg, MsgFlags};
@@ -704,12 +694,7 @@ mod recvfrom {
704694
send_thread.join().unwrap();
705695
}
706696

707-
#[cfg(any(
708-
target_os = "linux",
709-
target_os = "android",
710-
target_os = "freebsd",
711-
target_os = "netbsd",
712-
))]
697+
#[cfg(any(linux_android, target_os = "freebsd", target_os = "netbsd"))]
713698
#[test]
714699
pub fn udp_recvmmsg_dontwait_short_read() {
715700
use nix::sys::socket::{recvmmsg, MsgFlags};
@@ -1275,12 +1260,7 @@ pub fn test_sendmsg_ipv6packetinfo() {
12751260
//
12761261
// Note that binding to 0.0.0.0 is *required* on FreeBSD; sendmsg
12771262
// returns EINVAL otherwise. (See FreeBSD's ip(4) man page.)
1278-
#[cfg(any(
1279-
target_os = "netbsd",
1280-
target_os = "freebsd",
1281-
target_os = "openbsd",
1282-
target_os = "dragonfly",
1283-
))]
1263+
#[cfg(any(freebsdlike, netbsdlike))]
12841264
#[test]
12851265
pub fn test_sendmsg_ipv4sendsrcaddr() {
12861266
use nix::sys::socket::{
@@ -1429,12 +1409,7 @@ pub fn test_sendmsg_empty_cmsgs() {
14291409
}
14301410
}
14311411

1432-
#[cfg(any(
1433-
target_os = "android",
1434-
target_os = "linux",
1435-
target_os = "freebsd",
1436-
target_os = "dragonfly",
1437-
))]
1412+
#[cfg(any(linux_android, freebsdlike))]
14381413
#[test]
14391414
fn test_scm_credentials() {
14401415
use nix::sys::socket::{
@@ -1777,12 +1752,7 @@ fn loopback_address(
17771752
})
17781753
}
17791754

1780-
#[cfg(any(
1781-
target_os = "android",
1782-
apple_targets,
1783-
target_os = "linux",
1784-
target_os = "netbsd",
1785-
))]
1755+
#[cfg(any(linux_android, apple_targets, target_os = "netbsd"))]
17861756
// qemu doesn't seem to be emulating this correctly in these architectures
17871757
#[cfg_attr(
17881758
all(
@@ -1987,7 +1957,7 @@ pub fn test_recvif() {
19871957
}
19881958
}
19891959

1990-
#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))]
1960+
#[cfg(any(linux_android, target_os = "freebsd"))]
19911961
#[cfg_attr(qemu, ignore)]
19921962
#[test]
19931963
pub fn test_recvif_ipv4() {
@@ -2073,7 +2043,7 @@ pub fn test_recvif_ipv4() {
20732043
}
20742044
}
20752045

2076-
#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))]
2046+
#[cfg(any(linux_android, target_os = "freebsd"))]
20772047
#[cfg_attr(qemu, ignore)]
20782048
#[test]
20792049
pub fn test_recvif_ipv6() {
@@ -2159,14 +2129,7 @@ pub fn test_recvif_ipv6() {
21592129
}
21602130
}
21612131

2162-
#[cfg(any(
2163-
target_os = "android",
2164-
target_os = "freebsd",
2165-
apple_targets,
2166-
target_os = "linux",
2167-
target_os = "netbsd",
2168-
target_os = "openbsd",
2169-
))]
2132+
#[cfg(any(linux_android, target_os = "freebsd", apple_targets, netbsdlike))]
21702133
// qemu doesn't seem to be emulating this correctly in these architectures
21712134
#[cfg_attr(
21722135
all(
@@ -2463,7 +2426,7 @@ fn test_recvmmsg_timestampns() {
24632426
// Disable the test on emulated platforms because it fails in Cirrus-CI. Lack
24642427
// of QEMU support is suspected.
24652428
#[cfg_attr(qemu, ignore)]
2466-
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
2429+
#[cfg(any(linux_android, target_os = "fuchsia"))]
24672430
#[test]
24682431
fn test_recvmsg_rxq_ovfl() {
24692432
use nix::sys::socket::sockopt::{RcvBuf, RxqOvfl};
@@ -2557,7 +2520,7 @@ fn test_recvmsg_rxq_ovfl() {
25572520
assert_eq!(drop_counter, 1);
25582521
}
25592522

2560-
#[cfg(any(target_os = "linux", target_os = "android",))]
2523+
#[cfg(linux_android)]
25612524
mod linux_errqueue {
25622525
use super::FromStr;
25632526
use nix::sys::socket::*;

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"

0 commit comments

Comments
 (0)