|
1 | 1 | use crate::tests::register_buf_ring;
|
2 | 2 | use crate::utils;
|
3 | 3 | use crate::Test;
|
| 4 | +use ::rustix::io_uring::iovec; |
4 | 5 | use ::std::collections::BTreeSet;
|
5 | 6 | use io_uring::Errno;
|
6 | 7 | use io_uring::{cqueue, opcode, squeue, types, IoUring};
|
@@ -249,6 +250,111 @@ pub fn test_file_writev_readv<S: squeue::EntryMarker, C: cqueue::EntryMarker>(
|
249 | 250 | Ok(())
|
250 | 251 | }
|
251 | 252 |
|
| 253 | +pub fn test_pipe_fixed_writev_readv<S: squeue::EntryMarker, C: cqueue::EntryMarker>( |
| 254 | + ring: &mut IoUring<S, C>, |
| 255 | + test: &Test, |
| 256 | +) -> anyhow::Result<()> { |
| 257 | + require!( |
| 258 | + test; |
| 259 | + test.probe.is_supported(opcode::WritevFixed::CODE); |
| 260 | + test.probe.is_supported(opcode::ReadvFixed::CODE); |
| 261 | + ); |
| 262 | + |
| 263 | + println!("test pipe_fixed_writev_readv"); |
| 264 | + |
| 265 | + ring.submitter().unregister_buffers()?; |
| 266 | + |
| 267 | + let (rx, tx) = ::rustix::pipe::pipe()?; |
| 268 | + |
| 269 | + const BYTES0: &[u8] = "The quick brown fox jumps over the lazy dog.".as_bytes(); |
| 270 | + const BYTES1: &[u8] = "我能吞下玻璃而不伤身体。".as_bytes(); |
| 271 | + |
| 272 | + let mut src = Vec::with_capacity(BYTES0.len() + BYTES1.len()); |
| 273 | + src.extend_from_slice(BYTES0); |
| 274 | + src.extend_from_slice(BYTES1); |
| 275 | + |
| 276 | + let mut dst = vec![0u8; BYTES0.len() + BYTES1.len()]; |
| 277 | + |
| 278 | + unsafe { |
| 279 | + ring.submitter().register_buffers(&[ |
| 280 | + iovec { |
| 281 | + iov_base: src.as_mut_ptr() as *mut _, |
| 282 | + iov_len: src.len(), |
| 283 | + }, |
| 284 | + iovec { |
| 285 | + iov_base: dst.as_mut_ptr() as *mut _, |
| 286 | + iov_len: dst.len(), |
| 287 | + }, |
| 288 | + ])?; |
| 289 | + } |
| 290 | + |
| 291 | + let src_parts = [ |
| 292 | + libc::iovec { |
| 293 | + iov_base: src.as_ptr() as *mut _, |
| 294 | + iov_len: BYTES0.len(), |
| 295 | + }, |
| 296 | + libc::iovec { |
| 297 | + iov_base: unsafe { src.as_ptr().add(BYTES0.len()) } as *mut _, |
| 298 | + iov_len: BYTES1.len(), |
| 299 | + }, |
| 300 | + ]; |
| 301 | + unsafe { |
| 302 | + ring.submission().push( |
| 303 | + &opcode::WritevFixed::new( |
| 304 | + types::Fd(tx.as_raw_fd()), |
| 305 | + src_parts.as_ptr().cast(), |
| 306 | + src_parts.len() as u32, |
| 307 | + 0, |
| 308 | + ) |
| 309 | + .build() |
| 310 | + .user_data(0x666) |
| 311 | + .into(), |
| 312 | + )?; |
| 313 | + } |
| 314 | + ring.submit_and_wait(1)?; |
| 315 | + for cqe in ring.completion().map(Into::<cqueue::Entry>::into) { |
| 316 | + assert_eq!(cqe.user_data_u64(), 0x666); |
| 317 | + let len = cqe.result()?; |
| 318 | + assert_eq!(len, src.len() as _); |
| 319 | + } |
| 320 | + |
| 321 | + let dst_parts = [ |
| 322 | + libc::iovec { |
| 323 | + iov_base: dst.as_ptr() as *mut _, |
| 324 | + iov_len: BYTES0.len(), |
| 325 | + }, |
| 326 | + libc::iovec { |
| 327 | + iov_base: unsafe { dst.as_ptr().add(BYTES0.len()) } as *mut _, |
| 328 | + iov_len: BYTES1.len(), |
| 329 | + }, |
| 330 | + ]; |
| 331 | + unsafe { |
| 332 | + ring.submission().push( |
| 333 | + &opcode::ReadvFixed::new( |
| 334 | + types::Fd(rx.as_raw_fd()), |
| 335 | + dst_parts.as_ptr().cast(), |
| 336 | + dst_parts.len() as u32, |
| 337 | + 1, |
| 338 | + ) |
| 339 | + .build() |
| 340 | + .user_data(0x666) |
| 341 | + .into(), |
| 342 | + )?; |
| 343 | + } |
| 344 | + ring.submit_and_wait(1)?; |
| 345 | + for cqe in ring.completion().map(Into::<cqueue::Entry>::into) { |
| 346 | + assert_eq!(cqe.user_data_u64(), 0x666); |
| 347 | + let len = cqe.result()?; |
| 348 | + assert_eq!(len, src.len() as _); |
| 349 | + } |
| 350 | + |
| 351 | + ring.submitter().unregister_buffers()?; |
| 352 | + |
| 353 | + assert_eq!(src, dst); |
| 354 | + |
| 355 | + Ok(()) |
| 356 | +} |
| 357 | + |
252 | 358 | pub fn test_file_fsync<S: squeue::EntryMarker, C: cqueue::EntryMarker>(
|
253 | 359 | ring: &mut IoUring<S, C>,
|
254 | 360 | test: &Test,
|
|
0 commit comments