@@ -5,6 +5,7 @@ use nix::sys::aio::*;
5
5
use nix:: sys:: signal:: * ;
6
6
use nix:: sys:: time:: { TimeSpec , TimeValLike } ;
7
7
use std:: io:: { Write , Read , Seek , SeekFrom } ;
8
+ use std:: mem;
8
9
use std:: ops:: Deref ;
9
10
use std:: os:: unix:: io:: AsRawFd ;
10
11
use std:: rc:: Rc ;
@@ -88,6 +89,22 @@ fn test_fsync() {
88
89
aiocb. aio_return ( ) . unwrap ( ) ;
89
90
}
90
91
92
+ /// `AioCb::fsync` should not modify the `AioCb` object if libc::aio_fsync returns
93
+ /// an error
94
+ #[ test]
95
+ #[ cfg_attr( all( target_env = "musl" , target_arch = "x86_64" ) , ignore) ]
96
+ fn test_fsync_error ( ) {
97
+ const INITIAL : & ' static [ u8 ] = b"abcdef123456" ;
98
+ // Create an invalid AioFsyncMode
99
+ let mode = unsafe { mem:: transmute ( 666 ) } ;
100
+ let mut f = tempfile ( ) . unwrap ( ) ;
101
+ f. write ( INITIAL ) . unwrap ( ) ;
102
+ let mut aiocb = AioCb :: from_fd ( f. as_raw_fd ( ) ,
103
+ 0 , //priority
104
+ SigevNotify :: SigevNone ) ;
105
+ let err = aiocb. fsync ( mode) ;
106
+ assert ! ( err. is_err( ) ) ;
107
+ }
91
108
92
109
#[ test]
93
110
#[ cfg_attr( all( target_env = "musl" , target_arch = "x86_64" ) , ignore) ]
@@ -156,6 +173,24 @@ fn test_read() {
156
173
assert ! ( EXPECT == rbuf. deref( ) . deref( ) ) ;
157
174
}
158
175
176
+ /// `AioCb::read` should not modify the `AioCb` object if libc::aio_read returns
177
+ /// an error
178
+ #[ test]
179
+ #[ cfg_attr( all( target_env = "musl" , target_arch = "x86_64" ) , ignore) ]
180
+ fn test_read_error ( ) {
181
+ const INITIAL : & ' static [ u8 ] = b"abcdef123456" ;
182
+ let rbuf = Rc :: new ( vec ! [ 0 ; 4 ] . into_boxed_slice ( ) ) ;
183
+ let mut f = tempfile ( ) . unwrap ( ) ;
184
+ f. write ( INITIAL ) . unwrap ( ) ;
185
+ let mut aiocb = AioCb :: from_boxed_slice ( f. as_raw_fd ( ) ,
186
+ -1 , //an invalid offset
187
+ rbuf. clone ( ) ,
188
+ 0 , //priority
189
+ SigevNotify :: SigevNone ,
190
+ LioOpcode :: LIO_NOP ) ;
191
+ assert ! ( aiocb. read( ) . is_err( ) ) ;
192
+ }
193
+
159
194
// Tests from_mut_slice
160
195
#[ test]
161
196
#[ cfg_attr( all( target_env = "musl" , target_arch = "x86_64" ) , ignore) ]
@@ -230,6 +265,21 @@ fn test_write() {
230
265
assert ! ( rbuf == EXPECT ) ;
231
266
}
232
267
268
+ /// `AioCb::write` should not modify the `AioCb` object if libc::aio_write returns
269
+ /// an error
270
+ #[ test]
271
+ #[ cfg_attr( all( target_env = "musl" , target_arch = "x86_64" ) , ignore) ]
272
+ fn test_write_error ( ) {
273
+ let wbuf = "CDEF" . to_string ( ) . into_bytes ( ) ;
274
+ let mut aiocb = AioCb :: from_slice ( 666 , // An invalid file descriptor
275
+ 0 , //offset
276
+ & wbuf,
277
+ 0 , //priority
278
+ SigevNotify :: SigevNone ,
279
+ LioOpcode :: LIO_NOP ) ;
280
+ assert ! ( aiocb. write( ) . is_err( ) ) ;
281
+ }
282
+
233
283
lazy_static ! {
234
284
pub static ref SIGNALED : AtomicBool = AtomicBool :: new( false ) ;
235
285
}
0 commit comments