Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2010095rwd; Fri, 2 Jun 2023 03:36:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7xsmn73BXhT3U8UY8+hmnlg+dF5JwjD6tBJpXbSZQxpObkp5gr0tWPV59aup28K/9I0ciW X-Received: by 2002:a05:6e02:810:b0:33b:3d21:7db3 with SMTP id u16-20020a056e02081000b0033b3d217db3mr8480122ilm.27.1685702217566; Fri, 02 Jun 2023 03:36:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685702217; cv=none; d=google.com; s=arc-20160816; b=JcDZ9IcHrum9N2epL7TBHz1S3YhHuyod6sEbFjjpO4oBcHiZcdPSP14E9htU2sUCZy N6eD09X/J88tsmgxWzZ4QX/BA9m+FGlX1TZfantRq0s/7FPRL3Fx/F4A11EXeLprcOtx g114Zg8BEeNjsL8zOc+9cM5Fn2073RoFIoJjxQFmWKj0Ge+QYN+PM32A2JBaRCqK6KKS VsTPxphYdG7tGd0ip5pSIcoqOsxNJ+hk5ALFtBfvITaozLAaC6+ObuFum42wFHnJ3Gi5 CwxYIvmNwFUyczqP2EfoRy9TN/Vr4SVz9TX6WyW8CwImeJnwWrr/KVyOSHUsfpKd7bp5 rifg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:dkim-signature:date; bh=hkV/Wzs0kTjYsFPY0h5OTMyHCL31M5FdW2Ahke28pGY=; b=Y/yx4y0HrPluaOcsMzRpqh5qlrxmsoSqwmrQeDBX3aLpT6aI4qJBJCmsp1aRkWX9xb pvZ4E6QjvGObN/zTEd00Ii4rhJMBIWWe1EoWp3GEl2bqD58uAfH2mu8pns6IKf86xBS/ mWdYeEx2Lx3ciB4H3TYwVyhBbEzYS5iehL6xjwwrl7gH6J2TNavFi8Ja8xMEOEw+kwDv UkalXnAMhRwcz3PCAx44QZoXqR1qYWT/14Hjylx989+wFXUIww4+kdz/784dEiuo4VMY kcGHOO1Om4J4Mq5rz5Pbm350vJJeAvJ2GWfaH+5F9cTv1HVa7HtcJuhqFSpAC6008Ibw 4tSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@t-8ch.de header.s=mail header.b="HXAY/JzA"; 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 k26-20020a637b5a000000b005301151503esi806717pgn.186.2023.06.02.03.36.41; Fri, 02 Jun 2023 03:36:57 -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; dkim=pass header.i=@t-8ch.de header.s=mail header.b="HXAY/JzA"; 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 S235304AbjFBKUq (ORCPT + 99 others); Fri, 2 Jun 2023 06:20:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233986AbjFBKUj (ORCPT ); Fri, 2 Jun 2023 06:20:39 -0400 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96B66194; Fri, 2 Jun 2023 03:20:38 -0700 (PDT) Date: Fri, 2 Jun 2023 12:20:34 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=t-8ch.de; s=mail; t=1685701235; bh=p8zy09hQZDIIVHzkSV9VXJxDfAUWj/mvEvyOT3k7A/Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=HXAY/JzAJzZGzRxkerz7y+d+s64mDEh57DaAujLAWHIUZJkFJSVPGYOa+IvRPH32t MTKDzLcBUTuikb6NM8VUOjmr9e63fAiEmOGZKG7pTGvVmorEemK6nGONfxAY38evcp WWvGkvyaAQTYpX3dXfxbB5L60xEVkWEpTRDqH9l8= From: Thomas =?utf-8?Q?Wei=C3=9Fschuh?= To: Zhangjin Wu Cc: w@1wt.eu, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH] selftests/nolibc: test_fork: fix up duplicated print Message-ID: References: <61bdfe7bacebdef8aa9195f6f2550a5b0d33aab3.1685426545.git.falcon@tinylab.org> <20230602024157.11151-1-falcon@tinylab.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20230602024157.11151-1-falcon@tinylab.org> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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: X-Mailing-List: linux-kernel@vger.kernel.org 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 > 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 > > --- > > 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 > > > >