Skip to content

Commit

Permalink
test/nop: test error injection
Browse files Browse the repository at this point in the history
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
axboe committed Aug 30, 2024
1 parent 502136a commit 0dfe5b7
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/nop.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,45 @@

static int seq;

static int test_nop_inject(struct io_uring *ring, unsigned req_flags)
{
struct io_uring_cqe *cqe;
struct io_uring_sqe *sqe;
int ret;

sqe = io_uring_get_sqe(ring);
if (!sqe) {
fprintf(stderr, "get sqe failed\n");
goto err;
}

io_uring_prep_nop(sqe);
sqe->user_data = ++seq;
sqe->nop_flags = IORING_NOP_INJECT_RESULT;
sqe->flags |= req_flags;
sqe->len = -EFAULT;

ret = io_uring_submit(ring);
if (ret <= 0) {
fprintf(stderr, "sqe submit failed: %d\n", ret);
goto err;
}

ret = io_uring_wait_cqe(ring, &cqe);
if (ret < 0) {
fprintf(stderr, "wait completion %d\n", ret);
goto err;
}
if (cqe->res != -EFAULT) {
fprintf(stderr, "expected injected result, got %d\n", cqe->res);
goto err;
}
io_uring_cqe_seen(ring, cqe);
return 0;
err:
return 1;
}

static int test_single_nop(struct io_uring *ring, unsigned req_flags)
{
struct io_uring_cqe *cqe;
Expand Down Expand Up @@ -151,6 +190,11 @@ static int test_ring(unsigned flags)
fprintf(stderr, "test_barrier_nop failed\n");
goto err;
}
ret = test_nop_inject(&ring, req_flags);
if (ret) {
fprintf(stderr, "test_nop_inject failed\n");
goto err;
}
}
err:
io_uring_queue_exit(&ring);
Expand Down

0 comments on commit 0dfe5b7

Please sign in to comment.