| 59 | } |
| 60 | |
| 61 | static int pipe_test(int init_flags, struct params *p) |
| 62 | { |
| 63 | struct io_uring ring; |
| 64 | struct io_uring_sqe *sqe; |
| 65 | struct io_uring_cqe *cqe; |
| 66 | int ret, fds[2]; |
| 67 | |
| 68 | ret = io_uring_queue_init(8, &ring, init_flags); |
| 69 | /* can hit -ENOMEM due to repeated ring creation and teardowns */ |
| 70 | if (ret == -ENOMEM) { |
| 71 | usleep(1000); |
| 72 | return 0; |
| 73 | } else if (ret) { |
| 74 | fprintf(stderr, "ring_init: %d\n", ret); |
| 75 | return 1; |
| 76 | } |
| 77 | |
| 78 | if (p->fixed) { |
| 79 | int sz; |
| 80 | |
| 81 | if (p->too_small) |
| 82 | sz = 1; |
| 83 | else |
| 84 | sz = 100; |
| 85 | ret = io_uring_register_files_sparse(&ring, sz); |
| 86 | if (ret) { |
| 87 | if (ret == -EINVAL) { |
| 88 | no_pipe = 1; |
| 89 | return 0; |
| 90 | } |
| 91 | fprintf(stderr, "Failed to register sparse table %d\n", ret); |
| 92 | return 1; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | fds[0] = fds[1] = -1; |
| 97 | sqe = io_uring_get_sqe(&ring); |
| 98 | if (!p->fixed) |
| 99 | io_uring_prep_pipe(sqe, fds, 0); |
| 100 | else |
| 101 | io_uring_prep_pipe_direct(sqe, fds, 0, IORING_FILE_INDEX_ALLOC); |
| 102 | if (p->async) |
| 103 | sqe->flags |= IOSQE_ASYNC; |
| 104 | |
| 105 | io_uring_submit(&ring); |
| 106 | ret = io_uring_wait_cqe(&ring, &cqe); |
| 107 | if (ret) { |
| 108 | fprintf(stderr, "wait: %d\n", ret); |
| 109 | return 1; |
| 110 | } |
| 111 | if (cqe->res) { |
| 112 | if (cqe->res == -EINVAL) { |
| 113 | no_pipe = 1; |
| 114 | return 0; |
| 115 | } |
| 116 | if (p->fixed && p->too_small && cqe->res == -ENFILE) |
| 117 | goto done; |
| 118 | fprintf(stderr, "Bad cqe res %d\n", cqe->res); |
no test coverage detected