summaryrefslogtreecommitdiff
path: root/test/sys
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2017-12-20 15:07:44 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2017-12-20 15:07:44 +0000
commitdad777010547d04f32e21af131d223061f3821f2 (patch)
tree83caae312da5c8c4e2736f1e2da6e5382dc53e1d /test/sys
parent5d50acaa806b0b0cc6c04d26232fc6a6f10d18a3 (diff)
parent8db68be6ba9c25c0955f4febeb78b31030ba7603 (diff)
downloadnix-dad777010547d04f32e21af131d223061f3821f2.zip
Merge #818
818: Clippy cleanup r=Susurrus a=Susurrus Various fixes for errors and warnings pointed out by clippy.
Diffstat (limited to 'test/sys')
-rw-r--r--test/sys/test_aio.rs110
-rw-r--r--test/sys/test_aio_drop.rs4
-rw-r--r--test/sys/test_ioctl.rs74
-rw-r--r--test/sys/test_ptrace.rs17
-rw-r--r--test/sys/test_signal.rs2
-rw-r--r--test/sys/test_signalfd.rs2
-rw-r--r--test/sys/test_socket.rs2
-rw-r--r--test/sys/test_sockopt.rs2
-rw-r--r--test/sys/test_termios.rs2
-rw-r--r--test/sys/test_uio.rs19
-rw-r--r--test/sys/test_wait.rs25
11 files changed, 125 insertions, 134 deletions
diff --git a/test/sys/test_aio.rs b/test/sys/test_aio.rs
index 79a6b6c4..1f807585 100644
--- a/test/sys/test_aio.rs
+++ b/test/sys/test_aio.rs
@@ -49,12 +49,12 @@ fn test_accessors() {
#[test]
#[cfg_attr(all(target_env = "musl", target_arch = "x86_64"), ignore)]
fn test_cancel() {
- let wbuf: &'static [u8] = b"CDEF";
+ let wbuf: &[u8] = b"CDEF";
let f = tempfile().unwrap();
let mut aiocb = AioCb::from_slice( f.as_raw_fd(),
0, //offset
- &wbuf,
+ wbuf,
0, //priority
SigevNotify::SigevNone,
LioOpcode::LIO_NOP);
@@ -74,12 +74,12 @@ fn test_cancel() {
#[test]
#[cfg_attr(all(target_env = "musl", target_arch = "x86_64"), ignore)]
fn test_aio_cancel_all() {
- let wbuf: &'static [u8] = b"CDEF";
+ let wbuf: &[u8] = b"CDEF";
let f = tempfile().unwrap();
let mut aiocb = AioCb::from_slice(f.as_raw_fd(),
0, //offset
- &wbuf,
+ wbuf,
0, //priority
SigevNotify::SigevNone,
LioOpcode::LIO_NOP);
@@ -98,9 +98,9 @@ fn test_aio_cancel_all() {
#[test]
#[cfg_attr(all(target_env = "musl", target_arch = "x86_64"), ignore)]
fn test_fsync() {
- const INITIAL: &'static [u8] = b"abcdef123456";
+ const INITIAL: &[u8] = b"abcdef123456";
let mut f = tempfile().unwrap();
- f.write(INITIAL).unwrap();
+ f.write_all(INITIAL).unwrap();
let mut aiocb = AioCb::from_fd( f.as_raw_fd(),
0, //priority
SigevNotify::SigevNone);
@@ -119,11 +119,11 @@ fn test_fsync() {
fn test_fsync_error() {
use std::mem;
- const INITIAL: &'static [u8] = b"abcdef123456";
+ const INITIAL: &[u8] = b"abcdef123456";
// Create an invalid AioFsyncMode
let mode = unsafe { mem::transmute(666) };
let mut f = tempfile().unwrap();
- f.write(INITIAL).unwrap();
+ f.write_all(INITIAL).unwrap();
let mut aiocb = AioCb::from_fd( f.as_raw_fd(),
0, //priority
SigevNotify::SigevNone);
@@ -134,23 +134,23 @@ fn test_fsync_error() {
#[test]
#[cfg_attr(all(target_env = "musl", target_arch = "x86_64"), ignore)]
fn test_aio_suspend() {
- const INITIAL: &'static [u8] = b"abcdef123456";
- const WBUF: &'static [u8] = b"CDEF";
+ const INITIAL: &[u8] = b"abcdef123456";
+ const WBUF: &[u8] = b"CDEF";
let timeout = TimeSpec::seconds(10);
let rbuf = Rc::new(vec![0; 4].into_boxed_slice());
let mut f = tempfile().unwrap();
- f.write(INITIAL).unwrap();
+ f.write_all(INITIAL).unwrap();
let mut wcb = AioCb::from_slice( f.as_raw_fd(),
2, //offset
- &mut WBUF,
+ WBUF,
0, //priority
SigevNotify::SigevNone,
LioOpcode::LIO_WRITE);
let mut rcb = AioCb::from_boxed_slice( f.as_raw_fd(),
8, //offset
- rbuf.clone(),
+ Rc::clone(&rbuf),
0, //priority
SigevNotify::SigevNone,
LioOpcode::LIO_READ);
@@ -176,15 +176,15 @@ fn test_aio_suspend() {
#[test]
#[cfg_attr(all(target_env = "musl", target_arch = "x86_64"), ignore)]
fn test_read() {
- const INITIAL: &'static [u8] = b"abcdef123456";
+ const INITIAL: &[u8] = b"abcdef123456";
let rbuf = Rc::new(vec![0; 4].into_boxed_slice());
- const EXPECT: &'static [u8] = b"cdef";
+ const EXPECT: &[u8] = b"cdef";
let mut f = tempfile().unwrap();
- f.write(INITIAL).unwrap();
+ f.write_all(INITIAL).unwrap();
{
let mut aiocb = AioCb::from_boxed_slice( f.as_raw_fd(),
2, //offset
- rbuf.clone(),
+ Rc::clone(&rbuf),
0, //priority
SigevNotify::SigevNone,
LioOpcode::LIO_NOP);
@@ -205,13 +205,13 @@ fn test_read() {
#[test]
#[cfg(any(target_os = "freebsd", target_os = "macos"))]
fn test_read_error() {
- const INITIAL: &'static [u8] = b"abcdef123456";
+ const INITIAL: &[u8] = b"abcdef123456";
let rbuf = Rc::new(vec![0; 4].into_boxed_slice());
let mut f = tempfile().unwrap();
- f.write(INITIAL).unwrap();
+ f.write_all(INITIAL).unwrap();
let mut aiocb = AioCb::from_boxed_slice( f.as_raw_fd(),
-1, //an invalid offset
- rbuf.clone(),
+ Rc::clone(&rbuf),
0, //priority
SigevNotify::SigevNone,
LioOpcode::LIO_NOP);
@@ -222,11 +222,11 @@ fn test_read_error() {
#[test]
#[cfg_attr(all(target_env = "musl", target_arch = "x86_64"), ignore)]
fn test_read_into_mut_slice() {
- const INITIAL: &'static [u8] = b"abcdef123456";
+ const INITIAL: &[u8] = b"abcdef123456";
let mut rbuf = vec![0; 4];
- const EXPECT: &'static [u8] = b"cdef";
+ const EXPECT: &[u8] = b"cdef";
let mut f = tempfile().unwrap();
- f.write(INITIAL).unwrap();
+ f.write_all(INITIAL).unwrap();
{
let mut aiocb = AioCb::from_mut_slice( f.as_raw_fd(),
2, //offset
@@ -250,11 +250,11 @@ fn test_read_into_mut_slice() {
#[should_panic(expected = "Can't read into an immutable buffer")]
#[cfg_attr(target_env = "musl", ignore)]
fn test_read_immutable_buffer() {
- let rbuf: &'static [u8] = b"CDEF";
+ let rbuf: &[u8] = b"CDEF";
let f = tempfile().unwrap();
let mut aiocb = AioCb::from_slice( f.as_raw_fd(),
2, //offset
- &rbuf,
+ rbuf,
0, //priority
SigevNotify::SigevNone,
LioOpcode::LIO_NOP);
@@ -267,13 +267,13 @@ fn test_read_immutable_buffer() {
#[test]
#[cfg_attr(all(target_env = "musl", target_arch = "x86_64"), ignore)]
fn test_write() {
- const INITIAL: &'static [u8] = b"abcdef123456";
+ const INITIAL: &[u8] = b"abcdef123456";
let wbuf = "CDEF".to_string().into_bytes();
let mut rbuf = Vec::new();
- const EXPECT: &'static [u8] = b"abCDEF123456";
+ const EXPECT: &[u8] = b"abCDEF123456";
let mut f = tempfile().unwrap();
- f.write(INITIAL).unwrap();
+ f.write_all(INITIAL).unwrap();
let mut aiocb = AioCb::from_slice( f.as_raw_fd(),
2, //offset
&wbuf,
@@ -330,16 +330,16 @@ fn test_write_sigev_signal() {
SIGNALED.store(false, Ordering::Relaxed);
unsafe { sigaction(Signal::SIGUSR2, &sa) }.unwrap();
- const INITIAL: &'static [u8] = b"abcdef123456";
- const WBUF: &'static [u8] = b"CDEF";
+ const INITIAL: &[u8] = b"abcdef123456";
+ const WBUF: &[u8] = b"CDEF";
let mut rbuf = Vec::new();
- const EXPECT: &'static [u8] = b"abCDEF123456";
+ const EXPECT: &[u8] = b"abCDEF123456";
let mut f = tempfile().unwrap();
- f.write(INITIAL).unwrap();
+ f.write_all(INITIAL).unwrap();
let mut aiocb = AioCb::from_slice( f.as_raw_fd(),
2, //offset
- &WBUF,
+ WBUF,
0, //priority
SigevNotify::SigevSignal {
signal: Signal::SIGUSR2,
@@ -347,7 +347,7 @@ fn test_write_sigev_signal() {
},
LioOpcode::LIO_NOP);
aiocb.write().unwrap();
- while SIGNALED.load(Ordering::Relaxed) == false {
+ while !SIGNALED.load(Ordering::Relaxed) {
thread::sleep(time::Duration::from_millis(10));
}
@@ -364,26 +364,26 @@ fn test_write_sigev_signal() {
#[cfg(not(any(target_os = "ios", target_os = "macos")))]
#[cfg_attr(all(target_env = "musl", target_arch = "x86_64"), ignore)]
fn test_lio_listio_wait() {
- const INITIAL: &'static [u8] = b"abcdef123456";
- const WBUF: &'static [u8] = b"CDEF";
+ const INITIAL: &[u8] = b"abcdef123456";
+ const WBUF: &[u8] = b"CDEF";
let rbuf = Rc::new(vec![0; 4].into_boxed_slice());
let mut rbuf2 = Vec::new();
- const EXPECT: &'static [u8] = b"abCDEF123456";
+ const EXPECT: &[u8] = b"abCDEF123456";
let mut f = tempfile().unwrap();
- f.write(INITIAL).unwrap();
+ f.write_all(INITIAL).unwrap();
{
let mut wcb = AioCb::from_slice( f.as_raw_fd(),
2, //offset
- &WBUF,
+ WBUF,
0, //priority
SigevNotify::SigevNone,
LioOpcode::LIO_WRITE);
let mut rcb = AioCb::from_boxed_slice( f.as_raw_fd(),
8, //offset
- rbuf.clone(),
+ Rc::clone(&rbuf),
0, //priority
SigevNotify::SigevNone,
LioOpcode::LIO_READ);
@@ -407,26 +407,26 @@ fn test_lio_listio_wait() {
#[cfg(not(any(target_os = "ios", target_os = "macos")))]
#[cfg_attr(all(target_env = "musl", target_arch = "x86_64"), ignore)]
fn test_lio_listio_nowait() {
- const INITIAL: &'static [u8] = b"abcdef123456";
- const WBUF: &'static [u8] = b"CDEF";
+ const INITIAL: &[u8] = b"abcdef123456";
+ const WBUF: &[u8] = b"CDEF";
let rbuf = Rc::new(vec![0; 4].into_boxed_slice());
let mut rbuf2 = Vec::new();
- const EXPECT: &'static [u8] = b"abCDEF123456";
+ const EXPECT: &[u8] = b"abCDEF123456";
let mut f = tempfile().unwrap();
- f.write(INITIAL).unwrap();
+ f.write_all(INITIAL).unwrap();
{
let mut wcb = AioCb::from_slice( f.as_raw_fd(),
2, //offset
- &WBUF,
+ WBUF,
0, //priority
SigevNotify::SigevNone,
LioOpcode::LIO_WRITE);
let mut rcb = AioCb::from_boxed_slice( f.as_raw_fd(),
8, //offset
- rbuf.clone(),
+ Rc::clone(&rbuf),
0, //priority
SigevNotify::SigevNone,
LioOpcode::LIO_READ);
@@ -455,11 +455,11 @@ fn test_lio_listio_nowait() {
fn test_lio_listio_signal() {
#[allow(unused_variables)]
let m = ::SIGNAL_MTX.lock().expect("Mutex got poisoned by another test");
- const INITIAL: &'static [u8] = b"abcdef123456";
- const WBUF: &'static [u8] = b"CDEF";
+ const INITIAL: &[u8] = b"abcdef123456";
+ const WBUF: &[u8] = b"CDEF";
let rbuf = Rc::new(vec![0; 4].into_boxed_slice());
let mut rbuf2 = Vec::new();
- const EXPECT: &'static [u8] = b"abCDEF123456";
+ const EXPECT: &[u8] = b"abCDEF123456";
let mut f = tempfile().unwrap();
let sa = SigAction::new(SigHandler::Handler(sigfunc),
SaFlags::SA_RESETHAND,
@@ -467,19 +467,19 @@ fn test_lio_listio_signal() {
let sigev_notify = SigevNotify::SigevSignal { signal: Signal::SIGUSR2,
si_value: 0 };
- f.write(INITIAL).unwrap();
+ f.write_all(INITIAL).unwrap();
{
let mut wcb = AioCb::from_slice( f.as_raw_fd(),
2, //offset
- &WBUF,
+ WBUF,
0, //priority
SigevNotify::SigevNone,
LioOpcode::LIO_WRITE);
let mut rcb = AioCb::from_boxed_slice( f.as_raw_fd(),
8, //offset
- rbuf.clone(),
+ Rc::clone(&rbuf),
0, //priority
SigevNotify::SigevNone,
LioOpcode::LIO_READ);
@@ -487,7 +487,7 @@ fn test_lio_listio_signal() {
unsafe { sigaction(Signal::SIGUSR2, &sa) }.unwrap();
let err = lio_listio(LioMode::LIO_NOWAIT, &[&mut wcb, &mut rcb], sigev_notify);
err.expect("lio_listio failed");
- while SIGNALED.load(Ordering::Relaxed) == false {
+ while !SIGNALED.load(Ordering::Relaxed) {
thread::sleep(time::Duration::from_millis(10));
}
@@ -509,13 +509,13 @@ fn test_lio_listio_signal() {
#[should_panic(expected = "Can't read into an immutable buffer")]
#[cfg_attr(target_env = "musl", ignore)]
fn test_lio_listio_read_immutable() {
- let rbuf: &'static [u8] = b"abcd";
+ let rbuf: &[u8] = b"abcd";
let f = tempfile().unwrap();
let mut rcb = AioCb::from_slice( f.as_raw_fd(),
2, //offset
- &rbuf,
+ rbuf,
0, //priority
SigevNotify::SigevNone,
LioOpcode::LIO_READ);
diff --git a/test/sys/test_aio_drop.rs b/test/sys/test_aio_drop.rs
index ef0f5041..1f4a3e79 100644
--- a/test/sys/test_aio_drop.rs
+++ b/test/sys/test_aio_drop.rs
@@ -13,13 +13,13 @@ use tempfile::tempfile;
#[should_panic(expected = "Dropped an in-progress AioCb")]
#[cfg(not(target_env = "musl"))]
fn test_drop() {
- const WBUF: &'static [u8] = b"CDEF";
+ const WBUF: &[u8] = b"CDEF";
let f = tempfile().unwrap();
f.set_len(6).unwrap();
let mut aiocb = AioCb::from_slice( f.as_raw_fd(),
2, //offset
- &WBUF,
+ WBUF,
0, //priority
SigevNotify::SigevNone,
LioOpcode::LIO_NOP);
diff --git a/test/sys/test_ioctl.rs b/test/sys/test_ioctl.rs
index 1ed4a4b4..9a7a4819 100644
--- a/test/sys/test_ioctl.rs
+++ b/test/sys/test_ioctl.rs
@@ -87,22 +87,22 @@ mod linux {
#[test]
fn test_op_none() {
if cfg!(any(target_arch = "mips", target_arch = "mips64", target_arch="powerpc", target_arch="powerpc64")){
- assert_eq!(io!(b'q', 10), 0x2000710A);
- assert_eq!(io!(b'a', 255), 0x200061FF);
+ assert_eq!(io!(b'q', 10), 0x2000_710A);
+ assert_eq!(io!(b'a', 255), 0x2000_61FF);
} else {
- assert_eq!(io!(b'q', 10), 0x0000710A);
- assert_eq!(io!(b'a', 255), 0x000061FF);
+ assert_eq!(io!(b'q', 10), 0x0000_710A);
+ assert_eq!(io!(b'a', 255), 0x0000_61FF);
}
}
#[test]
fn test_op_write() {
if cfg!(any(target_arch = "mips", target_arch = "mips64", target_arch="powerpc", target_arch="powerpc64")){
- assert_eq!(iow!(b'z', 10, 1), 0x80017A0A);
- assert_eq!(iow!(b'z', 10, 512), 0x82007A0A);
+ assert_eq!(iow!(b'z', 10, 1), 0x8001_7A0A);
+ assert_eq!(iow!(b'z', 10, 512), 0x8200_7A0A);
} else {
- assert_eq!(iow!(b'z', 10, 1), 0x40017A0A);
- assert_eq!(iow!(b'z', 10, 512), 0x42007A0A);
+ assert_eq!(iow!(b'z', 10, 1), 0x4001_7A0A);
+ assert_eq!(iow!(b'z', 10, 512), 0x4200_7A0A);
}
}
@@ -110,9 +110,9 @@ mod linux {
#[test]
fn test_op_write_64() {
if cfg!(any(target_arch = "mips64", target_arch="powerpc64")){
- assert_eq!(iow!(b'z', 10, (1 as u64) << 32), 0x80007A0A);
+ assert_eq!(iow!(b'z', 10, (1 as u64) << 32), 0x8000_7A0A);
} else {
- assert_eq!(iow!(b'z', 10, (1 as u64) << 32), 0x40007A0A);
+ assert_eq!(iow!(b'z', 10, (1 as u64) << 32), 0x4000_7A0A);
}
}
@@ -120,11 +120,11 @@ mod linux {
#[test]
fn test_op_read() {
if cfg!(any(target_arch = "mips", target_arch = "mips64", target_arch="powerpc", target_arch="powerpc64")){
- assert_eq!(ior!(b'z', 10, 1), 0x40017A0A);
- assert_eq!(ior!(b'z', 10, 512), 0x42007A0A);
+ assert_eq!(ior!(b'z', 10, 1), 0x4001_7A0A);
+ assert_eq!(ior!(b'z', 10, 512), 0x4200_7A0A);
} else {
- assert_eq!(ior!(b'z', 10, 1), 0x80017A0A);
- assert_eq!(ior!(b'z', 10, 512), 0x82007A0A);
+ assert_eq!(ior!(b'z', 10, 1), 0x8001_7A0A);
+ assert_eq!(ior!(b'z', 10, 512), 0x8200_7A0A);
}
}
@@ -132,22 +132,22 @@ mod linux {
#[test]
fn test_op_read_64() {
if cfg!(any(target_arch = "mips64", target_arch="powerpc64")){
- assert_eq!(ior!(b'z', 10, (1 as u64) << 32), 0x40007A0A);
+ assert_eq!(ior!(b'z', 10, (1 as u64) << 32), 0x4000_7A0A);
} else {
- assert_eq!(ior!(b'z', 10, (1 as u64) << 32), 0x80007A0A);
+ assert_eq!(ior!(b'z', 10, (1 as u64) << 32), 0x8000_7A0A);
}
}
#[test]
fn test_op_read_write() {
- assert_eq!(iorw!(b'z', 10, 1), 0xC0017A0A);
- assert_eq!(iorw!(b'z', 10, 512), 0xC2007A0A);
+ assert_eq!(iorw!(b'z', 10, 1), 0xC001_7A0A);
+ assert_eq!(iorw!(b'z', 10, 512), 0xC200_7A0A);
}
#[cfg(target_pointer_width = "64")]
#[test]
fn test_op_read_write_64() {
- assert_eq!(iorw!(b'z', 10, (1 as u64) << 32), 0xC0007A0A);
+ assert_eq!(iorw!(b'z', 10, (1 as u64) << 32), 0xC000_7A0A);
}
}
@@ -160,44 +160,44 @@ mod linux {
mod bsd {
#[test]
fn test_op_none() {
- assert_eq!(io!(b'q', 10), 0x2000710A);
- assert_eq!(io!(b'a', 255), 0x200061FF);
+ assert_eq!(io!(b'q', 10), 0x2000_710A);
+ assert_eq!(io!(b'a', 255), 0x2000_61FF);
}
#[test]
fn test_op_write() {
- assert_eq!(iow!(b'z', 10, 1), 0x80017A0A);
- assert_eq!(iow!(b'z', 10, 512), 0x82007A0A);
+ assert_eq!(iow!(b'z', 10, 1), 0x8001_7A0A);
+ assert_eq!(iow!(b'z', 10, 512), 0x8200_7A0A);
}
#[cfg(target_pointer_width = "64")]
#[test]
fn test_op_write_64() {
- assert_eq!(iow!(b'z', 10, (1 as u64) << 32), 0x80007A0A);
+ assert_eq!(iow!(b'z', 10, (1 as u64) << 32), 0x8000_7A0A);
}
#[test]
fn test_op_read() {
- assert_eq!(ior!(b'z', 10, 1), 0x40017A0A);
- assert_eq!(ior!(b'z', 10, 512), 0x42007A0A);
+ assert_eq!(ior!(b'z', 10, 1), 0x4001_7A0A);
+ assert_eq!(ior!(b'z', 10, 512), 0x4200_7A0A);
}
#[cfg(target_pointer_width = "64")]
#[test]
fn test_op_read_64() {
- assert_eq!(ior!(b'z', 10, (1 as u64) << 32), 0x40007A0A);
+ assert_eq!(ior!(b'z', 10, (1 as u64) << 32), 0x4000_7A0A);
}
#[test]
fn test_op_read_write() {
- assert_eq!(iorw!(b'z', 10, 1), 0xC0017A0A);
- assert_eq!(iorw!(b'z', 10, 512), 0xC2007A0A);
+ assert_eq!(iorw!(b'z', 10, 1), 0xC001_7A0A);
+ assert_eq!(iorw!(b'z', 10, 512), 0xC200_7A0A);
}
#[cfg(target_pointer_width = "64")]
#[test]
fn test_op_read_write_64() {
- assert_eq!(iorw!(b'z', 10, (1 as u64) << 32), 0xC0007A0A);
+ assert_eq!(iorw!(b'z', 10, (1 as u64) << 32), 0xC000_7A0A);
}
}
@@ -269,10 +269,10 @@ mod linux_ioctls {
// From linux/videodev2.h
ioctl!(write_ptr s_audio with b'V', 34; v4l2_audio);
#[test]
- fn test_ioctl_read() {
+ fn test_ioctl_write_ptr() {
let file = tempfile().unwrap();
- let data: v4l2_audio = unsafe { mem::uninitialized() };
- let res = unsafe { g_audio(file.as_raw_fd(), &data) };
+ let data: v4l2_audio = unsafe { mem::zeroed() };
+ let res = unsafe { s_audio(file.as_raw_fd(), &data) };
assert!(res == Err(Sys(ENOTTY)) || res == Err(Sys(ENOSYS)));
}
@@ -288,9 +288,9 @@ mod linux_ioctls {
}
// From linux/videodev2.h
- ioctl!(write_ptr g_audio with b'V', 33; v4l2_audio);
+ ioctl!(read g_audio with b'V', 33; v4l2_audio);
#[test]
- fn test_ioctl_write_ptr() {
+ fn test_ioctl_read() {
let file = tempfile().unwrap();
let mut data: v4l2_audio = unsafe { mem::uninitialized() };
let res = unsafe { g_audio(file.as_raw_fd(), &mut data) };
@@ -328,8 +328,8 @@ mod linux_ioctls {
#[test]
fn test_ioctl_write_buf() {
let file = tempfile().unwrap();
- let mut data: [spi_ioc_transfer; 4] = unsafe { mem::uninitialized() };
- let res = unsafe { spi_ioc_message(file.as_raw_fd(), &mut data[..]) };
+ let data: [spi_ioc_transfer; 4] = unsafe { mem::zeroed() };
+ let res = unsafe { spi_ioc_message(file.as_raw_fd(), &data[..]) };
assert!(res == Err(Sys(ENOTTY)) || res == Err(Sys(ENOSYS)));
}
diff --git a/test/sys/test_ptrace.rs b/test/sys/test_ptrace.rs
index d3e579f3..debc4517 100644
--- a/test/sys/test_ptrace.rs
+++ b/test/sys/test_ptrace.rs
@@ -30,9 +30,8 @@ fn test_ptrace_getevent() {
// Just make sure ptrace_getsiginfo can be called at all, for now.
#[test]
fn test_ptrace_getsiginfo() {
- match ptrace::getsiginfo(getpid()) {
- Err(Error::UnsupportedOperation) => panic!("ptrace_getsiginfo returns Error::UnsupportedOperation!"),
- _ => (),
+ if let Err(Error::UnsupportedOperation) = ptrace::getsiginfo(getpid()) {
+ panic!("ptrace_getsiginfo returns Error::UnsupportedOperation!");
}
}
@@ -40,9 +39,8 @@ fn test_ptrace_getsiginfo() {
#[test]
fn test_ptrace_setsiginfo() {
let siginfo = unsafe { mem::uninitialized() };
- match ptrace::setsiginfo(getpid(), &siginfo) {
- Err(Error::UnsupportedOperation) => panic!("ptrace_setsiginfo returns Error::UnsupportedOperation!"),
- _ => (),
+ if let Err(Error::UnsupportedOperation) = ptrace::setsiginfo(getpid(), &siginfo) {
+ panic!("ptrace_setsiginfo returns Error::UnsupportedOperation!");
}
}
@@ -66,8 +64,8 @@ fn test_ptrace_cont() {
return;
}
- match fork() {
- Ok(Child) => {
+ match fork().expect("Error: Fork Failed") {
+ Child => {
ptrace::traceme().unwrap();
// As recommended by ptrace(2), raise SIGTRAP to pause the child
// until the parent is ready to continue
@@ -76,7 +74,7 @@ fn test_ptrace_cont() {
}
},
- Ok(Parent { child }) => {
+ Parent { child } => {
assert_eq!(waitpid(child, None), Ok(WaitStatus::Stopped(child, Signal::SIGTRAP)));
ptrace::cont(child, None).unwrap();
assert_eq!(waitpid(child, None), Ok(WaitStatus::Stopped(child, Signal::SIGTRAP)));
@@ -86,6 +84,5 @@ fn test_ptrace_cont() {
_ => panic!("The process should have been killed"),
}
},
- Err(_) => panic!("Error: Fork Failed")
}
}
diff --git a/test/sys/test_signal.rs b/test/sys/test_signal.rs
index 4084a0da..ab99ab19 100644
--- a/test/sys/test_signal.rs
+++ b/test/sys/test_signal.rs
@@ -3,5 +3,5 @@ use nix::sys::signal::*;
#[test]
fn test_kill_none() {
- kill(getpid(), None).ok().expect("Should be able to send signal to myself.");
+ kill(getpid(), None).expect("Should be able to send signal to myself.");
}
diff --git a/test/sys/test_signalfd.rs b/test/sys/test_signalfd.rs
index 6d65e6a0..a2f8fd8f 100644
--- a/test/sys/test_signalfd.rs
+++ b/test/sys/test_signalfd.rs
@@ -17,7 +17,7 @@ fn test_signalfd() {
// Send a SIGUSR1 signal to the current process. Note that this uses `raise` instead of `kill`
// because `kill` with `getpid` isn't correct during multi-threaded execution like during a
// cargo test session. Instead use `raise` which does the correct thing by default.
- raise(signal::SIGUSR1).ok().expect("Error: raise(SIGUSR1) failed");
+ raise(signal::SIGUSR1).expect("Error: raise(SIGUSR1) failed");
// And now catch that same signal.
let res = fd.read_signal().unwrap().unwrap();
diff --git a/test/sys/test_socket.rs b/test/sys/test_socket.rs
index d29b2ecb..a997fbca 100644
--- a/test/sys/test_socket.rs
+++ b/test/sys/test_socket.rs
@@ -13,7 +13,7 @@ pub fn test_inetv4_addr_to_sock_addr() {
match addr {
InetAddr::V4(addr) => {
- let ip: u32 = 0x7f000001;
+ let ip: u32 = 0x7f00_0001;
let port: u16 = 3000;
assert_eq!(addr.sin_addr.s_addr, ip.to_be());
diff --git a/test/sys/test_sockopt.rs b/test/sys/test_sockopt.rs
index 81db8248..a38657c1 100644
--- a/test/sys/test_sockopt.rs
+++ b/test/sys/test_sockopt.rs
@@ -5,7 +5,7 @@ use nix::sys::socket::{socket, sockopt, getsockopt, setsockopt, AddressFamily, S
fn test_so_buf() {
let fd = socket(AddressFamily::Inet, SockType::Datagram, SockFlag::empty(), SockProtocol::Udp)
.unwrap();
- let bufsize: usize = thread_rng().gen_range(4096, 131072);
+ let bufsize: usize = thread_rng().gen_range(4096, 131_072);
setsockopt(fd, sockopt::SndBuf, &bufsize).unwrap();
let actual = getsockopt(fd, sockopt::SndBuf).unwrap();
assert!(actual >= bufsize);
diff --git a/test/sys/test_termios.rs b/test/sys/test_termios.rs
index a3a948b3..903a5353 100644
--- a/test/sys/test_termios.rs
+++ b/test/sys/test_termios.rs
@@ -7,7 +7,7 @@ use nix::pty::openpty;
use nix::sys::termios::{self, LocalFlags, OutputFlags, Termios, tcgetattr};
use nix::unistd::{read, write, close};
-/// Helper function analogous to std::io::Write::write_all, but for `RawFd`s
+/// Helper function analogous to `std::io::Write::write_all`, but for `RawFd`s
fn write_all(f: RawFd, buf: &[u8]) {
let mut len = 0;
while len < buf.len() {
diff --git a/test/sys/test_uio.rs b/test/sys/test_uio.rs
index a2b68d07..c6331f1d 100644
--- a/test/sys/test_uio.rs
+++ b/test/sys/test_uio.rs
@@ -14,7 +14,7 @@ fn test_writev() {
for _ in 0..16 {
let s: String = thread_rng().gen_ascii_chars().take(128).collect();
let b = s.as_bytes();
- to_write.extend(b.iter().map(|x| x.clone()));
+ to_write.extend(b.iter().cloned());
}
// Allocate and fill iovecs
let mut iovecs = Vec::new();
@@ -66,7 +66,7 @@ fn test_readv() {
allocated += vec_len;
}
let mut iovecs = Vec::with_capacity(storage.len());
- for v in storage.iter_mut() {
+ for v in &mut storage {
iovecs.push(IoVec::from_mut_slice(&mut v[..]));
}
let pipe_res = pipe();
@@ -83,8 +83,8 @@ fn test_readv() {
assert_eq!(to_write.len(), read);
// Cccumulate data from iovecs
let mut read_buf = Vec::with_capacity(to_write.len());
- for iovec in iovecs.iter() {
- read_buf.extend(iovec.as_slice().iter().map(|x| x.clone()));
+ for iovec in &iovecs {
+ read_buf.extend(iovec.as_slice().iter().cloned());
}
// Check whether iovecs contain all written data
assert_eq!(read_buf.len(), to_write.len());
@@ -208,11 +208,11 @@ fn test_process_vm_readv() {
let mut vector = vec![1u8, 2, 3, 4, 5];
let (r, w) = pipe().unwrap();
- match fork() {
- Ok(Parent { child }) => {
+ match fork().expect("Error: Fork Failed") {
+ Parent { child } => {
close(w).unwrap();
// wait for child
- read(r, &mut vec![0u8]).unwrap();
+ read(r, &mut [0u8]).unwrap();
close(r).unwrap();
let ptr = vector.as_ptr() as usize;
@@ -229,15 +229,14 @@ fn test_process_vm_readv() {
assert_eq!(Ok(5), ret);
assert_eq!(20u8, buf.iter().sum());
},
- Ok(Child) => {
+ Child => {
let _ = close(r);
- for i in vector.iter_mut() {
+ for i in &mut vector {
*i += 1;
}
let _ = write(w, b"\0");
let _ = close(w);
loop { let _ = pause(); }
},
- Err(_) => panic!("fork failed")
}
}
diff --git a/test/sys/test_wait.rs b/test/sys/test_wait.rs
index 02f32734..9992607c 100644
--- a/test/sys/test_wait.rs
+++ b/test/sys/test_wait.rs
@@ -11,14 +11,12 @@ fn test_wait_signal() {
let m = ::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 fork() {
- Ok(Child) => pause().unwrap_or_else(|_| unsafe { _exit(123) }),
- Ok(Parent { child }) => {
- kill(child, Some(SIGKILL)).ok().expect("Error: Kill Failed");
+ match fork().expect("Error: Fork Failed") {
+ Child => pause().unwrap_or_else(|_| unsafe { _exit(123) }),
+ Parent { child } => {
+ kill(child, Some(SIGKILL)).expect("Error: Kill Failed");
assert_eq!(waitpid(child, None), Ok(WaitStatus::Signaled(child, SIGKILL, false)));
},
- // panic, fork should never fail unless there is a serious problem with the OS
- Err(_) => panic!("Error: Fork Failed")
}
}
@@ -28,13 +26,11 @@ fn test_wait_exit() {
let m = ::FORK_MTX.lock().expect("Mutex got poisoned by another test");
// Safe: Child only calls `_exit`, which is async-signal-safe.
- match fork() {
- Ok(Child) => unsafe { _exit(12); },
- Ok(Parent { child }) => {
+ match fork().expect("Error: Fork Failed") {
+ Child => unsafe { _exit(12); },
+ Parent { child } => {
assert_eq!(waitpid(child, None), Ok(WaitStatus::Exited(child, 12)));
},
- // panic, fork should never fail unless there is a serious problem with the OS
- Err(_) => panic!("Error: Fork Failed")
}
}
@@ -100,10 +96,9 @@ mod ptrace {
#[allow(unused_variables)]
let m = ::FORK_MTX.lock().expect("Mutex got poisoned by another test");
- match fork() {
- Ok(Child) => ptrace_child(),
- Ok(Parent { child }) => ptrace_parent(child),
- Err(_) => panic!("Error: Fork Failed")
+ match fork().expect("Error: Fork Failed") {
+ Child => ptrace_child(),
+ Parent { child } => ptrace_parent(child),
}
}
}