[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <9221753abe0509ef5cbb474a31873012e0e40706.1690733545.git.tanyuan@tinylab.org>
Date: Mon, 31 Jul 2023 13:51:00 +0800
From: Yuan Tan <tanyuan@...ylab.org>
To: w@....eu, thomas@...ch.de
Cc: falcon@...ylab.org, linux-kernel@...r.kernel.org,
linux-kselftest@...r.kernel.org, Yuan Tan <tanyuan@...ylab.org>
Subject: [PATCH v2 2/2] selftests/nolibc: add testcase for pipe
Add a testcase of pipe that child process sends message to parent
process.
Here we use memcmp() to avoid the output buffer issue.
Suggested-by: Thomas Weißschuh <thomas@...ch.de>
Suggested-by: Willy Tarreau <w@....eu>
Link: https://lore.kernel.org/all/c5de2d13-3752-4e1b-90d9-f58cca99c702@t-8ch.de/
Signed-off-by: Yuan Tan <tanyuan@...ylab.org>
---
tools/testing/selftests/nolibc/nolibc-test.c | 35 ++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index 03b1d30f5507..2653ab8d5124 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -767,6 +767,41 @@ int test_mmap_munmap(void)
return ret;
}
+int test_pipe(void)
+{
+ const char *const msg = "hello, nolibc";
+ int pipefd[2];
+ char buf[32];
+ pid_t pid;
+ ssize_t len;
+
+ if (pipe(pipefd) == -1)
+ return 1;
+
+ pid = fork();
+
+ switch (pid) {
+ case -1:
+ return 1;
+
+ case 0:
+ close(pipefd[0]);
+ write(pipefd[1], msg, strlen(msg));
+ close(pipefd[1]);
+ exit(EXIT_SUCCESS);
+
+ default:
+ close(pipefd[1]);
+ len = read(pipefd[0], buf, sizeof(buf));
+ close(pipefd[0]);
+ waitpid(pid, NULL, 0);
+
+ if (len != strlen(msg))
+ return 1;
+ return !!memcmp(buf, msg, len);
+ }
+}
+
/* Run syscall tests between IDs <min> and <max>.
* Return 0 on success, non-zero on failure.
--
2.34.1
Powered by blists - more mailing lists