Skip to content

Commit

Permalink
test/resize-rings: add test case for same size resize
Browse files Browse the repository at this point in the history
The test patches had a bug where the same size resizing would succeed,
but it would not copy back the parameters. Hence mapping the rings
again would fail, as io_uring_params wasn't correct.

Add a specific test case for that.

Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
axboe committed Oct 23, 2024
1 parent a50745f commit f360cc0
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions test/resize-rings.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,51 @@ static int test_overflow(struct io_uring *ring)
return T_EXIT_PASS;
}

static int test_same_resize(int flags)
{
struct io_uring_params p = { };
struct io_uring_sqe *sqe;
struct io_uring_cqe *cqe;
struct io_uring ring;
int i, ret;

ret = io_uring_queue_init(32, &ring, flags);
if (ret)
return T_EXIT_FAIL;

p.sq_entries = 32;
p.cq_entries = 64;
ret = io_uring_resize_rings(&ring, &p);
if (ret) {
fprintf(stderr, "resize failed: %d\n", ret);
return T_EXIT_FAIL;
}

for (i = 0; i < 32; i++) {
sqe = io_uring_get_sqe(&ring);
io_uring_prep_nop(sqe);
sqe->user_data = i + 1;
}

io_uring_submit(&ring);

for (i = 0; i < 32; i++) {
ret = io_uring_wait_cqe(&ring, &cqe);
if (ret) {
fprintf(stderr, "wait_cqe: %d\n", ret);
return T_EXIT_FAIL;
}
if (cqe->user_data != i + 1) {
fprintf(stderr, "Found cqe at wrong offset\n");
return T_EXIT_FAIL;
}
io_uring_cqe_seen(&ring, cqe);
}

io_uring_queue_exit(&ring);
return T_EXIT_PASS;
}

static int test(int flags, int fd, int async)
{
struct io_uring_params p = {
Expand Down Expand Up @@ -469,6 +514,12 @@ static int test(int flags, int fd, int async)
return T_EXIT_FAIL;
}

ret = test_same_resize(flags);
if (ret == T_EXIT_FAIL) {
fprintf(stderr, "test_same_resize %x failed\n", flags);
return T_EXIT_FAIL;
}

io_uring_queue_exit(&ring);
return T_EXIT_PASS;
}
Expand Down

0 comments on commit f360cc0

Please sign in to comment.