Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp318635rwd; Mon, 12 Jun 2023 14:08:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5iWA3fcoQiFIobuhy8yTP+Q5W4fu2AhFGY5xLOCoPW8HyBIACs8he/SO+5L4SdH+O86WT1 X-Received: by 2002:a17:907:6d1d:b0:97e:a7a0:45de with SMTP id sa29-20020a1709076d1d00b0097ea7a045demr7720281ejc.13.1686604130121; Mon, 12 Jun 2023 14:08:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686604130; cv=none; d=google.com; s=arc-20160816; b=ZfhBkaVZ6mlcW4U0SCzQIGx+FGroE7tgo296kphAVUz96esXvvKNBb6EW3z6f1agrB W0anKrruC6d+QImA9sePYJaZSKuQ8OYqO4/5p8U62GDWXLO0TR7X5cKukSlQksxDyX5b O620d5ZsjNSe45Kiq2Fp5NpgNXzP2zZXZrpwFxks979oxwkP0+GhWykJdZzrpuu7EHC/ ZCrziML3mfHP1tTj7A65VKppXCTpdHiYbxxlYYtqg0ekWaADd3Smvvnv+jSUXSmyOQJb wuvkfStjeJTzzsQQOrSzeVNDdjMdrbTY1M2mduahl3WkM3m0pbsxn4QYdceCGvSa1qcK KIFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0o51GdbAlF6Qdzjvc0QB6W7GNTeXiHLTPvpTqlFKYBI=; b=POa0tOwOelZZViKJ5aSY5W62HHuWaKuBIAnoBV9waHRmgfGm48UO+i2MX7aU/+co4P ZXjSM6cc0xprVllM13hSkLl5aTrZ6NssktdXMGES9s2vxl/ZQnv7v2a8azurUesvs6pl SmFPJNqBs/XwxSX5jGom4Fo+Gk2usrZtb3k+r1FNWp99OeMUHKkdhi1I+udkMRhqHdmd k4W56eS/9YlMebsoerzPCvbghsux3JtmC+1BKirjnXKzqgb0e4KsMV27fGU1jlHHxGvk S3iYjW/BeUbgSxlxEytV2gI8W6cJcWzplLIZpIVjrGxjndaoQCv29lyu0owKsQdw0IHg b/Wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WX9V9qKL; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v1-20020a1709063bc100b00978779cfc97si5728182ejf.795.2023.06.12.14.08.24; Mon, 12 Jun 2023 14:08:50 -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=@kernel.org header.s=k20201202 header.b=WX9V9qKL; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238288AbjFLUtp (ORCPT + 99 others); Mon, 12 Jun 2023 16:49:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232598AbjFLUrs (ORCPT ); Mon, 12 Jun 2023 16:47:48 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 172CF2967 for ; Mon, 12 Jun 2023 13:46:46 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B66AB62F18 for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42767C4332A; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602717; bh=0zt8I95z1HUq9EJL6kDDSqhW2E6bfWG/BgIkZcsxQ8U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WX9V9qKLsrktkGY0S+pZbFzmbFyCgZjOfy8DMZKbSGE+YoFb3FPDQCpbgLs+Dxyfs ATd7B767sG4SF1yANN+ZOAcNqeawVfzRtZae3RHkoTsytEbvlLurC1P6tsl28JACzW CuPsVGv1peAkwoZ1Qoy8hMk28mfZVyH6q212xIH4vAuyv9VyMIQK+4a0I6kJe7aUf2 h6Pa1HFguJCyUpstDl3nePUREzp/QG6kWfev3YWSBqJ82Kpf2T3i7nM7JhZEhAKj1K cdznNUPJxW7S2jeuqIUWJ3g2Au6A9WCCyHHtAd+NaMdRz1jbkC8KfGRHE73coZdt+u amTfMpPOlTfxg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 10216CE3A85; Mon, 12 Jun 2023 13:45:16 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, Zhangjin Wu , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 40/53] selftests/nolibc: test_fork: fix up duplicated print Date: Mon, 12 Jun 2023 13:45:01 -0700 Message-Id: <20230612204514.292087-40-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 From: Zhangjin Wu 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 Reviewed-by: Thomas Weißschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- 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 d417ca5d976f..fa18e7dc35c8 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.40.1