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

Function test

test/ringbuf-status.c:80–219  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78}
79
80static int test(int invalid)
81{
82 struct io_uring_sqe *sqe;
83 struct io_uring_cqe *cqe;
84 struct io_uring ring;
85 struct io_uring_buf_ring *br;
86 int ret, i, fds[2];
87 uint16_t head;
88 char *buf;
89 void *ptr;
90 char output[16];
91
92 memset(output, 0x55, sizeof(output));
93
94 ret = io_uring_queue_init(NR_BUFS, &ring, 0);
95 if (ret) {
96 fprintf(stderr, "ring setup failed: %d\n", ret);
97 return 1;
98 }
99
100 if (pipe(fds) < 0) {
101 perror("pipe");
102 return T_EXIT_FAIL;
103 }
104
105 if (posix_memalign((void **) &buf, 4096, FSIZE))
106 return 1;
107
108 br = io_uring_setup_buf_ring(&ring, NR_BUFS, BGID, 0, &ret);
109 if (!br) {
110 if (ret == -EINVAL) {
111 no_buf_ring = 1;
112 free(buf);
113 return 0;
114 }
115 fprintf(stderr, "Buffer ring register failed %d\n", ret);
116 return 1;
117 }
118
119 ptr = buf;
120 for (i = 0; i < NR_BUFS; i++) {
121 io_uring_buf_ring_add(br, ptr, BUF_SIZE, i + 1, BR_MASK, i);
122 ptr += BUF_SIZE;
123 }
124 io_uring_buf_ring_advance(br, NR_BUFS);
125
126 /* head should be zero at this point */
127 head = 1;
128 if (!invalid)
129 ret = io_uring_buf_ring_head(&ring, BGID, &head);
130 else
131 ret = io_uring_buf_ring_head(&ring, BGID + 10, &head);
132 if (ret) {
133 if (ret == -EINVAL) {
134 no_buf_ring_status = 1;
135 free(buf);
136 return T_EXIT_SKIP;
137 }

Callers 1

mainFunction · 0.70

Calls 6

io_uring_queue_initFunction · 0.85
io_uring_setup_buf_ringFunction · 0.85
io_uring_buf_ring_headFunction · 0.85
io_uring_submitFunction · 0.85
io_uring_queue_exitFunction · 0.85
io_uring_get_sqeFunction · 0.50

Tested by

no test coverage detected