From patchwork Tue Aug 1 15:40:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Yuan Tan X-Patchwork-Id: 13336952 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 DADC7C001DF for ; Tue, 1 Aug 2023 15:40:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231994AbjHAPko (ORCPT ); Tue, 1 Aug 2023 11:40:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232257AbjHAPkm (ORCPT ); Tue, 1 Aug 2023 11:40:42 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C058C18B; Tue, 1 Aug 2023 08:40:32 -0700 (PDT) X-QQ-mid: bizesmtp66t1690904426thfpaxec Received: from dslab-main2-ubuntu.tail147f4.ts ( [202.201.15.117]) by bizesmtp.qq.com (ESMTP) with id ; Tue, 01 Aug 2023 23:40:25 +0800 (CST) X-QQ-SSF: 01200000000000705000000A0000000 X-QQ-FEAT: kN2ypXZVqgwk/qBTNkd/iwlu662yQb25L197c9fZh4f02d1PhBEH9w+ZHw7Rb DlkUdXFYyspKmDSuSJXiIMbzbjgNRqkjqijFmGNyFtwdsRFrG3oMJnQ3J/4XtKc7ShV2PFG ek1MKLByFcQbrt2zsxytHpsxf5xa1Mh6V9Qi9uAsdEe+9DjTp8LxeiGbEN4fHAUQsvn4rAh NNFDpDG8gVDnEmmNOadR+qCTMNf5yOmt9dZ4LJTR27ApvzJ4uD+M32A451Sft4YN76apPBu vixRcPOdbDHBHVCwLXMuPi04EZOue08fwYz28/EdyooUDGcLljWKfoPUqMlumGAeFHTt8yv QhhuSvEqMsfTJo1HmVLY8qxjQEBjBlQ1WS9Hhyh/iL4x6rNwzyB6ty1JVK3MQ== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 5494693937254520093 From: Yuan Tan To: w@1wt.eu, thomas@t-8ch.de Cc: falcon@tinylab.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Yuan Tan Subject: [PATCH v3 2/2] selftests/nolibc: add testcase for pipe Date: Tue, 1 Aug 2023 23:40:23 +0800 Message-Id: <508ed252b8f60494d70cd211debbb297ee916325.1690903601.git.tanyuan@tinylab.org> X-Mailer: git-send-email 2.34.1 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 test case of pipe that sends and receives message in a single process. Suggested-by: Thomas Weißschuh Suggested-by: Willy Tarreau Link: https://lore.kernel.org/all/c5de2d13-3752-4e1b-90d9-f58cca99c702@t-8ch.de/ Signed-off-by: Yuan Tan --- tools/testing/selftests/nolibc/nolibc-test.c | 22 ++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 03b1d30f5507..e5667fa3cf0a 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -767,6 +767,27 @@ int test_mmap_munmap(void) return ret; } +static int test_pipe(void) +{ + const char *const msg = "hello, nolibc"; + int pipefd[2]; + char buf[32]; + ssize_t len; + + if (pipe(pipefd) == -1) + return 1; + + write(pipefd[1], msg, strlen(msg)); + close(pipefd[1]); + len = read(pipefd[0], buf, sizeof(buf)); + close(pipefd[0]); + + if (len != strlen(msg)) + return 1; + + return !!memcmp(buf, msg, len); +} + /* Run syscall tests between IDs and . * Return 0 on success, non-zero on failure. @@ -851,6 +872,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;