From patchwork Tue Jul 25 18:01:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuan Tan X-Patchwork-Id: 13326880 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3BB19C0015E for ; Tue, 25 Jul 2023 18:01:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232246AbjGYSBe (ORCPT ); Tue, 25 Jul 2023 14:01:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232289AbjGYSBd (ORCPT ); Tue, 25 Jul 2023 14:01:33 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55E431FF2; Tue, 25 Jul 2023 11:01:29 -0700 (PDT) X-QQ-mid: bizesmtp70t1690308084t5vcw89e Received: from localhost.localdomain ( [42.242.128.198]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 26 Jul 2023 02:01:23 +0800 (CST) X-QQ-SSF: 01200000000000403000B00A0000000 X-QQ-FEAT: ybg6K0M/reNhatuJAQj2pVlNYo7QSouh4qfAKOOGrsqpOAFklqw056+Ntmyga qaW+pewqcXh9WzeCoCMnFwpA5DYy9Z0WlEhvJmb7cIC8k7t9wsQ5yzxNpkuv9QJVbUflA/e qmM6U0pcIdjN3KNy/aecc5d7F3FJ1gXG0T+FskvW9g6BoH2kh9Tj5nR9To1heHtp60kbpGJ tKmfZeCL/sLwJV+N6GdH6zc4+C6AxKjgJx9j+RsW1/lcVafqDCflR76efmhm9Uz0mA3LB0L 7V1kxcINVYOZdQZ5V7Ls5Jhc61lZCfnxDzg67lQtU9pvGmjc9/AdvSnCEqoREdVZy/vn7lj wOh053nzx4vqPfIhG2qc8sLrgSGu9e2jDpfWYrnNBW0E2DLQXM= X-QQ-GoodBg: 0 X-BIZMAIL-ID: 15258818057665170873 From: Yuan Tan To: w@1wt.eu Cc: falcon@tinylab.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Yuan Tan Subject: [PATCH 1/2] tools/nolibc: add pipe() support Date: Tue, 25 Jul 2023 14:01:21 -0400 Message-Id: X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org pipe is crucial for shell. Signed-off-by: Yuan Tan --- tools/include/nolibc/sys.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index 8bfe7db20b80..09841fc266fe 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -752,6 +752,23 @@ int open(const char *path, int flags, ...) } +/* + * int pipe(int pipefd[2]); + */ + +static __attribute__((unused)) +int sys_pipe(int pipefd[2]) +{ + return my_syscall1(__NR_pipe, pipefd); +} + +static __attribute__((unused)) +int pipe(int pipefd[2]) +{ + return __sysret(sys_pipe(pipefd)); +} + + /* * int prctl(int option, unsigned long arg2, unsigned long arg3, * unsigned long arg4, unsigned long arg5); From patchwork Tue Jul 25 18:01:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuan Tan X-Patchwork-Id: 13326882 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0C95CC0015E for ; Tue, 25 Jul 2023 18:01:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232452AbjGYSBu (ORCPT ); Tue, 25 Jul 2023 14:01:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232383AbjGYSBl (ORCPT ); Tue, 25 Jul 2023 14:01:41 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7FCA2115; Tue, 25 Jul 2023 11:01:38 -0700 (PDT) X-QQ-mid: bizesmtp62t1690308093t9wenc48 Received: from localhost.localdomain ( [42.242.128.198]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 26 Jul 2023 02:01:32 +0800 (CST) X-QQ-SSF: 01200000000000403000B00A0000000 X-QQ-FEAT: hoArX50alxGfKCqcoJrDpBOVNpOBAj8Euz2UJh6j3yf0pnrWIamc1qk6NJsZy ZPdG6F8iyNMtFTdqKUKL/Y80gyczqCycfftYBrPWMlKrVYIJUsBXBCwq4dUDN9P/gRGQ6MX 5v25aVNj8TMCLPo2SaYhIll5Zlpo/tzxtqGCtW+EvmEfl+bowYQeHhK06ZkQGRojxoMsHfg MqDHWHmeJCKE0avHl7btJ2zcdw0ZpQYhMGYIfLkonv5xzILyLqC5SGFCNe5IWZOyxn6z4Po ldkvveqgISSqk/h/KcsH8ZmcYKQNEg/GrmvqFlrnIlsXP1TvwXRssxHReSNcT3OpPUS3rSb WI54hW64St4bxdwyT/GZd0Tt13b2WiJypbOQ+ol1nT5mO47I77QYh81YNn2RQ== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 4769715897786675155 From: Yuan Tan To: w@1wt.eu Cc: falcon@tinylab.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Yuan Tan Subject: [PATCH 2/2] selftests/nolibc: add testcase for pipe. Date: Tue, 25 Jul 2023 14:01:30 -0400 Message-Id: <160ddef0313e11085ee906144d6d9678b8156171.1690307717.git.tanyuan@tinylab.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Add a testcase of pipe that child process sends message to parent process. Signed-off-by: Yuan Tan --- tools/testing/selftests/nolibc/nolibc-test.c | 34 ++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 03b1d30f5507..43ba2884fd1e 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -767,6 +767,39 @@ int test_mmap_munmap(void) return ret; } +int test_pipe(void) +{ + int pipefd[2]; + char buf[32]; + pid_t pid; + char *msg = "hello, nolibc"; + + 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]); + read(pipefd[0], buf, 32); + close(pipefd[0]); + wait(NULL); + + if (strcmp(buf, msg)) + return 1; + return 0; + } +} /* Run syscall tests between IDs and . * Return 0 on success, non-zero on failure. @@ -851,6 +884,7 @@ int run_syscall(int min, int max) CASE_TEST(mmap_munmap_good); EXPECT_SYSZR(1, test_mmap_munmap()); break; CASE_TEST(open_tty); EXPECT_SYSNE(1, tmp = open("/dev/null", 0), -1); if (tmp != -1) close(tmp); break; CASE_TEST(open_blah); EXPECT_SYSER(1, tmp = open("/proc/self/blah", 0), -1, ENOENT); if (tmp != -1) close(tmp); break; + CASE_TEST(pipe); EXPECT_SYSZR(1, test_pipe()); break; CASE_TEST(poll_null); EXPECT_SYSZR(1, poll(NULL, 0, 0)); break; CASE_TEST(poll_stdout); EXPECT_SYSNE(1, ({ struct pollfd fds = { 1, POLLOUT, 0}; poll(&fds, 1, 0); }), -1); break; CASE_TEST(poll_fault); EXPECT_SYSER(1, poll((void *)1, 1, 0), -1, EFAULT); break;