Message ID | 61bdfe7bacebdef8aa9195f6f2550a5b0d33aab3.1685426545.git.falcon@tinylab.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1967751vqr; Mon, 29 May 2023 23:16:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6ApPND99NlPY2JUt2U+hFDytFBYIXS2KhzC3+cde2ePQejZZYwotRG9MJlomH44adVCovy X-Received: by 2002:a05:6a00:2e17:b0:646:f971:b179 with SMTP id fc23-20020a056a002e1700b00646f971b179mr2170430pfb.16.1685427405461; Mon, 29 May 2023 23:16:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685427405; cv=none; d=google.com; s=arc-20160816; b=hrRYKsM+1ugqbI5pi61j2k3clgcgM/08Fvbx8/aTnqBqyaFVfbEw96krN1APLlULYh 5rtbc2ZMtrMrMcP3nPnNa0WmtD3/Wsyv3RD6hmfXP4YABXJoRiixzbYpovcAzvVvFQcl r0PdZqAXP4JYixiXi3sH7afxt1TjEt9mu1VbHjfdUBPVYkD47crPczO6iMC4hbzqsDEL ow4VT2SRiCMpBWPYxZhCpxrYeHot/48E5kZejrmMnPlfDtAAJ+lV6VrzpT0AeQhmI4Ea 2a380e3fOWWUd//v2z6S7LtmGVSw4dVwNZovW3kXjSmwPUO8Q8idry+DSH71YvHkmtUf aZ9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from; bh=/NhNCij1Hj23S6EIJzo0+w3iKFt84u7jbW8XhPol1Ig=; b=fu6/YS3FlXHu/B1FBHNDxgYzkS2YaG2Q7qVt48B40DGc8H+Fn4jiDgIcXJUM7TC0O0 QgdLvMqw4pZWy4cJS8xq0Ndq7XXn/GIOzexwfWCcSV/h4lyrvIPirMrjIuG52I9b+zS5 HDTCmZdO56jGtcI00sQTLtJDITOTaCXoFtiQEdhOlSmZ1LVscnijs98AIZYYbBczk/7Q +Lk8wMgOQ/oAUuaTv6/59qHHX93Mkk/MNuTPeR8dsHphkhhkzIssU855XTMakAM6u2RF TXLsgMm+jcpXgKmRuXZnyL2OD5lgcDTpnm2GI30KR8oAT6I52MjX41z6/KbOx2tL2RKP RIIg== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q10-20020aa7982a000000b00643a695e976si1140343pfl.291.2023.05.29.23.16.30; Mon, 29 May 2023 23:16:45 -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 S230156AbjE3GDp (ORCPT <rfc822;andrewvogler123@gmail.com> + 99 others); Tue, 30 May 2023 02:03:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229864AbjE3GDn (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 30 May 2023 02:03:43 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.221.58]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06A5CB0; Mon, 29 May 2023 23:03:40 -0700 (PDT) X-QQ-mid: bizesmtp64t1685426616t6i79jvf Received: from linux-lab-host.localdomain ( [119.123.130.226]) by bizesmtp.qq.com (ESMTP) with id ; Tue, 30 May 2023 14:03:35 +0800 (CST) X-QQ-SSF: 01200000000000D0V000000A0000000 X-QQ-FEAT: LE7C6P2vL8TLgV2F0j76Wmms1UUKWbcxXK9RaWGqVHLu+pFIx8EiGjOM3wKRQ shwmo4Gsz/AGl71NVfCsxNc9+rc1p5oBNfN5GR3fWjMEDOmo6xVBlAVn/SYsc2yh2+yerBH N1F+4j+osjG2kC6gH2jgmO23OHID/6V/1DOg1IwkABmVrjIvDSaanYtJ/Ufbh1R2T3BhLPp zAPh/5PWc/Fh6VuzY6EXSGWzny2EbjFwOKfSCZL3WNtdbOFEFpsVZjUDBh6hJ93TBf84GWj Xvf677gSaPEbQa7rfxPWAz8rjlfS1yf5PvS9yuKKjvNQ6mrmV/kt8DWbGZ25MPM3gWwXhxc +uoslweEIgUDWS5SdNHRBO6cE/lFnHPGY/pKdlIlHeMuXkGxc7JFxnExV+FbQ== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 1020271105133103119 From: Zhangjin Wu <falcon@tinylab.org> To: w@1wt.eu Cc: thomas@t-8ch.de, falcon@tinylab.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH] selftests/nolibc: test_fork: fix up duplicated print Date: Tue, 30 May 2023 14:03:33 +0800 Message-Id: <61bdfe7bacebdef8aa9195f6f2550a5b0d33aab3.1685426545.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz3a-3 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767298727146744331?= X-GMAIL-MSGID: =?utf-8?q?1767298727146744331?= |
Series |
selftests/nolibc: test_fork: fix up duplicated print
|
|
Commit Message
Zhangjin Wu
May 30, 2023, 6:03 a.m. UTC
running nolibc-test with glibc on x86_64 got such print issue:
29 execve_root = -1 EACCES [OK]
30 fork30 fork = 0 [OK]
31 getdents64_root = 712 [OK]
The fork test case has three printf calls:
(1) llen += printf("%d %s", test, #name);
(2) llen += printf(" = %d %s ", expr, errorname(errno));
(3) llen += pad_spc(llen, 64, "[FAIL]\n"); --> vfprintf()
In the following scene, the above issue happens:
(a) The parent calls (1)
(b) The parent calls fork()
(c) The child runs and shares the print buffer of (1)
(d) The child exits, flushs the print buffer and closes its own stdout/stderr
* "30 fork" is printed at the first time.
(e) The parent calls (2) and (3), with "\n" in (3), it flushs the whole buffer
* "30 fork = 0 ..." is printed
Therefore, there are two "30 fork" in the stdout.
Between (a) and (b), if flush the stdout (and the sterr), the child in
stage (c) will not be able to 'see' the print buffer.
Signed-off-by: Zhangjin Wu <falcon@tinylab.org>
---
tools/testing/selftests/nolibc/nolibc-test.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
Comments
Hi, Willy What about this one for 2023xxxx-nolibc-rv32+stkp6? @Thomas, welcome your Reviewed-by If it is ok for you ;-) Best regards, Zhangjin > running nolibc-test with glibc on x86_64 got such print issue: > > 29 execve_root = -1 EACCES [OK] > 30 fork30 fork = 0 [OK] > 31 getdents64_root = 712 [OK] > > The fork test case has three printf calls: > > (1) llen += printf("%d %s", test, #name); > (2) llen += printf(" = %d %s ", expr, errorname(errno)); > (3) llen += pad_spc(llen, 64, "[FAIL]\n"); --> vfprintf() > > In the following scene, the above issue happens: > > (a) The parent calls (1) > (b) The parent calls fork() > (c) The child runs and shares the print buffer of (1) > (d) The child exits, flushs the print buffer and closes its own stdout/stderr > * "30 fork" is printed at the first time. > (e) The parent calls (2) and (3), with "\n" in (3), it flushs the whole buffer > * "30 fork = 0 ..." is printed > > Therefore, there are two "30 fork" in the stdout. > > Between (a) and (b), if flush the stdout (and the sterr), the child in > stage (c) will not be able to 'see' the print buffer. > > Signed-off-by: Zhangjin Wu <falcon@tinylab.org> > --- > tools/testing/selftests/nolibc/nolibc-test.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c > index 7de46305f419..88323a60aa4a 100644 > --- a/tools/testing/selftests/nolibc/nolibc-test.c > +++ b/tools/testing/selftests/nolibc/nolibc-test.c > @@ -486,7 +486,13 @@ static int test_getpagesize(void) > static int test_fork(void) > { > int status; > - pid_t pid = fork(); > + pid_t pid; > + > + /* flush the printf buffer to avoid child flush it */ > + fflush(stdout); > + fflush(stderr); > + > + pid = fork(); > > switch (pid) { > case -1: > -- > 2.25.1 > >
On 2023-06-02 10:41:57+0800, Zhangjin Wu wrote: > Hi, Willy > > What about this one for 2023xxxx-nolibc-rv32+stkp6? > > @Thomas, welcome your Reviewed-by If it is ok for you ;-) Indeed, good catch! Reviewed-by: Thomas Weißschuh <linux@weissschuh.net> > Best regards, > Zhangjin > > > running nolibc-test with glibc on x86_64 got such print issue: > > > > 29 execve_root = -1 EACCES [OK] > > 30 fork30 fork = 0 [OK] > > 31 getdents64_root = 712 [OK] > > > > The fork test case has three printf calls: > > > > (1) llen += printf("%d %s", test, #name); > > (2) llen += printf(" = %d %s ", expr, errorname(errno)); > > (3) llen += pad_spc(llen, 64, "[FAIL]\n"); --> vfprintf() > > > > In the following scene, the above issue happens: > > > > (a) The parent calls (1) > > (b) The parent calls fork() > > (c) The child runs and shares the print buffer of (1) > > (d) The child exits, flushs the print buffer and closes its own stdout/stderr > > * "30 fork" is printed at the first time. > > (e) The parent calls (2) and (3), with "\n" in (3), it flushs the whole buffer > > * "30 fork = 0 ..." is printed > > > > Therefore, there are two "30 fork" in the stdout. > > > > Between (a) and (b), if flush the stdout (and the sterr), the child in > > stage (c) will not be able to 'see' the print buffer. > > > > Signed-off-by: Zhangjin Wu <falcon@tinylab.org> > > --- > > tools/testing/selftests/nolibc/nolibc-test.c | 8 +++++++- > > 1 file changed, 7 insertions(+), 1 deletion(-) > > > > diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c > > index 7de46305f419..88323a60aa4a 100644 > > --- a/tools/testing/selftests/nolibc/nolibc-test.c > > +++ b/tools/testing/selftests/nolibc/nolibc-test.c > > @@ -486,7 +486,13 @@ static int test_getpagesize(void) > > static int test_fork(void) > > { > > int status; > > - pid_t pid = fork(); > > + pid_t pid; > > + > > + /* flush the printf buffer to avoid child flush it */ > > + fflush(stdout); > > + fflush(stderr); > > + > > + pid = fork(); > > > > switch (pid) { > > case -1: > > -- > > 2.25.1 > > > >
On Fri, Jun 02, 2023 at 12:20:34PM +0200, Thomas Weißschuh wrote: > On 2023-06-02 10:41:57+0800, Zhangjin Wu wrote: > > Hi, Willy > > > > What about this one for 2023xxxx-nolibc-rv32+stkp6? > > > > @Thomas, welcome your Reviewed-by If it is ok for you ;-) > > Indeed, good catch! > > Reviewed-by: Thomas Weißschuh <linux@weissschuh.net> And queued, thanks to you both! Willy
diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 7de46305f419..88323a60aa4a 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -486,7 +486,13 @@ static int test_getpagesize(void) static int test_fork(void) { int status; - pid_t pid = fork(); + pid_t pid; + + /* flush the printf buffer to avoid child flush it */ + fflush(stdout); + fflush(stderr); + + pid = fork(); switch (pid) { case -1: