From patchwork Sat Jun 3 08:17:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 102800 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1547037vqr; Sat, 3 Jun 2023 02:06:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ49L4N0cLHRDw8vtwPZNKhErpGkzJr73ROiXt4aEsVEWjHigTM4VN681Eav4p7EPXYK0/dl X-Received: by 2002:a05:6a20:158b:b0:104:ffd0:232a with SMTP id h11-20020a056a20158b00b00104ffd0232amr1250555pzj.8.1685783218137; Sat, 03 Jun 2023 02:06:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685783218; cv=none; d=google.com; s=arc-20160816; b=LI+jKFuNCwytkrC3wnO8NTB29oj3Mrf8MrLUigbu4XfJzckMDfbG227UZtSJBbk81o 6RWoAG+AOVyMJMV6i6OpBlaHDq9fOjYct3m4v+92Q6DyqhoOBme21ohZ2Te+EZxTJWv0 4oFNIx+HlUMfQLh2tWNjXWwYfBaH6SlOwpVc3ysmW4PsjSQ0fqxkCz0UrjRnB3f5XTxu jTiqGqH0A6uzbVsEkE+ZJ+/EAKUtCYGT0GhXwGKGUnWXBF/vih1wJ0V8kKcDZVM8YsiE UxrCsSeUFfJnV6HpTDlB/X4wP8dAHClkynv+In7yebZqKi7mj0ks1UT/GK1FGTkMxmCt sNuQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j24-20020a63cf18000000b00513af1fa0b5si2315278pgg.797.2023.06.03.02.06.46; Sat, 03 Jun 2023 02:06:58 -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 S234630AbjFCIR4 (ORCPT + 99 others); Sat, 3 Jun 2023 04:17:56 -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_Wei=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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767671823529833985?= X-GMAIL-MSGID: =?utf-8?q?1767671823529833985?= 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: