* Test: submit reads consuming all buffers, refill, repeat. * Verifies data integrity through the whole process. */
| 43 | * Verifies data integrity through the whole process. |
| 44 | */ |
| 45 | static int test_read_drain_refill(void) |
| 46 | { |
| 47 | struct io_uring ring; |
| 48 | struct io_uring_buf_ring *br; |
| 49 | struct io_uring_sqe *sqe; |
| 50 | struct io_uring_cqe *cqe; |
| 51 | void *buf_base; |
| 52 | char *file_data; |
| 53 | const char *fname = ".buf-ring-stress-tmp"; |
| 54 | int fd, ret, round; |
| 55 | int total_read = 0; |
| 56 | |
| 57 | ret = io_uring_queue_init(32, &ring, 0); |
| 58 | if (ret) { |
| 59 | fprintf(stderr, "ring setup: %d\n", ret); |
| 60 | return T_EXIT_FAIL; |
| 61 | } |
| 62 | |
| 63 | /* Setup buffer ring */ |
| 64 | br = io_uring_setup_buf_ring(&ring, NR_BUFS, BGID, 0, &ret); |
| 65 | if (!br) { |
| 66 | if (ret == -EINVAL || ret == -ENOENT) { |
| 67 | io_uring_queue_exit(&ring); |
| 68 | return T_EXIT_SKIP; |
| 69 | } |
| 70 | fprintf(stderr, "buf ring setup: %d\n", ret); |
| 71 | io_uring_queue_exit(&ring); |
| 72 | return T_EXIT_FAIL; |
| 73 | } |
| 74 | |
| 75 | buf_base = malloc(NR_BUFS * BUF_SIZE); |
| 76 | if (!buf_base) |
| 77 | goto err; |
| 78 | |
| 79 | /* Create test file with known pattern */ |
| 80 | file_data = malloc(FILE_SIZE); |
| 81 | if (!file_data) |
| 82 | goto err; |
| 83 | |
| 84 | for (int i = 0; i < FILE_SIZE; i++) |
| 85 | file_data[i] = (char)(i & 0xff); |
| 86 | |
| 87 | fd = open(fname, O_CREAT | O_WRONLY | O_TRUNC, 0644); |
| 88 | if (fd < 0) { |
| 89 | perror("open write"); |
| 90 | free(file_data); |
| 91 | goto err; |
| 92 | } |
| 93 | if (write(fd, file_data, FILE_SIZE) != FILE_SIZE) { |
| 94 | perror("write"); |
| 95 | close(fd); |
| 96 | free(file_data); |
| 97 | goto err; |
| 98 | } |
| 99 | close(fd); |
| 100 | |
| 101 | fd = open(fname, O_RDONLY); |
| 102 | if (fd < 0) { |
no test coverage detected