diff mbox series

syscalls/pipe14: Add new test

Message ID 20230627051911.521-1-akumar@suse.de
State Accepted
Headers show
Series syscalls/pipe14: Add new test | expand

Commit Message

Avinesh Kumar June 27, 2023, 5:19 a.m. UTC
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

Comments

Cyril Hrubis June 27, 2023, 9:45 a.m. UTC | #1
Hi!
Applied, thanks.
diff mbox series

Patch

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
+};