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

Function test

test/fixed-reuse.c:25–118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23#define BSIZE 4096
24
25static int test(struct io_uring *ring)
26{
27 struct io_uring_cqe *cqe;
28 struct io_uring_sqe *sqe;
29 char buf[BSIZE];
30 int ret, i;
31
32 /* open FNAME1 in slot 0 */
33 sqe = io_uring_get_sqe(ring);
34 io_uring_prep_openat_direct(sqe, AT_FDCWD, FNAME1, O_RDONLY, 0, 0);
35 sqe->user_data = 1;
36
37 ret = io_uring_submit(ring);
38 if (ret != 1) {
39 fprintf(stderr, "sqe submit failed: %d\n", ret);
40 goto err;
41 }
42
43 ret = io_uring_wait_cqe(ring, &cqe);
44 if (ret < 0) {
45 fprintf(stderr, "wait completion %d\n", ret);
46 goto err;
47 }
48 if (cqe->res != 0) {
49 fprintf(stderr, "open res %d\n", ret);
50 goto err;
51 }
52 io_uring_cqe_seen(ring, cqe);
53
54 /*
55 * Now open FNAME2 in that same slot, verifying we get data from
56 * FNAME2 and not FNAME1.
57 */
58 sqe = io_uring_get_sqe(ring);
59 io_uring_prep_openat_direct(sqe, AT_FDCWD, FNAME2, O_RDONLY, 0, 0);
60 sqe->flags |= IOSQE_IO_LINK;
61 sqe->user_data = 2;
62
63 sqe = io_uring_get_sqe(ring);
64 io_uring_prep_read(sqe, 0, buf, sizeof(buf), 0);
65 sqe->flags |= IOSQE_FIXED_FILE;
66 sqe->flags |= IOSQE_IO_LINK;
67 sqe->user_data = 3;
68
69 sqe = io_uring_get_sqe(ring);
70 io_uring_prep_close_direct(sqe, 0);
71 sqe->user_data = 4;
72
73 ret = io_uring_submit(ring);
74 if (ret != 3) {
75 fprintf(stderr, "sqe submit failed: %d\n", ret);
76 goto err;
77 }
78
79 for (i = 0; i < 3; i++) {
80 ret = io_uring_wait_cqe(ring, &cqe);
81 if (ret < 0) {
82 fprintf(stderr, "wait completion %d\n", ret);

Callers 1

mainFunction · 0.70

Calls 2

io_uring_submitFunction · 0.85
io_uring_get_sqeFunction · 0.50

Tested by

no test coverage detected