summaryrefslogtreecommitdiff
path: root/test/sys
diff options
context:
space:
mode:
authorAlan Somers <asomers@gmail.com>2021-05-30 12:27:39 -0600
committerAlan Somers <asomers@gmail.com>2021-05-30 20:12:41 -0600
commit7b7d9540056f6378820caf955a0335268184d6b7 (patch)
treef27fa7b8dbb4d089c0f7bda9569bfab8ead1b4dc /test/sys
parenta55dd4537286c8fbd96e3e21e18c56a38f8124b9 (diff)
downloadnix-7b7d9540056f6378820caf955a0335268184d6b7.zip
misc Clippy cleanup
* Fix race conditions in the tests. Two tests were grabbing a mutex but immediately dropping it. Thank you, Clippy. * Remove vestigial Windows support. Remove some code added to support Windows in 2015. Nix is no longer intended to ever run on Windows. * Various other minor Clippy lints.
Diffstat (limited to 'test/sys')
-rw-r--r--test/sys/test_ioctl.rs16
-rw-r--r--test/sys/test_signal.rs11
-rw-r--r--test/sys/test_socket.rs47
-rw-r--r--test/sys/test_sockopt.rs2
-rw-r--r--test/sys/test_uio.rs2
-rw-r--r--test/sys/test_wait.rs2
6 files changed, 37 insertions, 43 deletions
diff --git a/test/sys/test_ioctl.rs b/test/sys/test_ioctl.rs
index fa4510a6..ddb86968 100644
--- a/test/sys/test_ioctl.rs
+++ b/test/sys/test_ioctl.rs
@@ -56,10 +56,10 @@ mod linux {
#[test]
fn test_op_write_64() {
if cfg!(any(target_arch = "mips64", target_arch="powerpc64")){
- assert_eq!(request_code_write!(b'z', 10, (1 as u64) << 32) as u32,
+ assert_eq!(request_code_write!(b'z', 10, 1u64 << 32) as u32,
0x8000_7A0A);
} else {
- assert_eq!(request_code_write!(b'z', 10, (1 as u64) << 32) as u32,
+ assert_eq!(request_code_write!(b'z', 10, 1u64 << 32) as u32,
0x4000_7A0A);
}
@@ -80,10 +80,10 @@ mod linux {
#[test]
fn test_op_read_64() {
if cfg!(any(target_arch = "mips64", target_arch="powerpc64")){
- assert_eq!(request_code_read!(b'z', 10, (1 as u64) << 32) as u32,
+ assert_eq!(request_code_read!(b'z', 10, 1u64 << 32) as u32,
0x4000_7A0A);
} else {
- assert_eq!(request_code_read!(b'z', 10, (1 as u64) << 32) as u32,
+ assert_eq!(request_code_read!(b'z', 10, 1u64 << 32) as u32,
0x8000_7A0A);
}
}
@@ -97,7 +97,7 @@ mod linux {
#[cfg(target_pointer_width = "64")]
#[test]
fn test_op_read_write_64() {
- assert_eq!(request_code_readwrite!(b'z', 10, (1 as u64) << 32) as u32,
+ assert_eq!(request_code_readwrite!(b'z', 10, 1u64 << 32) as u32,
0xC000_7A0A);
}
}
@@ -131,7 +131,7 @@ mod bsd {
#[cfg(target_pointer_width = "64")]
#[test]
fn test_op_write_64() {
- assert_eq!(request_code_write!(b'z', 10, (1 as u64) << 32), 0x8000_7A0A);
+ assert_eq!(request_code_write!(b'z', 10, 1u64 << 32), 0x8000_7A0A);
}
#[test]
@@ -143,7 +143,7 @@ mod bsd {
#[cfg(target_pointer_width = "64")]
#[test]
fn test_op_read_64() {
- assert_eq!(request_code_read!(b'z', 10, (1 as u64) << 32), 0x4000_7A0A);
+ assert_eq!(request_code_read!(b'z', 10, 1u64 << 32), 0x4000_7A0A);
}
#[test]
@@ -155,7 +155,7 @@ mod bsd {
#[cfg(target_pointer_width = "64")]
#[test]
fn test_op_read_write_64() {
- assert_eq!(request_code_readwrite!(b'z', 10, (1 as u64) << 32), 0xC000_7A0A);
+ assert_eq!(request_code_readwrite!(b'z', 10, 1u64 << 32), 0xC000_7A0A);
}
}
diff --git a/test/sys/test_signal.rs b/test/sys/test_signal.rs
index fdb7f36d..c8c13e52 100644
--- a/test/sys/test_signal.rs
+++ b/test/sys/test_signal.rs
@@ -1,4 +1,3 @@
-use libc;
#[cfg(not(target_os = "redox"))]
use nix::Error;
use nix::sys::signal::*;
@@ -53,9 +52,9 @@ fn test_sigprocmask() {
// Make sure the old set doesn't contain the signal, otherwise the following
// test don't make sense.
- assert_eq!(old_signal_set.contains(SIGNAL), false,
- "the {:?} signal is already blocked, please change to a \
- different one", SIGNAL);
+ assert!(!old_signal_set.contains(SIGNAL),
+ "the {:?} signal is already blocked, please change to a \
+ different one", SIGNAL);
// Now block the signal.
let mut signal_set = SigSet::empty();
@@ -67,8 +66,8 @@ fn test_sigprocmask() {
old_signal_set.clear();
sigprocmask(SigmaskHow::SIG_BLOCK, None, Some(&mut old_signal_set))
.expect("expect to be able to retrieve old signals");
- assert_eq!(old_signal_set.contains(SIGNAL), true,
- "expected the {:?} to be blocked", SIGNAL);
+ assert!(old_signal_set.contains(SIGNAL),
+ "expected the {:?} to be blocked", SIGNAL);
// Reset the signal.
sigprocmask(SigmaskHow::SIG_UNBLOCK, Some(&signal_set), None)
diff --git a/test/sys/test_socket.rs b/test/sys/test_socket.rs
index 32318ef0..c22eaeb1 100644
--- a/test/sys/test_socket.rs
+++ b/test/sys/test_socket.rs
@@ -7,7 +7,6 @@ use std::path::Path;
use std::slice;
use std::str::FromStr;
use libc::c_char;
-use tempfile;
#[cfg(any(target_os = "linux", target_os= "android"))]
use crate::*;
@@ -81,7 +80,7 @@ pub fn test_addr_equality_path() {
let path = "/foo/bar";
let actual = Path::new(path);
let addr1 = UnixAddr::new(actual).unwrap();
- let mut addr2 = addr1.clone();
+ let mut addr2 = addr1;
addr2.0.sun_path[10] = 127;
@@ -168,7 +167,7 @@ mod recvfrom {
use std::thread;
use super::*;
- const MSG: &'static [u8] = b"Hello, World!";
+ const MSG: &[u8] = b"Hello, World!";
fn sendrecv<Fs, Fr>(rsock: RawFd, ssock: RawFd, f_send: Fs, mut f_recv: Fr) -> Option<SockAddr>
where
@@ -318,6 +317,7 @@ mod recvfrom {
target_os = "freebsd",
target_os = "netbsd",
))]
+ #[allow(clippy::vec_init_then_push)]
#[test]
pub fn udp_sendmmsg() {
use nix::sys::uio::IoVec;
@@ -367,7 +367,7 @@ mod recvfrom {
}
sendmmsg(s, msgs.iter(), flags)
.map(move |sent_bytes| {
- assert!(sent_bytes.len() >= 1);
+ assert!(!sent_bytes.is_empty());
for sent in &sent_bytes {
assert_eq!(*sent, m.len());
}
@@ -425,7 +425,7 @@ mod recvfrom {
for iov in &iovs {
msgs.push_back(RecvMmsgData {
- iov: iov,
+ iov,
cmsg_buffer: None,
})
};
@@ -497,7 +497,7 @@ mod recvfrom {
for iov in &iovs {
msgs.push_back(RecvMmsgData {
- iov: iov,
+ iov,
cmsg_buffer: None,
})
};
@@ -835,12 +835,9 @@ pub fn test_sendmsg_ipv6packetinfo() {
let inet_addr = InetAddr::from_std(&std_sa);
let sock_addr = SockAddr::new_inet(inet_addr);
- match bind(sock, &sock_addr) {
- Err(Error::Sys(Errno::EADDRNOTAVAIL)) => {
- println!("IPv6 not available, skipping test.");
- return;
- },
- _ => (),
+ if let Err(Error::Sys(Errno::EADDRNOTAVAIL)) = bind(sock, &sock_addr) {
+ println!("IPv6 not available, skipping test.");
+ return;
}
let slice = [1u8, 2, 3, 4, 5, 6, 7, 8];
@@ -1399,8 +1396,8 @@ pub fn test_recvif() {
_ => panic!("unexpected additional control msg"),
}
}
- assert_eq!(rx_recvif, true);
- assert_eq!(rx_recvdstaddr, true);
+ assert!(rx_recvif);
+ assert!(rx_recvdstaddr);
assert_eq!(msg.bytes, 8);
assert_eq!(
iovec[0].as_slice(),
@@ -1479,18 +1476,16 @@ pub fn test_recv_ipv6pktinfo() {
);
let mut cmsgs = msg.cmsgs();
- match cmsgs.next() {
- Some(ControlMessageOwned::Ipv6PacketInfo(pktinfo)) => {
- let i = if_nametoindex(lo_name.as_bytes()).expect("if_nametoindex");
- assert_eq!(
- pktinfo.ipi6_ifindex as libc::c_uint,
- i,
- "unexpected ifindex (expected {}, got {})",
- i,
- pktinfo.ipi6_ifindex
- );
- },
- _ => (),
+ if let Some(ControlMessageOwned::Ipv6PacketInfo(pktinfo)) = cmsgs.next()
+ {
+ let i = if_nametoindex(lo_name.as_bytes()).expect("if_nametoindex");
+ assert_eq!(
+ pktinfo.ipi6_ifindex as libc::c_uint,
+ i,
+ "unexpected ifindex (expected {}, got {})",
+ i,
+ pktinfo.ipi6_ifindex
+ );
}
assert!(cmsgs.next().is_none(), "unexpected additional control msg");
assert_eq!(msg.bytes, 8);
diff --git a/test/sys/test_sockopt.rs b/test/sys/test_sockopt.rs
index d151cf55..e0ed0f7c 100644
--- a/test/sys/test_sockopt.rs
+++ b/test/sys/test_sockopt.rs
@@ -74,7 +74,7 @@ fn test_bindtodevice() {
fn test_so_tcp_keepalive() {
let fd = socket(AddressFamily::Inet, SockType::Stream, SockFlag::empty(), SockProtocol::Tcp).unwrap();
setsockopt(fd, sockopt::KeepAlive, &true).unwrap();
- assert_eq!(getsockopt(fd, sockopt::KeepAlive).unwrap(), true);
+ assert!(getsockopt(fd, sockopt::KeepAlive).unwrap());
#[cfg(any(target_os = "android",
target_os = "dragonfly",
diff --git a/test/sys/test_uio.rs b/test/sys/test_uio.rs
index aede530a..9dd4f01d 100644
--- a/test/sys/test_uio.rs
+++ b/test/sys/test_uio.rs
@@ -214,7 +214,7 @@ fn test_process_vm_readv() {
use crate::*;
require_capability!(CAP_SYS_PTRACE);
- let _ = crate::FORK_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = crate::FORK_MTX.lock().expect("Mutex got poisoned by another test");
// Pre-allocate memory in the child, since allocation isn't safe
// post-fork (~= async-signal-safe)
diff --git a/test/sys/test_wait.rs b/test/sys/test_wait.rs
index 5bb298eb..f68b8b08 100644
--- a/test/sys/test_wait.rs
+++ b/test/sys/test_wait.rs
@@ -8,7 +8,7 @@ use libc::_exit;
#[test]
#[cfg(not(target_os = "redox"))]
fn test_wait_signal() {
- let _ = crate::FORK_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = crate::FORK_MTX.lock().expect("Mutex got poisoned by another test");
// Safe: The child only calls `pause` and/or `_exit`, which are async-signal-safe.
match unsafe{fork()}.expect("Error: Fork Failed") {