| 8 | #include "helpers.h" |
| 9 | |
| 10 | int main(int argc, char *argv[]) |
| 11 | { |
| 12 | struct io_uring ring; |
| 13 | unsigned values[2]; |
| 14 | int ret; |
| 15 | |
| 16 | if (argc > 1) |
| 17 | return T_EXIT_SKIP; |
| 18 | |
| 19 | ret = io_uring_queue_init(8, &ring, 0); |
| 20 | if (ret) { |
| 21 | fprintf(stderr, "ring setup failed\n"); |
| 22 | return T_EXIT_FAIL; |
| 23 | } |
| 24 | |
| 25 | if (!(ring.features & IORING_FEAT_REG_REG_RING)) { |
| 26 | fprintf(stderr, "IORING_FEAT_REG_REG_RING not available in kernel\n"); |
| 27 | io_uring_queue_exit(&ring); |
| 28 | return T_EXIT_SKIP; |
| 29 | } |
| 30 | |
| 31 | ret = io_uring_close_ring_fd(&ring); |
| 32 | if (ret != -EINVAL) { |
| 33 | fprintf(stderr, "closing ring fd should EINVAL before register\n"); |
| 34 | goto err; |
| 35 | } |
| 36 | |
| 37 | ret = io_uring_unregister_ring_fd(&ring); |
| 38 | if (ret != -EINVAL) { |
| 39 | fprintf(stderr, "unregistering not-registered ring fd should fail\n"); |
| 40 | goto err; |
| 41 | } |
| 42 | |
| 43 | ret = io_uring_register_ring_fd(&ring); |
| 44 | if (ret != 1) { |
| 45 | fprintf(stderr, "registering ring fd failed\n"); |
| 46 | goto err; |
| 47 | } |
| 48 | |
| 49 | ret = io_uring_register_ring_fd(&ring); |
| 50 | if (ret != -EEXIST) { |
| 51 | fprintf(stderr, "registering already-registered ring fd should fail\n"); |
| 52 | goto err; |
| 53 | } |
| 54 | |
| 55 | /* Test a simple io_uring_register operation expected to work. |
| 56 | * io_uring_register_iowq_max_workers is arbitrary. |
| 57 | */ |
| 58 | values[0] = values[1] = 0; |
| 59 | ret = io_uring_register_iowq_max_workers(&ring, values); |
| 60 | if (ret || (values[0] == 0 && values[1] == 0)) { |
| 61 | fprintf(stderr, "io_uring_register operation failed before closing ring fd\n"); |
| 62 | goto err; |
| 63 | } |
| 64 | |
| 65 | ret = io_uring_close_ring_fd(&ring); |
| 66 | if (ret != 1) { |
| 67 | fprintf(stderr, "closing ring fd failed\n"); |
nothing calls this directly
no test coverage detected