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