Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3260053rwd; Sat, 3 Jun 2023 01:43:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4sihVN1zdBxVGJGFRA/amUef5c8Atoz6harGL7FhbKE6hp9hBsiFQbx5JD3wTFjopcITrG X-Received: by 2002:a05:6a00:e05:b0:655:a7b4:2c8f with SMTP id bq5-20020a056a000e0500b00655a7b42c8fmr413792pfb.11.1685781813454; Sat, 03 Jun 2023 01:43:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685781813; cv=none; d=google.com; s=arc-20160816; b=kAP+lsFp4WxbGoQc6U9jjlhkONT14LThi03xHE3kzoMIlw5Nlv5hpGrRGIj1ERsSmY kfH93/FNIe4TrZni9FzOY5QZOpCMZUFZZdj/VqfbqNJm7/ab1kH9+eEXI4Gm/bzDAZYR XEos1LyirjT6ULLgHCxbBScZwk2oCoT7BP/ILe+v7yNtdVM376uOhg7VFFaf9GESKFy7 hIbqJBSeiLOO8fnyQ/xOnC65OgzTF4V5mZGR/xZ0IjE5ZJPsmEXaGaXH9Zt5vFeLgFJX JTcVq6tISHqfX/jGAoRANYCd0/IIzbz7DAH5y6mZUS2oVTcEmUaWX+J4gFnJwYKwiv+3 ko8Q== 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:references:in-reply-to:message-id:date:subject:cc:to :from; bh=jom/dMSefvBNaBXB220EbEgqzVjnmqxaJ35MmXEc7/s=; b=S6u7ZD4KrGmpguICr2VvlToGHolN7AhNYQBXphbSaJ6TS6bBOzaPgUmT+QuS0/kwZZ mtomHYOriOO82lFwap98RSW0fyIuUBKM73wmpb8ICrLvygI3mde/mi7gyVv3Lfq27XOj kftsDxZNz+79L+VGiIcilfa1MMBR9cpGsVNgiYkLhlfJ2iP1pj/QzfYfZYCheqBIZqrr LXPu6O7RStrsCIE1y2McUO+cpANdKwYOU2L7qsbKfzeb6HmrPQ8AyexnzG+dXbs4mTMn 8hAj9X35KUfEGQlO/yp3OLmCoLLSJCMYLnebM7fpxbGczxk0Ar19oj9siSN25J7kBFwP c4MQ== 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 j8-20020a637a48000000b0053f287c32besi2275334pgn.206.2023.06.03.01.43.21; Sat, 03 Jun 2023 01:43:33 -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 S234609AbjFCIRz (ORCPT + 99 others); Sat, 3 Jun 2023 04:17:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229539AbjFCIRx (ORCPT ); Sat, 3 Jun 2023 04:17:53 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAE5AE56; Sat, 3 Jun 2023 01:17:50 -0700 (PDT) X-QQ-mid: bizesmtp77t1685780261tx6oj29b Received: from linux-lab-host.localdomain ( [119.123.130.226]) by bizesmtp.qq.com (ESMTP) with id ; Sat, 03 Jun 2023 16:17:40 +0800 (CST) X-QQ-SSF: 01200000000000D0V000000A0000000 X-QQ-FEAT: E5K4RXiq5f16O7Lg/ibaIwDGJ/dBM+SgASgVWJNrZJ0DycLMa61F85p3zn/s0 pmVP+uUxVO+uRq/qEVaGBrw6dy5nIj47egVC3sA8D6LyXOmfE2qgnjJAplThr2LHojLED11 dN48gvX6BDj+6ZskNGLKC05GNgBi/1WsGLb1E+3d17NhlPgK0/LzJRM0pb94DuYlP0Nmb59 w/YBaNODEaG8SfvzKEIj3lR1qDDwBvXpe5afs1A1FBfiTrIN0OgVeJJbKuaREYCdlovpmwR TbYhxWH70C7N9rrtU2bVFSPPjUczDufHPnteLBOjhwo549unG3iUV5HoN68eGMNqiD9QnOE Mbf4IaVts3z35QJQ2XUbnjfxanJ+JTJpIGiU/3+zwyVM15wQhyWDL98jOVCeDUWXeWyrFpD X-QQ-GoodBg: 0 X-BIZMAIL-ID: 11015261677064545706 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, thomas@t-8ch.de, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Subject: [PATCH v3 12/12] selftests/nolibc: test_fork: fix up duplicated print Date: Sat, 3 Jun 2023 16:17:25 +0800 Message-Id: <4e090aff64abeca598d1bb6ee54b40ee4ce52858.1685777982.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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_MSPIKE_H3, RCVD_IN_MSPIKE_WL,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: X-Mailing-List: linux-kernel@vger.kernel.org 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. Reviewed-by: Thomas Weißschuh 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 e68c5692ec54..7dd950879161 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -490,7 +490,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