MCPcopy Create free account
hub / github.com/axboe/liburing / test_write

Function test_write

test/fpos.c:141–223  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

139
140
141static int test_write(struct io_uring *ring, bool async, int blocksize)
142{
143 int ret, fd, i;
144 struct io_uring_sqe *sqe;
145 struct io_uring_cqe *cqe;
146 bool fail = false;
147 loff_t current;
148 char data[blocksize+1];
149 char readbuff[QUEUE_SIZE*blocksize+1];
150
151 fd = open(".test_fpos_write", O_RDWR | O_CREAT, 0644);
152 unlink(".test_fpos_write");
153 assert(fd >= 0);
154
155 for (i = 0; i < blocksize; i++)
156 data[i] = 'A' + i;
157
158 data[blocksize] = '\0';
159
160 for (i = 0; i < QUEUE_SIZE; ++i) {
161 sqe = io_uring_get_sqe(ring);
162 if (!sqe) {
163 fprintf(stderr, "no sqe\n");
164 return -1;
165 }
166 io_uring_prep_write(sqe, fd, data + (i % blocksize), 1, -1);
167 sqe->user_data = 1;
168 if (async)
169 sqe->flags |= IOSQE_ASYNC;
170 if (i != QUEUE_SIZE - 1)
171 sqe->flags |= IOSQE_IO_LINK;
172 }
173 ret = io_uring_submit_and_wait(ring, QUEUE_SIZE);
174 if (ret != QUEUE_SIZE) {
175 fprintf(stderr, "submit failed: %d\n", ret);
176 return 1;
177 }
178 for (i = 0; i < QUEUE_SIZE; ++i) {
179 int res;
180
181 ret = io_uring_peek_cqe(ring, &cqe);
182 res = cqe->res;
183 if (ret) {
184 fprintf(stderr, "peek failed: %d\n", ret);
185 return ret;
186 }
187 io_uring_cqe_seen(ring, cqe);
188 if (!fail && res != 1) {
189 fprintf(stderr, "bad result %d\n", res);
190 fail = true;
191 }
192 }
193 current = lseek(fd, 0, SEEK_CUR);
194 if (current != QUEUE_SIZE) {
195 fprintf(stderr, "f_pos incorrect, expected %ld have %d\n",
196 (long) current, QUEUE_SIZE);
197 fail = true;
198 }

Callers 1

mainFunction · 0.85

Calls 2

io_uring_submit_and_waitFunction · 0.85
io_uring_get_sqeFunction · 0.50

Tested by

no test coverage detected