MCPcopy Create free account
hub / github.com/axboe/liburing / test_readv_fixed

Function test_readv_fixed

test/vec-regbuf.c:523–610  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

521}
522
523static int test_readv_fixed(struct buf_desc *bd, struct iovec *vecs, int nr_vec)
524{
525 unsigned buf_idx = bd->buf_idx;
526 struct io_uring *ring = &bd->ring;
527 struct io_uring_sqe *sqe;
528 struct io_uring_cqe *cqe;
529 size_t total_len, i, offset;
530 int ret, fd;
531 char *expected;
532 char filename[] = ".readv_fixed.XXXXXX";
533
534 total_len = t_iovec_data_length(vecs, nr_vec);
535
536 expected = malloc(total_len);
537 if (!expected) {
538 fprintf(stderr, "malloc failed\n");
539 return 1;
540 }
541
542 /* Fill expected buffer with pattern */
543 for (i = 0; i < total_len; i++)
544 expected[i] = i & 0xff;
545
546 fd = mkstemp(filename);
547 if (fd < 0) {
548 perror("mkstemp");
549 free(expected);
550 return 1;
551 }
552 unlink(filename);
553
554 /* Write expected data to file */
555 ret = write(fd, expected, total_len);
556 if (ret != total_len) {
557 fprintf(stderr, "file write failed: %d\n", ret);
558 close(fd);
559 free(expected);
560 return 1;
561 }
562
563 /* Clear registered buffer before reading into it */
564 memset(bd->buf_wr, 0, bd->size);
565
566 /* Read using READV_FIXED - vecs already point to bd->buf_wr (registered) */
567 sqe = io_uring_get_sqe(ring);
568 io_uring_prep_readv_fixed(sqe, fd, vecs, nr_vec, 0, 0, buf_idx);
569
570 ret = io_uring_submit(ring);
571 if (ret != 1) {
572 fprintf(stderr, "submit failed %i\n", ret);
573 close(fd);
574 free(expected);
575 return 1;
576 }
577
578 ret = io_uring_wait_cqe(ring, &cqe);
579 if (ret) {
580 fprintf(stderr, "wait_cqe=%d\n", ret);

Callers 1

test_readvFunction · 0.85

Calls 3

t_iovec_data_lengthFunction · 0.85
io_uring_submitFunction · 0.85
io_uring_get_sqeFunction · 0.50

Tested by

no test coverage detected