diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/sys/test_ioctl.rs | 16 | ||||
-rw-r--r-- | test/sys/test_signal.rs | 11 | ||||
-rw-r--r-- | test/sys/test_socket.rs | 47 | ||||
-rw-r--r-- | test/sys/test_sockopt.rs | 2 | ||||
-rw-r--r-- | test/sys/test_uio.rs | 2 | ||||
-rw-r--r-- | test/sys/test_wait.rs | 2 | ||||
-rw-r--r-- | test/test_net.rs | 2 | ||||
-rw-r--r-- | test/test_stat.rs | 14 | ||||
-rw-r--r-- | test/test_unistd.rs | 2 |
9 files changed, 39 insertions, 59 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") { diff --git a/test/test_net.rs b/test/test_net.rs index b8940e71..40ecd6bb 100644 --- a/test/test_net.rs +++ b/test/test_net.rs @@ -8,5 +8,5 @@ const LOOPBACK: &[u8] = b"lo0"; #[test] fn test_if_nametoindex() { - assert!(if_nametoindex(&LOOPBACK[..]).is_ok()); + assert!(if_nametoindex(LOOPBACK).is_ok()); } diff --git a/test/test_stat.rs b/test/test_stat.rs index 98112d61..27fcee59 100644 --- a/test/test_stat.rs +++ b/test/test_stat.rs @@ -44,18 +44,6 @@ use nix::unistd::chdir; #[cfg(not(any(target_os = "netbsd", target_os = "redox")))] use nix::Result; -use tempfile; - -#[allow(unused_comparisons)] -// uid and gid are signed on Windows, but not on other platforms. This function -// allows warning free compiles on all platforms, and can be removed when -// expression-level #[allow] is available. -#[cfg(not(any(target_os = "netbsd", target_os = "redox")))] -fn valid_uid_gid(stat: FileStat) -> bool { - // uid could be 0 for the `root` user. This quite possible when - // the tests are being run on a rooted Android device. - stat.st_uid >= 0 && stat.st_gid >= 0 -} #[cfg(not(any(target_os = "netbsd", target_os = "redox")))] fn assert_stat_results(stat_result: Result<FileStat>) { @@ -64,7 +52,6 @@ fn assert_stat_results(stat_result: Result<FileStat>) { assert!(stats.st_ino > 0); // inode is positive integer, exact number machine dependent assert!(stats.st_mode > 0); // must be positive integer assert_eq!(stats.st_nlink, 1); // there links created, must be 1 - assert!(valid_uid_gid(stats)); // must be positive integers assert_eq!(stats.st_size, 0); // size is 0 because we did not write anything to the file assert!(stats.st_blksize > 0); // must be positive integer, exact number machine dependent assert!(stats.st_blocks <= 16); // Up to 16 blocks can be allocated for a blank file @@ -84,7 +71,6 @@ fn assert_lstat_results(stat_result: Result<FileStat>) { // On other platforms they are the same (either both are u16 or u32). assert_eq!((stats.st_mode as usize) & (S_IFMT as usize), S_IFLNK as usize); // should be a link assert_eq!(stats.st_nlink, 1); // there links created, must be 1 - assert!(valid_uid_gid(stats)); // must be positive integers assert!(stats.st_size > 0); // size is > 0 because it points to another file assert!(stats.st_blksize > 0); // must be positive integer, exact number machine dependent diff --git a/test/test_unistd.rs b/test/test_unistd.rs index eb811e2d..73341947 100644 --- a/test/test_unistd.rs +++ b/test/test_unistd.rs @@ -441,7 +441,7 @@ fn test_getcwd() { // kicks in. Note: One path cannot be longer than 255 bytes // (NAME_MAX) whole path cannot be longer than PATH_MAX (usually // 4096 on linux, 1024 on macos) - let mut inner_tmp_dir = tmpdir_path.to_path_buf(); + let mut inner_tmp_dir = tmpdir_path; for _ in 0..5 { let newdir = iter::repeat("a").take(100).collect::<String>(); inner_tmp_dir.push(newdir); |