summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2019-10-24 13:43:33 -0600
committerJens Axboe <axboe@kernel.dk>2019-10-24 13:46:58 -0600
commitd974c9fbe63497604335b07611bb73d734fcec94 (patch)
treeceda052b2b16e4390536f0b348f68b17997ef157
parent675ee6ac622ac4a5060db8f09f1b58a1d830b701 (diff)
downloadliburing-d974c9fbe63497604335b07611bb73d734fcec94.tar.gz
liburing-d974c9fbe63497604335b07611bb73d734fcec94.tar.bz2
test/accept: add test to see if we cancel correctly on exit
This will exit with 0 in both the normal and failure case, but the failure case will leave workers idle once done. We check for that in runtests.sh now. Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--test/accept.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/test/accept.c b/test/accept.c
index 64cdbaf..501af58 100644
--- a/test/accept.c
+++ b/test/accept.c
@@ -151,6 +151,48 @@ err:
return 1;
}
+static void sig_alrm(int sig)
+{
+ exit(0);
+}
+
+static int test_accept_cancel(void)
+{
+ struct io_uring m_io_uring;
+ struct io_uring_cqe *cqe;
+ struct io_uring_sqe *sqe;
+ int fd;
+
+ assert(io_uring_queue_init(32, &m_io_uring, 0) >= 0);
+
+ fd = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_TCP);
+
+ int32_t val = 1;
+ assert(setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &val, sizeof(val)) != -1);
+ assert(setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)) != -1);
+
+ struct sockaddr_in addr;
+
+ addr.sin_family = AF_INET;
+ addr.sin_port = 0x1235;
+ addr.sin_addr.s_addr = 0x0100007fU;
+
+ assert(bind(fd, (struct sockaddr*)&addr, sizeof(addr)) != -1);
+ assert(listen(fd, 128) != -1);
+
+ sqe = io_uring_get_sqe(&m_io_uring);
+ io_uring_prep_accept(sqe, fd, NULL, NULL, 0);
+ assert(io_uring_submit(&m_io_uring) != -1);
+
+ signal(SIGALRM, sig_alrm);
+ alarm(1);
+ assert(!io_uring_wait_cqe(&m_io_uring, &cqe));
+ io_uring_cqe_seen(&m_io_uring, cqe);
+
+ io_uring_queue_exit(&m_io_uring);
+ return 0;
+}
+
static int test_accept(void)
{
struct io_uring m_io_uring;
@@ -191,5 +233,11 @@ int main(int argc, char *argv[])
return ret;
}
+ ret = test_accept_cancel();
+ if (ret) {
+ fprintf(stderr, "test_accept_cancel failed\n");
+ return ret;
+ }
+
return 0;
}