From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 2/2] syscalls: Add test for splicing to /dev/zero and /dev/null
Date: Wed, 20 Mar 2024 10:59:27 +0100 [thread overview]
Message-ID: <20240320095927.19973-3-chrubis@suse.cz> (raw)
In-Reply-To: <20240320095927.19973-1-chrubis@suse.cz>
Both of these devices discard written data.
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/splice/.gitignore | 1 +
testcases/kernel/syscalls/splice/splice09.c | 55 +++++++++++++++++++++
3 files changed, 57 insertions(+)
create mode 100644 testcases/kernel/syscalls/splice/splice09.c
diff --git a/runtest/syscalls b/runtest/syscalls
index 0889f58a1..50bc350f0 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1518,6 +1518,7 @@ splice05 splice05
splice06 splice06
splice07 splice07
splice08 splice08
+splice09 splice09
tee01 tee01
tee02 tee02
diff --git a/testcases/kernel/syscalls/splice/.gitignore b/testcases/kernel/syscalls/splice/.gitignore
index 9453cf93a..96b1727a1 100644
--- a/testcases/kernel/syscalls/splice/.gitignore
+++ b/testcases/kernel/syscalls/splice/.gitignore
@@ -6,3 +6,4 @@
/splice06
/splice07
/splice08
+/splice09
diff --git a/testcases/kernel/syscalls/splice/splice09.c b/testcases/kernel/syscalls/splice/splice09.c
new file mode 100644
index 000000000..46f755b01
--- /dev/null
+++ b/testcases/kernel/syscalls/splice/splice09.c
@@ -0,0 +1,55 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test for splicing to /dev/zero and /dev/null these two devices discard all
+ * data written to them.
+ *
+ * The support for splicing to /dev/zero was added in:
+ * 1b057bd800c3 ("drivers/char/mem: implement splice() for /dev/zero, /dev/full")
+ */
+
+#define _GNU_SOURCE
+#include "tst_test.h"
+
+static const char *test_devices[] = {
+ "/dev/null",
+ "/dev/zero",
+};
+
+static void verify_splice(unsigned int n)
+{
+ char buf[1024];
+ char dev_fd;
+ int pipefd[2];
+
+ memset(buf, 0xff, sizeof(buf));
+
+ tst_res(TINFO, "Testing %s", test_devices[n]);
+
+ dev_fd = SAFE_OPEN(test_devices[n], O_WRONLY);
+
+ SAFE_PIPE(pipefd);
+ SAFE_WRITE(1, pipefd[1], buf, sizeof(buf));
+
+ TST_EXP_POSITIVE(splice(pipefd[0], NULL, dev_fd, NULL, sizeof(buf), 0));
+
+ if (TST_PASS && TST_RET != sizeof(buf))
+ tst_res(TFAIL, "Wrote only part of the pipe buffer");
+ else
+ tst_res(TPASS, "Wrote whole pipe buffer");
+
+ SAFE_CLOSE(pipefd[0]);
+ SAFE_CLOSE(pipefd[1]);
+ SAFE_CLOSE(dev_fd);
+}
+
+static struct tst_test test = {
+ .test = verify_splice,
+ .tcnt = ARRAY_SIZE(test_devices),
+ .min_kver = "6.7",
+};
--
2.43.2
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2024-03-20 10:00 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-20 9:59 [LTP] [PATCH 0/2] Add splice tests fro /dev/{zero,null,full} Cyril Hrubis
2024-03-20 9:59 ` [LTP] [PATCH 1/2] syscalls: Add test for splicing from /dev/zero and /dev/full Cyril Hrubis
2024-03-20 13:26 ` Jan Stancek
2024-04-11 10:43 ` Cyril Hrubis
2024-04-11 11:08 ` Jan Stancek
2024-04-11 11:50 ` Cyril Hrubis
2024-03-21 9:29 ` Petr Vorel
2024-04-11 10:42 ` Cyril Hrubis
2024-03-20 9:59 ` Cyril Hrubis [this message]
2024-03-21 9:33 ` [LTP] [PATCH 2/2] syscalls: Add test for splicing to /dev/zero and /dev/null Petr Vorel
2024-04-11 10:36 ` Cyril Hrubis
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=20240320095927.19973-3-chrubis@suse.cz \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).