@@ -88,6 +88,26 @@ fn test_fsync() {
88
88
aiocb. aio_return ( ) . unwrap ( ) ;
89
89
}
90
90
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
+ }
91
111
92
112
#[ test]
93
113
#[ cfg_attr( all( target_env = "musl" , target_arch = "x86_64" ) , ignore) ]
@@ -156,6 +176,26 @@ fn test_read() {
156
176
assert ! ( EXPECT == rbuf. deref( ) . deref( ) ) ;
157
177
}
158
178
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
+
159
199
// Tests from_mut_slice
160
200
#[ test]
161
201
#[ cfg_attr( all( target_env = "musl" , target_arch = "x86_64" ) , ignore) ]
@@ -230,6 +270,23 @@ fn test_write() {
230
270
assert ! ( rbuf == EXPECT ) ;
231
271
}
232
272
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
+
233
290
lazy_static ! {
234
291
pub static ref SIGNALED : AtomicBool = AtomicBool :: new( false ) ;
235
292
}
0 commit comments