From: Pavel Begunkov <[email protected]>
To: Jens Axboe <[email protected]>,
[email protected], Clay Harris <[email protected]>
Subject: [PATCH liburing 3/3] tee/test: add test for tee(2)
Date: Sat, 2 May 2020 15:11:29 +0300 [thread overview]
Message-ID: <0c63f91aa48ef8da42f995028c122445cf610c3c.1588421430.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>
Add tee() tests with pipe data validation
Signed-off-by: Pavel Begunkov <[email protected]>
---
test/splice.c | 184 ++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 157 insertions(+), 27 deletions(-)
diff --git a/test/splice.c b/test/splice.c
index 50a1feb..b084d04 100644
--- a/test/splice.c
+++ b/test/splice.c
@@ -29,6 +29,8 @@ struct test_ctx {
static int splice_flags = 0;
static int sqe_flags = 0;
static int no_op = 0;
+static int has_splice = 0;
+static int has_tee = 0;
static int read_buf(int fd, void *buf, int len)
{
@@ -133,10 +135,11 @@ static int init_splice_ctx(struct test_ctx *ctx)
return 0;
}
-static int do_splice(struct io_uring *ring,
- int fd_in, loff_t off_in,
- int fd_out, loff_t off_out,
- unsigned int len)
+static int do_splice_op(struct io_uring *ring,
+ int fd_in, loff_t off_in,
+ int fd_out, loff_t off_out,
+ unsigned int len,
+ __u8 opcode)
{
struct io_uring_cqe *cqe;
struct io_uring_sqe *sqe;
@@ -152,6 +155,7 @@ static int do_splice(struct io_uring *ring,
len, splice_flags);
sqe->flags |= sqe_flags;
sqe->user_data = 42;
+ sqe->opcode = opcode;
ret = io_uring_submit(ring);
if (ret != 1) {
@@ -183,18 +187,59 @@ static int do_splice(struct io_uring *ring,
return 0;
}
-static int check_splice(struct io_uring *ring, struct test_ctx *ctx)
+static int do_splice(struct io_uring *ring,
+ int fd_in, loff_t off_in,
+ int fd_out, loff_t off_out,
+ unsigned int len)
+{
+ return do_splice_op(ring, fd_in, off_in, fd_out, off_out, len,
+ IORING_OP_SPLICE);
+}
+
+static int do_tee(struct io_uring *ring,
+ int fd_in, loff_t off_in,
+ int fd_out, loff_t off_out,
+ unsigned int len)
+{
+ if (off_in == -1)
+ off_in = 0;
+ if (off_out == -1)
+ off_out = 0;
+
+ return do_splice_op(ring, fd_in, off_in, fd_out, off_out, len,
+ IORING_OP_TEE);
+}
+
+static void check_splice_support(struct io_uring *ring, struct test_ctx *ctx)
{
int fds[2];
if (pipe(fds) < 0)
- return -1;
+ return;
no_op = 0;
do_splice(ring, ctx->fd_in, 0, fds[1], -1, BUF_SIZE);
close(fds[0]);
close(fds[1]);
- return no_op;
+ has_splice = !no_op;
+}
+
+static void check_tee_support(struct io_uring *ring, struct test_ctx *ctx)
+{
+ int pipe1[2], pipe2[2];
+
+ if (pipe(pipe1) < 0)
+ return;
+ if (pipe(pipe2) < 0)
+ return;
+
+ no_op = 0;
+ do_tee(ring, pipe1[0], -1, pipe2[1], -1, 0);
+ close(pipe1[0]);
+ close(pipe1[1]);
+ close(pipe2[0]);
+ close(pipe2[1]);
+ has_tee = !no_op;
}
static int splice_to_pipe(struct io_uring *ring, struct test_ctx *ctx)
@@ -275,37 +320,120 @@ static int fail_splice_pipe_offset(struct io_uring *ring, struct test_ctx *ctx)
return 0;
}
-static int test_splice(struct io_uring *ring, struct test_ctx *ctx)
+static int fail_tee_with_file(struct io_uring *ring, struct test_ctx *ctx)
{
int ret;
- ret = splice_to_pipe(ring, ctx);
- if (ret) {
- fprintf(stderr, "splice_to_pipe failed %i %i\n",
- ret, errno);
+ ret = do_tee(ring, ctx->fd_in, 0, ctx->pipe1[1], 0, BUF_SIZE);
+ if (ret != -ESPIPE && ret != -EINVAL)
return ret;
- }
- ret = splice_from_pipe(ring, ctx);
- if (ret) {
- fprintf(stderr, "splice_from_pipe failed %i %i\n",
- ret, errno);
+ return 0;
+}
+
+static int fail_tee_offset(struct io_uring *ring, struct test_ctx *ctx)
+{
+ int ret;
+
+ ret = do_splice_op(ring, ctx->pipe2[0], -1, ctx->pipe1[1], 0,
+ BUF_SIZE, IORING_OP_TEE);
+ if (ret != -ESPIPE && ret != -EINVAL)
return ret;
- }
- ret = splice_pipe_to_pipe(ring, ctx);
+ ret = do_splice_op(ring, ctx->pipe2[0], 0, ctx->pipe1[1], -1,
+ BUF_SIZE, IORING_OP_TEE);
+ if (ret != -ESPIPE && ret != -EINVAL)
+ return ret;
+
+ return 0;
+}
+
+static int check_tee(struct io_uring *ring, struct test_ctx *ctx)
+{
+ int ret;
+
+ ret = write_buf(ctx->real_pipe1[1], ctx->buf_in, BUF_SIZE);
+ if (ret)
+ return ret;
+ ret = do_tee(ring, ctx->pipe1[0], -1, ctx->pipe2[1], -1, BUF_SIZE);
+ if (ret)
+ return ret;
+
+ ret = check_content(ctx->real_pipe1[0], ctx->buf_out, BUF_SIZE,
+ ctx->buf_in);
if (ret) {
- fprintf(stderr, "splice_pipe_to_pipe failed %i %i\n",
- ret, errno);
+ fprintf(stderr, "tee(), invalid src data\n");
return ret;
}
- ret = fail_splice_pipe_offset(ring, ctx);
+ ret = check_content(ctx->real_pipe2[0], ctx->buf_out, BUF_SIZE,
+ ctx->buf_in);
if (ret) {
- fprintf(stderr, "fail_splice_pipe_offset failed %i %i\n",
- ret, errno);
+ fprintf(stderr, "tee(), invalid dst data\n");
return ret;
}
+
+ return 0;
+}
+
+
+static int test_splice(struct io_uring *ring, struct test_ctx *ctx)
+{
+ int ret;
+
+ if (has_splice) {
+ ret = splice_to_pipe(ring, ctx);
+ if (ret) {
+ fprintf(stderr, "splice_to_pipe failed %i %i\n",
+ ret, errno);
+ return ret;
+ }
+
+ ret = splice_from_pipe(ring, ctx);
+ if (ret) {
+ fprintf(stderr, "splice_from_pipe failed %i %i\n",
+ ret, errno);
+ return ret;
+ }
+
+ ret = splice_pipe_to_pipe(ring, ctx);
+ if (ret) {
+ fprintf(stderr, "splice_pipe_to_pipe failed %i %i\n",
+ ret, errno);
+ return ret;
+ }
+
+ ret = fail_splice_pipe_offset(ring, ctx);
+ if (ret) {
+ fprintf(stderr, "fail_splice_pipe_offset failed %i %i\n",
+ ret, errno);
+ return ret;
+ }
+ }
+
+ if (has_tee) {
+ ret = fail_tee_with_file(ring, ctx);
+ if (ret) {
+ fprintf(stderr, "fail_tee_with_file() failed %i %i\n",
+ ret, errno);
+ return ret;
+ }
+
+ ret = fail_tee_offset(ring, ctx);
+ if (ret) {
+ fprintf(stderr, "fail_tee_offset failed %i %i\n",
+ ret, errno);
+ return ret;
+ }
+
+ ret = check_tee(ring, ctx);
+ if (ret) {
+ fprintf(stderr, "check_tee() failed %i %i\n",
+ ret, errno);
+ return ret;
+ }
+ }
+
return 0;
}
@@ -328,10 +456,12 @@ int main(int argc, char *argv[])
return 1;
}
- if (check_splice(&ring, &ctx)) {
+ check_splice_support(&ring, &ctx);
+ if (!has_splice)
fprintf(stdout, "skip, doesn't support splice()\n");
- return 0;
- }
+ check_tee_support(&ring, &ctx);
+ if (!has_tee)
+ fprintf(stdout, "skip, doesn't support tee()\n");
ret = test_splice(&ring, &ctx);
if (ret) {
--
2.24.0
prev parent reply other threads:[~2020-05-02 12:12 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-02 12:11 [PATCH liburing 0/3] test tee Pavel Begunkov
2020-05-02 12:11 ` [PATCH liburing 1/3] splice/test: improve splice tests Pavel Begunkov
2020-05-02 12:11 ` [PATCH liburing 2/3] update io_uring.h with tee() Pavel Begunkov
2020-05-02 12:11 ` Pavel Begunkov [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0c63f91aa48ef8da42f995028c122445cf610c3c.1588421430.git.asml.silence@gmail.com \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox