summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2020-02-29 12:11:21 -0700
committerJens Axboe <axboe@kernel.dk>2020-02-29 12:11:21 -0700
commit00469d8d393d6c0783a0b29ce6f86b5b9ae620e1 (patch)
tree9cffe917508f6e4fc4a0396468de7303ef0bb6b8
parent66b3760a93d5c7b93a05c99adfd557fc1d7a46b0 (diff)
downloadliburing-00469d8d393d6c0783a0b29ce6f86b5b9ae620e1.tar.gz
liburing-00469d8d393d6c0783a0b29ce6f86b5b9ae620e1.tar.bz2
test/send_recvmsg: ensure that we get -ENOBUFS for no buffers
Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--test/send_recvmsg.c41
1 files changed, 29 insertions, 12 deletions
diff --git a/test/send_recvmsg.c b/test/send_recvmsg.c
index 8092947..e89e638 100644
--- a/test/send_recvmsg.c
+++ b/test/send_recvmsg.c
@@ -80,12 +80,21 @@ err:
return 1;
}
-static int do_recvmsg(struct io_uring *ring, struct iovec *iov)
+struct recv_data {
+ pthread_mutex_t *mutex;
+ int buf_select;
+ int no_buf_add;
+};
+
+static int do_recvmsg(struct io_uring *ring, struct iovec *iov,
+ struct recv_data *rd)
{
struct io_uring_cqe *cqe;
io_uring_wait_cqe(ring, &cqe);
if (cqe->res < 0) {
+ if (rd->no_buf_add && rd->buf_select)
+ return 0;
fprintf(stderr, "%s: failed cqe: %d\n", __FUNCTION__, cqe->res);
goto err;
}
@@ -97,6 +106,11 @@ static int do_recvmsg(struct io_uring *ring, struct iovec *iov)
iov->iov_base = (void *) cqe->user_data;
}
+ if (rd->no_buf_add && rd->buf_select) {
+ fprintf(stderr, "Expected -ENOBUFS: %d\n", cqe->res);
+ goto err;
+ }
+
if (cqe->res -1 != strlen(str)) {
fprintf(stderr, "got wrong length: %d/%d\n", cqe->res,
(int) strlen(str) + 1);
@@ -113,11 +127,6 @@ err:
return 1;
}
-struct recv_data {
- pthread_mutex_t *mutex;
- int buf_select;
-};
-
static void *recv_fn(void *data)
{
struct recv_data *rd = data;
@@ -138,7 +147,7 @@ static void *recv_fn(void *data)
goto err;
}
- if (rd->buf_select) {
+ if (rd->buf_select && !rd->no_buf_add) {
sqe = io_uring_get_sqe(&ring);
io_uring_prep_provide_buffers(sqe, buf, sizeof(buf) -1, 1,
BUF_GID, BUF_BID);
@@ -168,7 +177,7 @@ static void *recv_fn(void *data)
}
pthread_mutex_unlock(mutex);
- ret = do_recvmsg(&ring, &iov);
+ ret = do_recvmsg(&ring, &iov, rd);
io_uring_queue_exit(&ring);
@@ -234,7 +243,7 @@ err:
return 1;
}
-static int test(int buf_select)
+static int test(int buf_select, int no_buf_add)
{
struct recv_data rd;
pthread_mutexattr_t attr;
@@ -250,6 +259,7 @@ static int test(int buf_select)
rd.mutex = &mutex;
rd.buf_select = buf_select;
+ rd.no_buf_add = no_buf_add;
ret = pthread_create(&recv_thread, NULL, recv_fn, &rd);
if (ret) {
fprintf(stderr, "Thread create failed\n");
@@ -268,17 +278,24 @@ int main(int argc, char *argv[])
{
int ret;
- ret = test(0);
+ ret = test(0, 0);
if (ret) {
fprintf(stderr, "send_recvmsg 0 failed\n");
return 1;
}
- ret = test(1);
+ ret = test(1, 0);
if (ret) {
- fprintf(stderr, "send_recvmsg 1 failed\n");
+ fprintf(stderr, "send_recvmsg 1 0 failed\n");
return 1;
}
+ ret = test(1, 1);
+ if (ret) {
+ fprintf(stderr, "send_recvmsg 1 1 failed\n");
+ return 1;
+ }
+
+
return 0;
}