| 1007 | }; |
| 1008 | |
| 1009 | static int __test_io(struct io_uring *ring, int fd, int write, |
| 1010 | int seq, struct iovec *vecs, int exp_len, off_t start) |
| 1011 | { |
| 1012 | struct io_uring_sqe *sqe; |
| 1013 | struct io_uring_cqe *cqe; |
| 1014 | int i, ret; |
| 1015 | off_t offset; |
| 1016 | |
| 1017 | offset = start; |
| 1018 | for (i = 0; i < BUFFERS; i++) { |
| 1019 | sqe = io_uring_get_sqe(ring); |
| 1020 | if (!sqe) { |
| 1021 | fprintf(stderr, "sqe get failed\n"); |
| 1022 | goto err; |
| 1023 | } |
| 1024 | if (!seq) |
| 1025 | offset = start + BS * (rand() % BUFFERS); |
| 1026 | if (write) { |
| 1027 | io_uring_prep_write_fixed(sqe, fd, vecs[i].iov_base, |
| 1028 | vecs[i].iov_len, |
| 1029 | offset, i); |
| 1030 | } else { |
| 1031 | io_uring_prep_read_fixed(sqe, fd, vecs[i].iov_base, |
| 1032 | vecs[i].iov_len, |
| 1033 | offset, i); |
| 1034 | } |
| 1035 | sqe->user_data = i; |
| 1036 | if (seq) |
| 1037 | offset += BS; |
| 1038 | } |
| 1039 | |
| 1040 | ret = io_uring_submit(ring); |
| 1041 | if (ret != BUFFERS) { |
| 1042 | fprintf(stderr, "submit got %d, wanted %d\n", ret, BUFFERS); |
| 1043 | goto err; |
| 1044 | } |
| 1045 | |
| 1046 | for (i = 0; i < BUFFERS; i++) { |
| 1047 | ret = io_uring_wait_cqe(ring, &cqe); |
| 1048 | if (ret) { |
| 1049 | fprintf(stderr, "wait_cqe=%d\n", ret); |
| 1050 | goto err; |
| 1051 | } |
| 1052 | if (exp_len == -1) { |
| 1053 | int iov_len = vecs[cqe->user_data].iov_len; |
| 1054 | |
| 1055 | if (cqe->res != iov_len) { |
| 1056 | fprintf(stderr, "cqe res %d, wanted %d\n", |
| 1057 | cqe->res, iov_len); |
| 1058 | goto err; |
| 1059 | } |
| 1060 | } else if (cqe->res != exp_len) { |
| 1061 | fprintf(stderr, "cqe res %d, wanted %d\n", cqe->res, exp_len); |
| 1062 | goto err; |
| 1063 | } |
| 1064 | io_uring_cqe_seen(ring, cqe); |
| 1065 | } |
| 1066 | |