Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp5329572rwb; Tue, 1 Aug 2023 00:10:29 -0700 (PDT) X-Google-Smtp-Source: APBJJlF9ejJyeQTIHgLV7QGn/CC0pA76STc8JZA2fclyDoPwsAIVUTnQi+b6J3+2gsr49TOIQ7K2 X-Received: by 2002:a05:6808:16a0:b0:3a7:51cd:966b with SMTP id bb32-20020a05680816a000b003a751cd966bmr189445oib.19.1690873829619; Tue, 01 Aug 2023 00:10:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690873829; cv=none; d=google.com; s=arc-20160816; b=QbGWvWq9o+ETnbwCBWJUCM0nXIeQxrDNUSFNkoi+7PNBL3FVWLCdzt83j9ZQBJQ2WH Eyxkb8LrNWWa4Z1toBvbXNtpO0o9RwOv20HLyUj3JimtgdgYwbjPMX4xGh6YYCkZC+AZ RHo+XYhjZ3f4PvsVshiMndxAqwdu1/Vq00TxyrFCOq9lhy81b3R0dQkpLs5fmk6mlOS6 RNn+0F3IzfCCDujU18BmUVFvU7UeLiM4ObQ5hZzYx286W1Cw1Zs9tywBU8WLwg+9+ssn 8vbd+r4PU+QfUkN6NCAX/VU17in5nhhv4B4685aBWYruS5gtheWlKaC/kdyYmO5iTuJt k1uQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id; bh=ILrYUrQcktECakkue39lw71N6v6R3whFplkmovaGf2k=; fh=wNDKJ5swWjyQ7F3jhyOCfLsKUoEXnQMMIrwc6LhVrIs=; b=XY8QVPtBh/YVhjPnOPW5GB6/SiO3cTN+qNrS35HWK/LuAgExdTFVGLG3nrs1X65idV ONytTWIHH+LxjXW4W0ZBp115VdyFHnXqgvIVJpp71nO3ldttKRxZIPIsuQXOnOhsUMrS F+uJ1XGKsrREa10xttss9gBN69GrCI22nI9w0aL7aO2tEww8OWVxZvWOYJjKAdtZgsCP 5iVmtEhS1sm+1yfMTtF4lS2QxzPRuGxmLeSAqEXa1MHkmKoE7tyDApJRcaenOUjf90dd RExnnfd944WyBQw/YMh4cNTMFbjiT1tYLNZj1zbXEzOnidv832pz9eF7e5DjyOFhkgNj VEqA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h23-20020a17090aea9700b0025c238650d1si8397869pjz.174.2023.08.01.00.10.17; Tue, 01 Aug 2023 00:10:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231952AbjHAGvv convert rfc822-to-8bit (ORCPT + 99 others); Tue, 1 Aug 2023 02:51:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231401AbjHAGvt (ORCPT ); Tue, 1 Aug 2023 02:51:49 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 256FC98; Mon, 31 Jul 2023 23:51:47 -0700 (PDT) X-QQ-mid: bizesmtp71t1690872701tsui0fld Received: from [172.18.158.193] ( [116.30.131.233]) by bizesmtp.qq.com (ESMTP) with id ; Tue, 01 Aug 2023 14:51:39 +0800 (CST) X-QQ-SSF: 01200000000000705000000A0000000 X-QQ-FEAT: ZkxZBO9qcf44GMyj7VnIU0nlWQiO6xiwChHQckw5pR7G6DunNXMpna7iu1/B1 a4a5k6ggt/PXHvYdKUth5QDKE4bs6sAxWnIIC7dH/sJjycMWQaw7lhvG7q7HWN7F4D9eA3M 9YFrxBjyMcUIISLmnWtzmv7OPMYRU7fkEJr8tn3S+lX3go4jMYvAFvG5qEmB/wFhfG40ASj UWUUDDNb+996HS15XMtnLMgh0/g/Qm1WbqSRbphc7C9bbs/lebZHv0NvnnvOpQRK7rvnv/G AR1ZHoSW2mri23OM27MnTFzuoal972CCPm3p6Qwpw10H1NmObWiUH2scsT7EjFSvracgDzz CUzs/oTG1M9TyOBCHAW11pqTQpW7RSqjTIULVs4jhfZhMGVFkg= X-QQ-GoodBg: 0 X-BIZMAIL-ID: 1130335647924404570 Message-ID: <2ADAE3198D1A85E3+c1c957d4706ee51d90e0b2a425a633eafcca8810.camel@tinylab.org> Subject: Re: [PATCH v2 2/2] selftests/nolibc: add testcase for pipe From: Yuan Tan To: Thomas =?ISO-8859-1?Q?Wei=DFschuh?= Cc: w@1wt.eu, falcon@tinylab.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, tanyuan@tinylab.org Date: Tue, 01 Aug 2023 14:51:40 +0800 In-Reply-To: <51b39ee9-7645-4759-9cc0-3cfe721a2757@t-8ch.de> References: <9221753abe0509ef5cbb474a31873012e0e40706.1690733545.git.tanyuan@tinylab.org> <2ba88bae-2986-4e70-9828-824d7b140277@t-8ch.de> <51b39ee9-7645-4759-9cc0-3cfe721a2757@t-8ch.de> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT User-Agent: Evolution 3.44.4-0ubuntu2 MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 X-Spam-Status: No, score=-0.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_RPBL, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Thomas, On Mon, 2023-07-31 at 20:28 +0200, Thomas Weißschuh wrote: > On 2023-08-01 02:01:36+0800, Yuan Tan wrote: > > Hi Thomas, > > On Mon, 2023-07-31 at 17:41 +0200, Thomas Weißschuh wrote: > > > On 2023-07-31 20:35:28+0800, Yuan Tan wrote: > > > > 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. > > > > > > The testcase is supposed to cover the code of nolibc. > > > It should be the *minimal* amount of code to be reasonable sure > > > that > > > the > > > code in nolibc does the correct thing. > > > If pipe() returns a value that behaves like a pipe I see no > > > reason to > > > doubt it will also survive fork(). > > > > > > Validating that would mean testing the kernel and not nolibc. > > > For the kernel there are different testsuites. > > > > > > Less code means less work for everyone involved, now and in the > > > future. > > > > > > > It's a good point and I never thought about this aspect. > > > > I wonder whether the code below is enough? > > > > static int test_pipe(void) > > { > >         int pipefd[2]; > > > >         if (pipe(pipefd) == -1) > >                 return 1; > > > >         close(pipefd[0]); > >         close(pipefd[1]); > > > >         return 0; > > } > > That is very barebones. > > If accidentally a wrong syscall number was used and the used syscall > would not take any arguments this test would still succeed. > > Keeping the write-read-cycle from the previous revision would test > that > nicely. Essentially the same code as before but without the fork(). > > > > > And I forgot to add this line: > > > >         CASE_TEST(pipe); EXPECT_SYSZR(1, test_pipe()); break; > > > > I will add it in next patch. > > > In the situation you described, that is indeed the case. Would this be fine? 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); }