Hi Thomas,
On Mon, 2023-07-31 at 08:10 +0200, Thomas Weißschuh wrote:
On 2023-07-31 13:51:00+0800, Yuan Tan wrote:
Add a testcase of pipe that child process sends message to parent process.
Thinking about it some more:
What's the advantage of going via a child process? The pipe should work the same within the same process.
The pipe is commonly used for process communication, and I think as a test case it is supposed to cover the most common scenarios.
Here we use memcmp() to avoid the output buffer issue.
This sentence is meaningless without the background from v1. You can drop it.
Got it.
Suggested-by: Thomas Weißschuh thomas@t-8ch.de Suggested-by: Willy Tarreau w@1wt.eu Link: https://lore.kernel.org/all/c5de2d13-3752-4e1b-90d9-f58cca99c702@t-8ch.de/ Signed-off-by: Yuan Tan tanyuan@tinylab.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)
Should be static and actually get called :-)
+{ + 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