| 263 | } |
| 264 | |
| 265 | static int test(int first_good, int async, int overflow, int incremental) |
| 266 | { |
| 267 | struct io_uring_buf_ring *br; |
| 268 | struct io_uring_params p = { }; |
| 269 | struct io_uring_sqe *sqe; |
| 270 | struct io_uring_cqe *cqe; |
| 271 | struct io_uring ring; |
| 272 | int ret, fds[2], i, start_msg = 0; |
| 273 | int br_flags = 0; |
| 274 | char tmp[32]; |
| 275 | void *ptr[NR_BUFS]; |
| 276 | char *inc_index; |
| 277 | |
| 278 | p.flags = IORING_SETUP_CQSIZE; |
| 279 | if (!overflow) |
| 280 | p.cq_entries = NR_BUFS + 1; |
| 281 | else |
| 282 | p.cq_entries = NR_OVERFLOW; |
| 283 | ret = io_uring_queue_init_params(1, &ring, &p); |
| 284 | if (ret) { |
| 285 | fprintf(stderr, "ring setup failed: %d\n", ret); |
| 286 | return 1; |
| 287 | } |
| 288 | |
| 289 | if (incremental) { |
| 290 | if (no_buf_ring_inc) |
| 291 | return 0; |
| 292 | br_flags |= IOU_PBUF_RING_INC; |
| 293 | } |
| 294 | |
| 295 | br = io_uring_setup_buf_ring(&ring, NR_BUFS, BUF_BGID, br_flags, &ret); |
| 296 | if (!br) { |
| 297 | if (ret == -EINVAL) { |
| 298 | if (incremental) { |
| 299 | no_buf_ring_inc = 1; |
| 300 | return 0; |
| 301 | } |
| 302 | no_buf_ring = 1; |
| 303 | return 0; |
| 304 | } |
| 305 | fprintf(stderr, "Buffer ring register failed %d\n", ret); |
| 306 | return 1; |
| 307 | } |
| 308 | |
| 309 | if (pipe(fds) < 0) { |
| 310 | perror("pipe"); |
| 311 | return 1; |
| 312 | } |
| 313 | |
| 314 | if (!incremental) { |
| 315 | for (i = 0; i < NR_BUFS; i++) { |
| 316 | unsigned size = i <= 1 ? BUF_SIZE_FIRST : BUF_SIZE; |
| 317 | ptr[i] = malloc(size); |
| 318 | if (!ptr[i]) |
| 319 | return 1; |
| 320 | io_uring_buf_ring_add(br, ptr[i], size, i + 1, BR_MASK, i); |
| 321 | } |
| 322 | inc_index = NULL; |
no test coverage detected