| 81 | } |
| 82 | |
| 83 | static int test_file(struct io_uring *ring, char *__fname) |
| 84 | { |
| 85 | struct io_uring_cqe *cqe; |
| 86 | struct io_uring_sqe *sqe; |
| 87 | struct __kernel_timespec ts; |
| 88 | char filename[64], *fname; |
| 89 | int fd, ret, i; |
| 90 | void *buf; |
| 91 | |
| 92 | if (!__fname) { |
| 93 | fname = filename; |
| 94 | sprintf(fname, ".defer-tw-timeout.%d", getpid()); |
| 95 | t_create_file(fname, 128*1024); |
| 96 | } else { |
| 97 | fname = __fname; |
| 98 | } |
| 99 | |
| 100 | fd = open(fname, O_RDONLY | O_DIRECT); |
| 101 | if (fd < 0) { |
| 102 | if (errno == EINVAL || errno == EPERM || errno == EACCES) { |
| 103 | if (!__fname) |
| 104 | unlink(fname); |
| 105 | return T_EXIT_SKIP; |
| 106 | } |
| 107 | perror("open"); |
| 108 | if (!__fname) |
| 109 | unlink(fname); |
| 110 | return T_EXIT_FAIL; |
| 111 | } |
| 112 | |
| 113 | if (!__fname) |
| 114 | unlink(fname); |
| 115 | |
| 116 | if (posix_memalign(&buf, 4096, 4096)) { |
| 117 | close(fd); |
| 118 | return T_EXIT_FAIL; |
| 119 | } |
| 120 | |
| 121 | sqe = io_uring_get_sqe(ring); |
| 122 | io_uring_prep_read(sqe, fd, buf, 4096, 0); |
| 123 | |
| 124 | ts.tv_sec = 1; |
| 125 | ts.tv_nsec = 0; |
| 126 | |
| 127 | ret = io_uring_submit_and_wait_timeout(ring, &cqe, 2, &ts, NULL); |
| 128 | if (ret != 1) { |
| 129 | fprintf(stderr, "unexpected wait ret %d\n", ret); |
| 130 | close(fd); |
| 131 | free(buf); |
| 132 | return T_EXIT_FAIL; |
| 133 | } |
| 134 | |
| 135 | for (i = 0; i < 2; i++) { |
| 136 | ret = io_uring_peek_cqe(ring, &cqe); |
| 137 | if (ret) |
| 138 | break; |
| 139 | io_uring_cqe_seen(ring, cqe); |
| 140 | } |
no test coverage detected