Skip to content

Commit

Permalink
test/sync-cancel: test IORING_ASYNC_CANCEL_OP
Browse files Browse the repository at this point in the history
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
axboe committed Aug 30, 2024
1 parent d75f774 commit c1a4213
Showing 1 changed file with 48 additions and 21 deletions.
69 changes: 48 additions & 21 deletions test/sync-cancel.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

static int no_sync_cancel;

static int test_sync_cancel_timeout(struct io_uring *ring, int async)
static int test_sync_cancel_timeout(struct io_uring *ring, int async, int by_op)
{
struct io_uring_sync_cancel_reg reg = { };
struct io_uring_sqe *sqe;
Expand Down Expand Up @@ -43,7 +43,8 @@ static int test_sync_cancel_timeout(struct io_uring *ring, int async)

usleep(10000);

reg.addr = 0x89;
reg.flags = IORING_ASYNC_CANCEL_OP;
reg.opcode = IORING_OP_READ;
reg.timeout.tv_nsec = 1;
ret = io_uring_register_sync_cancel(ring, &reg);
if (async) {
Expand Down Expand Up @@ -80,7 +81,7 @@ static int test_sync_cancel_timeout(struct io_uring *ring, int async)
}

static int test_sync_cancel(struct io_uring *ring, int async, int nr_all,
int use_fd)
int use_fd, int by_op)
{
struct io_uring_sync_cancel_reg reg = { };
struct io_uring_sqe *sqe;
Expand Down Expand Up @@ -168,64 +169,90 @@ int main(int argc, char *argv[])
else if (ret != T_SETUP_OK)
return ret;

ret = test_sync_cancel(&ring, 0, 0, 0);
ret = test_sync_cancel(&ring, 0, 0, 0, 0);
if (ret) {
fprintf(stderr, "test_sync_cancel 0 0 0 failed\n");
return T_EXIT_FAIL;
}
if (no_sync_cancel)
return T_EXIT_SKIP;

ret = test_sync_cancel(&ring, 1, 0, 0);
ret = test_sync_cancel(&ring, 0, 0, 0, 1);
if (ret) {
fprintf(stderr, "test_sync_cancel 1 0 0 failed\n");
fprintf(stderr, "test_sync_cancel 0 0 1 failed\n");
return T_EXIT_FAIL;
}

ret = test_sync_cancel(&ring, 0, 1, 0);
ret = test_sync_cancel(&ring, 1, 0, 0, 0);
if (ret) {
fprintf(stderr, "test_sync_cancel 0 1 0 failed\n");
fprintf(stderr, "test_sync_cancel 1 0 0 0 failed\n");
return T_EXIT_FAIL;
}

ret = test_sync_cancel(&ring, 1, 1, 0);
ret = test_sync_cancel(&ring, 1, 0, 0, 1);
if (ret) {
fprintf(stderr, "test_sync_cancel 1 1 0 failed\n");
fprintf(stderr, "test_sync_cancel 1 0 0 1 failed\n");
return T_EXIT_FAIL;
}

ret = test_sync_cancel(&ring, 0, 0, 1);

ret = test_sync_cancel(&ring, 0, 1, 0, 0);
if (ret) {
fprintf(stderr, "test_sync_cancel 0 0 1 failed\n");
fprintf(stderr, "test_sync_cancel 0 1 0 0 failed\n");
return T_EXIT_FAIL;
}

ret = test_sync_cancel(&ring, 0, 1, 0, 1);
if (ret) {
fprintf(stderr, "test_sync_cancel 0 1 0 1 failed\n");
return T_EXIT_FAIL;
}


ret = test_sync_cancel(&ring, 1, 1, 0, 0);
if (ret) {
fprintf(stderr, "test_sync_cancel 1 1 0 0 failed\n");
return T_EXIT_FAIL;
}

ret = test_sync_cancel(&ring, 0, 0, 1, 0);
if (ret) {
fprintf(stderr, "test_sync_cancel 0 0 1 0 failed\n");
return T_EXIT_FAIL;
}

ret = test_sync_cancel(&ring, 1, 0, 1, 0);
if (ret) {
fprintf(stderr, "test_sync_cancel 1 0 1 0 failed\n");
return T_EXIT_FAIL;
}

ret = test_sync_cancel(&ring, 1, 0, 1);
ret = test_sync_cancel(&ring, 0, 1, 1, 0);
if (ret) {
fprintf(stderr, "test_sync_cancel 1 0 1 failed\n");
fprintf(stderr, "test_sync_cancel 0 1 1 0 failed\n");
return T_EXIT_FAIL;
}

ret = test_sync_cancel(&ring, 0, 1, 1);
ret = test_sync_cancel(&ring, 1, 1, 1, 0);
if (ret) {
fprintf(stderr, "test_sync_cancel 0 1 1 failed\n");
fprintf(stderr, "test_sync_cancel 1 1 1 0 failed\n");
return T_EXIT_FAIL;
}

ret = test_sync_cancel(&ring, 1, 1, 1);
ret = test_sync_cancel_timeout(&ring, 0, 0);
if (ret) {
fprintf(stderr, "test_sync_cancel 1 1 1 failed\n");
fprintf(stderr, "test_sync_cancel_timeout 0 0\n");
return T_EXIT_FAIL;
}

ret = test_sync_cancel_timeout(&ring, 0);
ret = test_sync_cancel_timeout(&ring, 0, 1);
if (ret) {
fprintf(stderr, "test_sync_cancel_timeout 0\n");
fprintf(stderr, "test_sync_cancel_timeout 0 1\n");
return T_EXIT_FAIL;
}

/* must be last, leaves request */
ret = test_sync_cancel_timeout(&ring, 1);
ret = test_sync_cancel_timeout(&ring, 1, 0);
if (ret) {
fprintf(stderr, "test_sync_cancel_timeout 1\n");
return T_EXIT_FAIL;
Expand Down

0 comments on commit c1a4213

Please sign in to comment.