@@ -88,6 +88,26 @@ fn test_fsync() {
8888 aiocb. aio_return ( ) . unwrap ( ) ;
8989}
9090
91+ /// `AioCb::fsync` should not modify the `AioCb` object if libc::aio_fsync returns
92+ /// an error
93+ // Skip on Linux, because Linux's AIO implementation can't detect errors
94+ // synchronously
95+ #[ test]
96+ #[ cfg( any( target_os = "freebsd" , target_os = "macos" ) ) ]
97+ fn test_fsync_error ( ) {
98+ use std:: mem;
99+
100+ const INITIAL : & ' static [ u8 ] = b"abcdef123456" ;
101+ // Create an invalid AioFsyncMode
102+ let mode = unsafe { mem:: transmute ( 666 ) } ;
103+ let mut f = tempfile ( ) . unwrap ( ) ;
104+ f. write ( INITIAL ) . unwrap ( ) ;
105+ let mut aiocb = AioCb :: from_fd ( f. as_raw_fd ( ) ,
106+ 0 , //priority
107+ SigevNotify :: SigevNone ) ;
108+ let err = aiocb. fsync ( mode) ;
109+ assert ! ( err. is_err( ) ) ;
110+ }
91111
92112#[ test]
93113#[ cfg_attr( all( target_env = "musl" , target_arch = "x86_64" ) , ignore) ]
@@ -156,6 +176,26 @@ fn test_read() {
156176 assert ! ( EXPECT == rbuf. deref( ) . deref( ) ) ;
157177}
158178
179+ /// `AioCb::read` should not modify the `AioCb` object if libc::aio_read returns
180+ /// an error
181+ // Skip on Linux, because Linux's AIO implementation can't detect errors
182+ // synchronously
183+ #[ test]
184+ #[ cfg( any( target_os = "freebsd" , target_os = "macos" ) ) ]
185+ fn test_read_error ( ) {
186+ const INITIAL : & ' static [ u8 ] = b"abcdef123456" ;
187+ let rbuf = Rc :: new ( vec ! [ 0 ; 4 ] . into_boxed_slice ( ) ) ;
188+ let mut f = tempfile ( ) . unwrap ( ) ;
189+ f. write ( INITIAL ) . unwrap ( ) ;
190+ let mut aiocb = AioCb :: from_boxed_slice ( f. as_raw_fd ( ) ,
191+ -1 , //an invalid offset
192+ rbuf. clone ( ) ,
193+ 0 , //priority
194+ SigevNotify :: SigevNone ,
195+ LioOpcode :: LIO_NOP ) ;
196+ assert ! ( aiocb. read( ) . is_err( ) ) ;
197+ }
198+
159199// Tests from_mut_slice
160200#[ test]
161201#[ cfg_attr( all( target_env = "musl" , target_arch = "x86_64" ) , ignore) ]
@@ -230,6 +270,23 @@ fn test_write() {
230270 assert ! ( rbuf == EXPECT ) ;
231271}
232272
273+ /// `AioCb::write` should not modify the `AioCb` object if libc::aio_write returns
274+ /// an error
275+ // Skip on Linux, because Linux's AIO implementation can't detect errors
276+ // synchronously
277+ #[ test]
278+ #[ cfg( any( target_os = "freebsd" , target_os = "macos" ) ) ]
279+ fn test_write_error ( ) {
280+ let wbuf = "CDEF" . to_string ( ) . into_bytes ( ) ;
281+ let mut aiocb = AioCb :: from_slice ( 666 , // An invalid file descriptor
282+ 0 , //offset
283+ & wbuf,
284+ 0 , //priority
285+ SigevNotify :: SigevNone ,
286+ LioOpcode :: LIO_NOP ) ;
287+ assert ! ( aiocb. write( ) . is_err( ) ) ;
288+ }
289+
233290lazy_static ! {
234291 pub static ref SIGNALED : AtomicBool = AtomicBool :: new( false ) ;
235292}
0 commit comments