Skip to content

Commit

Permalink
test/io_uring_register: fix poll testing
Browse files Browse the repository at this point in the history
The test is buggy in that it sets up a ring with a size of 1, and then
expects POLLOUT or POLLIN to be set when polling the ring. However,
POLLIN will only be set if there are CQEs ready to reap, and the test
doesn't ensure that is the case. Which is fine since it's also
testing for POLLOUT, however POLLOUT is only true if the ring has
SQE entries available. But since it's a ring of size 1 AND the only
SQE is already being used, that is not going to be true either. Hence
it'll wait forever.

This used to work by accident as the internal io_uring test for
whether the SQ ring is full or not was buggy, and didn't take into
account whether they were committed already or not. Bump the ring size
to 2 so that the test will actually (kind of) work.

While at it, ensure that we test both SQPOLL and !SQPOLL for the poll
testing.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
axboe committed Oct 15, 2024
1 parent 89ed36b commit cbae992
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions test/io_uring_register.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,14 +436,14 @@ static int ioring_poll(struct io_uring *ring, int fd, int fixed)
return ret;
}

static int test_poll_ringfd(void)
static int __test_poll_ringfd(int ring_flags)
{
int status = 0;
int ret;
int fd;
struct io_uring ring;

ret = io_uring_queue_init(1, &ring, 0);
ret = io_uring_queue_init(2, &ring, ring_flags);
if (ret) {
perror("io_uring_queue_init");
return 1;
Expand All @@ -466,6 +466,17 @@ static int test_poll_ringfd(void)
return status;
}

static int test_poll_ringfd(void)
{
int ret;

ret = __test_poll_ringfd(0);
if (ret)
return ret;

return __test_poll_ringfd(IORING_SETUP_SQPOLL);
}

int main(int argc, char **argv)
{
int fd, ret;
Expand Down

0 comments on commit cbae992

Please sign in to comment.