| 50 | } |
| 51 | |
| 52 | static int test(int nentries, int ring_flags) |
| 53 | { |
| 54 | struct io_uring ring; |
| 55 | unsigned values[2]; |
| 56 | int ret; |
| 57 | |
| 58 | ret = io_uring_queue_init(nentries, &ring, |
| 59 | IORING_SETUP_REGISTERED_FD_ONLY | IORING_SETUP_NO_MMAP | |
| 60 | ring_flags); |
| 61 | if (ret == -EINVAL || ret == -ENOENT) { |
| 62 | no_mmap = 1; |
| 63 | return T_EXIT_SKIP; |
| 64 | } else if (ret == -ENOMEM) { |
| 65 | fprintf(stdout, "Enable huge pages to test big rings\n"); |
| 66 | return T_EXIT_SKIP; |
| 67 | } else if (ret) { |
| 68 | fprintf(stderr, "ring setup failed: %d\n", ret); |
| 69 | return T_EXIT_FAIL; |
| 70 | } |
| 71 | |
| 72 | ret = io_uring_register_ring_fd(&ring); |
| 73 | if (ret != -EEXIST) { |
| 74 | fprintf(stderr, "registering already-registered ring fd should fail\n"); |
| 75 | goto err; |
| 76 | } |
| 77 | |
| 78 | ret = io_uring_close_ring_fd(&ring); |
| 79 | if (ret != -EBADF) { |
| 80 | fprintf(stderr, "closing already-closed ring fd should fail\n"); |
| 81 | goto err; |
| 82 | } |
| 83 | |
| 84 | /* Test a simple io_uring_register operation expected to work. |
| 85 | * io_uring_register_iowq_max_workers is arbitrary. |
| 86 | */ |
| 87 | values[0] = values[1] = 0; |
| 88 | ret = io_uring_register_iowq_max_workers(&ring, values); |
| 89 | if (ret || (values[0] == 0 && values[1] == 0)) { |
| 90 | fprintf(stderr, "io_uring_register operation failed after closing ring fd\n"); |
| 91 | goto err; |
| 92 | } |
| 93 | |
| 94 | ret = test_nops(&ring, nentries, nentries * 4); |
| 95 | if (ret) |
| 96 | goto err; |
| 97 | |
| 98 | io_uring_queue_exit(&ring); |
| 99 | return T_EXIT_PASS; |
| 100 | |
| 101 | err: |
| 102 | io_uring_queue_exit(&ring); |
| 103 | return T_EXIT_FAIL; |
| 104 | } |
| 105 | |
| 106 | int main(int argc, char *argv[]) |
| 107 | { |
no test coverage detected