public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] syscalls/pipe14: Add new test
@ 2023-06-27  5:19 Avinesh Kumar
  2023-06-27  9:45 ` Cyril Hrubis
  0 siblings, 1 reply; 2+ messages in thread
From: Avinesh Kumar @ 2023-06-27  5:19 UTC (permalink / raw)
  To: ltp

New test to verify, if the write end of a pipe is closed, then a process
reading from the pipe will see end-of-file (i.e., read() returns 0) once it
has read all remaining data in the pipe.

Signed-off-by: Avinesh Kumar <akumar@suse.de>
---
 runtest/syscalls                          |  1 +
 testcases/kernel/syscalls/pipe/.gitignore |  1 +
 testcases/kernel/syscalls/pipe/pipe14.c   | 46 +++++++++++++++++++++++
 3 files changed, 48 insertions(+)
 create mode 100644 testcases/kernel/syscalls/pipe/pipe14.c

diff --git a/runtest/syscalls b/runtest/syscalls
index e5ad2c2f9..c6524d7c4 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -988,6 +988,7 @@ pipe10 pipe10
 pipe11 pipe11
 pipe12 pipe12
 pipe13 pipe13
+pipe14 pipe14
 
 pipe2_01 pipe2_01
 pipe2_02 pipe2_02
diff --git a/testcases/kernel/syscalls/pipe/.gitignore b/testcases/kernel/syscalls/pipe/.gitignore
index 23e7186a6..774d73205 100644
--- a/testcases/kernel/syscalls/pipe/.gitignore
+++ b/testcases/kernel/syscalls/pipe/.gitignore
@@ -11,3 +11,4 @@
 /pipe11
 /pipe12
 /pipe13
+/pipe14
diff --git a/testcases/kernel/syscalls/pipe/pipe14.c b/testcases/kernel/syscalls/pipe/pipe14.c
new file mode 100644
index 000000000..2d2969d82
--- /dev/null
+++ b/testcases/kernel/syscalls/pipe/pipe14.c
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2023 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Verify that, if the write end of a pipe is closed, then a process reading
+ * from the pipe will see end-of-file (i.e., read() returns 0) once it has
+ * read all remaining data in the pipe.
+ */
+
+#include "tst_test.h"
+
+static int fds[2];
+
+static void run(void)
+{
+	char wrbuf[] = "abcdefghijklmnopqrstuvwxyz";
+	char rdbuf[30];
+
+	memset(rdbuf, 0, sizeof(rdbuf));
+	SAFE_PIPE(fds);
+
+	SAFE_WRITE(SAFE_WRITE_ALL, fds[1], wrbuf, sizeof(wrbuf));
+	SAFE_CLOSE(fds[1]);
+
+	SAFE_READ(0, fds[0], rdbuf, sizeof(wrbuf));
+
+	TST_EXP_VAL(SAFE_READ(0, fds[0], rdbuf, 1), 0);
+	SAFE_CLOSE(fds[0]);
+}
+
+static void cleanup(void)
+{
+	if (fds[0] > 0)
+		SAFE_CLOSE(fds[0]);
+	if (fds[1] > 0)
+		SAFE_CLOSE(fds[1]);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.cleanup = cleanup
+};
-- 
2.41.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [LTP] [PATCH] syscalls/pipe14: Add new test
  2023-06-27  5:19 [LTP] [PATCH] syscalls/pipe14: Add new test Avinesh Kumar
@ 2023-06-27  9:45 ` Cyril Hrubis
  0 siblings, 0 replies; 2+ messages in thread
From: Cyril Hrubis @ 2023-06-27  9:45 UTC (permalink / raw)
  To: Avinesh Kumar; +Cc: ltp

Hi!
Applied, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-06-27  9:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-27  5:19 [LTP] [PATCH] syscalls/pipe14: Add new test Avinesh Kumar
2023-06-27  9:45 ` Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox