diff options
author | Jens Axboe <axboe@kernel.dk> | 2020-05-23 16:52:43 -0600 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2020-05-23 16:52:43 -0600 |
commit | db4d0388694403998cda03ace5f31fd8a2acd6fc (patch) | |
tree | 4abf3d47364f979891d50abda19696928245b33c /test | |
parent | 87d9bc02cf4b88538a9ab6bfb5ad3e2d632d1134 (diff) | |
download | liburing-db4d0388694403998cda03ace5f31fd8a2acd6fc.tar.gz liburing-db4d0388694403998cda03ace5f31fd8a2acd6fc.tar.bz2 |
test/file-register: ensure write vs read is ordered
We submit both the read and write at the same time, there's no guarantee
the write is even started by the time the read is issued. Play it safe
and wait for the write before starting the read.
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'test')
-rw-r--r-- | test/file-register.c | 54 |
1 files changed, 34 insertions, 20 deletions
diff --git a/test/file-register.c b/test/file-register.c index 86abd4c..7400b3a 100644 --- a/test/file-register.c +++ b/test/file-register.c @@ -413,7 +413,7 @@ static int test_fixed_read_write(struct io_uring *ring, int index) struct io_uring_sqe *sqe; struct io_uring_cqe *cqe; struct iovec iov[2]; - int ret, i; + int ret; iov[0].iov_base = malloc(4096); iov[0].iov_len = 4096; @@ -431,6 +431,23 @@ static int test_fixed_read_write(struct io_uring *ring, int index) sqe->flags |= IOSQE_FIXED_FILE; sqe->user_data = 1; + ret = io_uring_submit(ring); + if (ret != 1) { + fprintf(stderr, "%s: got %d, wanted 1\n", __FUNCTION__, ret); + return 1; + } + + ret = io_uring_wait_cqe(ring, &cqe); + if (ret < 0) { + fprintf(stderr, "%s: io_uring_wait_cqe=%d\n", __FUNCTION__, ret); + return 1; + } + if (cqe->res != 4096) { + fprintf(stderr, "%s: write cqe->res=%d\n", __FUNCTION__, cqe->res); + return 1; + } + io_uring_cqe_seen(ring, cqe); + sqe = io_uring_get_sqe(ring); if (!sqe) { fprintf(stderr, "%s: failed to get sqe\n", __FUNCTION__); @@ -441,28 +458,25 @@ static int test_fixed_read_write(struct io_uring *ring, int index) sqe->user_data = 2; ret = io_uring_submit(ring); - if (ret != 2) { - fprintf(stderr, "%s: got %d, wanted 2\n", __FUNCTION__, ret); + if (ret != 1) { + fprintf(stderr, "%s: got %d, wanted 1\n", __FUNCTION__, ret); return 1; } - for (i = 0; i < 2; i++) { - ret = io_uring_wait_cqe(ring, &cqe); - if (ret < 0) { - fprintf(stderr, "%s: io_uring_wait_cqe=%d\n", __FUNCTION__, ret); - return 1; - } - if (cqe->res != 4096) { - fprintf(stderr, "%s: cqe->res=%d\n", __FUNCTION__, cqe->res); - return 1; - } - if (cqe->user_data == 2) { - if (memcmp(iov[1].iov_base, iov[0].iov_base, 4096)) { - fprintf(stderr, "%s: data mismatch\n", __FUNCTION__); - return 1; - } - } - io_uring_cqe_seen(ring, cqe); + ret = io_uring_wait_cqe(ring, &cqe); + if (ret < 0) { + fprintf(stderr, "%s: io_uring_wait_cqe=%d\n", __FUNCTION__, ret); + return 1; + } + if (cqe->res != 4096) { + fprintf(stderr, "%s: read cqe->res=%d\n", __FUNCTION__, cqe->res); + return 1; + } + io_uring_cqe_seen(ring, cqe); + + if (memcmp(iov[1].iov_base, iov[0].iov_base, 4096)) { + fprintf(stderr, "%s: data mismatch\n", __FUNCTION__); + return 1; } free(iov[0].iov_base); |