From bd2cda18cec3d2acb1f7bb37778be557029b0268 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sun, 3 Sep 2017 14:27:57 -0600 Subject: Fixed error handling in `AioCb::{fsync,read,write}` Previously, the `AioCb`'s `in_progress` field would erroneously be set to `true`, even if the syscall had an error Fixes #714 --- test/sys/test_aio.rs | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'test/sys/test_aio.rs') diff --git a/test/sys/test_aio.rs b/test/sys/test_aio.rs index 23cab56e..67fd0850 100644 --- a/test/sys/test_aio.rs +++ b/test/sys/test_aio.rs @@ -88,6 +88,26 @@ fn test_fsync() { aiocb.aio_return().unwrap(); } +/// `AioCb::fsync` should not modify the `AioCb` object if libc::aio_fsync returns +/// an error +// Skip on Linux, because Linux's AIO implementation can't detect errors +// synchronously +#[test] +#[cfg(any(target_os = "freebsd", target_os = "macos"))] +fn test_fsync_error() { + use std::mem; + + const INITIAL: &'static [u8] = b"abcdef123456"; + // Create an invalid AioFsyncMode + let mode = unsafe { mem::transmute(666) }; + let mut f = tempfile().unwrap(); + f.write(INITIAL).unwrap(); + let mut aiocb = AioCb::from_fd( f.as_raw_fd(), + 0, //priority + SigevNotify::SigevNone); + let err = aiocb.fsync(mode); + assert!(err.is_err()); +} #[test] #[cfg_attr(all(target_env = "musl", target_arch = "x86_64"), ignore)] @@ -156,6 +176,26 @@ fn test_read() { assert!(EXPECT == rbuf.deref().deref()); } +/// `AioCb::read` should not modify the `AioCb` object if libc::aio_read returns +/// an error +// Skip on Linux, because Linux's AIO implementation can't detect errors +// synchronously +#[test] +#[cfg(any(target_os = "freebsd", target_os = "macos"))] +fn test_read_error() { + const INITIAL: &'static [u8] = b"abcdef123456"; + let rbuf = Rc::new(vec![0; 4].into_boxed_slice()); + let mut f = tempfile().unwrap(); + f.write(INITIAL).unwrap(); + let mut aiocb = AioCb::from_boxed_slice( f.as_raw_fd(), + -1, //an invalid offset + rbuf.clone(), + 0, //priority + SigevNotify::SigevNone, + LioOpcode::LIO_NOP); + assert!(aiocb.read().is_err()); +} + // Tests from_mut_slice #[test] #[cfg_attr(all(target_env = "musl", target_arch = "x86_64"), ignore)] @@ -230,6 +270,23 @@ fn test_write() { assert!(rbuf == EXPECT); } +/// `AioCb::write` should not modify the `AioCb` object if libc::aio_write returns +/// an error +// Skip on Linux, because Linux's AIO implementation can't detect errors +// synchronously +#[test] +#[cfg(any(target_os = "freebsd", target_os = "macos"))] +fn test_write_error() { + let wbuf = "CDEF".to_string().into_bytes(); + let mut aiocb = AioCb::from_slice( 666, // An invalid file descriptor + 0, //offset + &wbuf, + 0, //priority + SigevNotify::SigevNone, + LioOpcode::LIO_NOP); + assert!(aiocb.write().is_err()); +} + lazy_static! { pub static ref SIGNALED: AtomicBool = AtomicBool::new(false); } -- cgit v1.2.3