Message ID | 20230713135440.3651409-2-ryan.roberts@arm.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1855131vqm; Thu, 13 Jul 2023 07:15:22 -0700 (PDT) X-Google-Smtp-Source: APBJJlGn8o2IKaurD6n+7iY6bav6KHyPTi75isNYaj31t/BLGbX9c1eLVQt7a0ogk2/PSEygzhw3 X-Received: by 2002:a2e:b614:0:b0:2b6:faaa:fb53 with SMTP id r20-20020a2eb614000000b002b6faaafb53mr1456692ljn.26.1689257722188; Thu, 13 Jul 2023 07:15:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689257722; cv=none; d=google.com; s=arc-20160816; b=IAqRszVG3qI6qeRN40/9KyZCN097JIRsA0fwohEbJCmmJmSLYGA+NQrUMzi8Yjj0H4 PUpYYI1RpkAmj4N3DAu0lZQrLpdisEDe8GsmBRxB78hXvY78dDZgcpjOilFuq7at9xaB ezOfShMuPq5Z3JfUExyXe9g9kBOnd+IO1UhLaaVpkoRGnhlP99EUGBrYk6Mysa2C+tXP j2S09CDNN0QYmZ622oH+RA4dBcdsuzIECVU1QwwlEkKmaylcHfxpJz/02QAQC7m6TIFH 86O6Hd+zfy/vLtNE2DLsX4FmoLL1IYtHP2DO6UqrKIMeF0hhRPCTenPpb3bkPnwBk6C9 DGsg== 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; bh=1UY/dJEooJnNbfAHm7UE9cYo3rXDScw1JA9mM8Arq2c=; fh=PBHZcfMfFxGGBVmDESRU6Gjyj3qxzeiTc8DMNv9diCw=; b=VGZt17xPYM62ad1cQLe54Qwi5lbIJEfsEx6V7RsCcwfY6v0axYFHnK2FUp4uNtCxON 4TFOT17FzzWVJPuH+npb9euzgLWX+zTgLfD8NAOBc8ei6J5obNHybQcKYHdjdaDmxlVD Jh2IkP5L5nNBGjIqAoBpNCaVw9mbIlXNNryMjSJtFHY7WapNEXENQ6B0gg2pwE5l5BNE 3pIanNsOlgtc2w9c+6fu2UdRS+3zTkOS8Kj/LH1cYKij3D4dOoJN7RrhAENNZpx6rWRd sR3tsbNif8BQNg1mOW3QYfnMdu8PQlCuIQV1GwmDX7t+zDP3OP35Z+x/nxqgJQOfHiMX 57kg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o14-20020a170906358e00b009920ac37832si7244074ejb.504.2023.07.13.07.14.57; Thu, 13 Jul 2023 07:15:22 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231799AbjGMNy6 (ORCPT <rfc822;ybw1215001957@gmail.com> + 99 others); Thu, 13 Jul 2023 09:54:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231524AbjGMNyx (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 13 Jul 2023 09:54:53 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6D3181992; Thu, 13 Jul 2023 06:54:52 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B25D71576; Thu, 13 Jul 2023 06:55:34 -0700 (PDT) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A829D3F73F; Thu, 13 Jul 2023 06:54:50 -0700 (PDT) From: Ryan Roberts <ryan.roberts@arm.com> To: Andrew Morton <akpm@linux-foundation.org>, Shuah Khan <shuah@kernel.org>, =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= <jglisse@redhat.com>, David Hildenbrand <david@redhat.com>, Mark Brown <broonie@kernel.org>, John Hubbard <jhubbard@nvidia.com>, Florent Revest <revest@chromium.org>, "Liam R. Howlett" <Liam.Howlett@oracle.com> Cc: Ryan Roberts <ryan.roberts@arm.com>, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org Subject: [PATCH v1 1/9] selftests: Line buffer test program's stdout Date: Thu, 13 Jul 2023 14:54:32 +0100 Message-Id: <20230713135440.3651409-2-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230713135440.3651409-1-ryan.roberts@arm.com> References: <20230713135440.3651409-1-ryan.roberts@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE,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: INBOX X-GMAIL-THRID: 1771315105480991985 X-GMAIL-MSGID: 1771315105480991985 |
Series |
selftests/mm fixes for arm64
|
|
Commit Message
Ryan Roberts
July 13, 2023, 1:54 p.m. UTC
The selftests runner pipes the test program's stdout to tap_prefix. The
presence of the pipe means that the test program sets its stdout to be
fully buffered (as aposed to line buffered when directly connected to
the terminal). The block buffering means that there is often content in
the buffer at fork() time, which causes the output to end up duplicated.
This was causing problems for mm:cow where test results were duplicated
20-30x.
Solve this by using `stdbuf`, when available to force the test program
to use line buffered mode. This means previously printf'ed results are
flushed out of the program before any fork().
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
---
tools/testing/selftests/kselftest/runner.sh | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
Comments
On Thu, Jul 13, 2023 at 02:54:32PM +0100, Ryan Roberts wrote: > The selftests runner pipes the test program's stdout to tap_prefix. The > presence of the pipe means that the test program sets its stdout to be > fully buffered (as aposed to line buffered when directly connected to > the terminal). The block buffering means that there is often content in > the buffer at fork() time, which causes the output to end up duplicated. > This was causing problems for mm:cow where test results were duplicated > 20-30x. > > Solve this by using `stdbuf`, when available to force the test program > to use line buffered mode. This means previously printf'ed results are > flushed out of the program before any fork(). This is going to be useful in general since not all selftests use the kselftest helpers but it'd probably also be good to make ksft_print_header() also make the output unbuffered so that if setbuf isn't installed on the target system or the tests are run standalone we don't run into issues there. Even if the test isn't corrupting data having things unbuffered is going to be good for making sure we don't drop any output if the test dies. > + if [ -x /usr/bin/stdbuf ]; then > + stdbuf="/usr/bin/stdbuf --output=L " > + fi Might be more robust to use type -p to find stdbuf in case it's in /bin or something?
On 13/07/2023 15:16, Mark Brown wrote: > On Thu, Jul 13, 2023 at 02:54:32PM +0100, Ryan Roberts wrote: >> The selftests runner pipes the test program's stdout to tap_prefix. The >> presence of the pipe means that the test program sets its stdout to be >> fully buffered (as aposed to line buffered when directly connected to >> the terminal). The block buffering means that there is often content in >> the buffer at fork() time, which causes the output to end up duplicated. >> This was causing problems for mm:cow where test results were duplicated >> 20-30x. >> >> Solve this by using `stdbuf`, when available to force the test program >> to use line buffered mode. This means previously printf'ed results are >> flushed out of the program before any fork(). > > This is going to be useful in general since not all selftests use the > kselftest helpers but it'd probably also be good to make > ksft_print_header() also make the output unbuffered Yeah sounds reasonable. > so that if setbuf > isn't installed on the target system or the tests are run standalone we > don't run into issues there. Even if the test isn't corrupting data > having things unbuffered is going to be good for making sure we don't > drop any output if the test dies. Note that currently I've set stdbuf to encourage line buffering rather than no buffering. Are you saying no buffering is preferred? I took the view that line buffering is a good middle ground, and and aligns with what people see when developing and running the program manually in the terminal. > >> + if [ -x /usr/bin/stdbuf ]; then >> + stdbuf="/usr/bin/stdbuf --output=L " >> + fi > > Might be more robust to use type -p to find stdbuf in case it's in /bin > or something? Yep good idea.
On Thu, Jul 13, 2023 at 03:32:19PM +0100, Ryan Roberts wrote: > On 13/07/2023 15:16, Mark Brown wrote: > > so that if setbuf > > isn't installed on the target system or the tests are run standalone we > > don't run into issues there. Even if the test isn't corrupting data > > having things unbuffered is going to be good for making sure we don't > > drop any output if the test dies. > Note that currently I've set stdbuf to encourage line buffering rather than no > buffering. Are you saying no buffering is preferred? I took the view that line > buffering is a good middle ground, and and aligns with what people see when > developing and running the program manually in the terminal. TBH with the way KTAP is specified line buffered and unbuffered are probably equivalent, I was just defaulting to unbuffered since it's the more conservative (if less performant for lots of I/O) option.
On 13/07/2023 15:16, Mark Brown wrote: > On Thu, Jul 13, 2023 at 02:54:32PM +0100, Ryan Roberts wrote: >> The selftests runner pipes the test program's stdout to tap_prefix. The >> presence of the pipe means that the test program sets its stdout to be >> fully buffered (as aposed to line buffered when directly connected to >> the terminal). The block buffering means that there is often content in >> the buffer at fork() time, which causes the output to end up duplicated. >> This was causing problems for mm:cow where test results were duplicated >> 20-30x. >> >> Solve this by using `stdbuf`, when available to force the test program >> to use line buffered mode. This means previously printf'ed results are >> flushed out of the program before any fork(). > > This is going to be useful in general since not all selftests use the > kselftest helpers but it'd probably also be good to make > ksft_print_header() also make the output unbuffered so that if setbuf > isn't installed on the target system or the tests are run standalone we > don't run into issues there. Even if the test isn't corrupting data > having things unbuffered is going to be good for making sure we don't > drop any output if the test dies. > >> + if [ -x /usr/bin/stdbuf ]; then >> + stdbuf="/usr/bin/stdbuf --output=L " >> + fi > > Might be more robust to use type -p to find stdbuf in case it's in /bin > or something? Just looking at making this change; run_selftest.sh's shebang is for sh, and sh's type doesn't support the -p option. So I'm inclined to leave it as is. There are multiple other places in the script where /usr/bin is hardcoded when looking for programs too. Shout if you violently disagree.
diff --git a/tools/testing/selftests/kselftest/runner.sh b/tools/testing/selftests/kselftest/runner.sh index 1c952d1401d4..cb2b395ae296 100644 --- a/tools/testing/selftests/kselftest/runner.sh +++ b/tools/testing/selftests/kselftest/runner.sh @@ -105,8 +105,11 @@ run_one() echo "# Warning: file $TEST is missing!" echo "not ok $test_num $TEST_HDR_MSG" else + if [ -x /usr/bin/stdbuf ]; then + stdbuf="/usr/bin/stdbuf --output=L " + fi eval kselftest_cmd_args="\$${kselftest_cmd_args_ref:-}" - cmd="./$BASENAME_TEST $kselftest_cmd_args" + cmd="$stdbuf ./$BASENAME_TEST $kselftest_cmd_args" if [ ! -x "$TEST" ]; then echo "# Warning: file $TEST is not executable"