From patchwork Mon Jul 24 08:25:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 124690 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp1657680vqg; Mon, 24 Jul 2023 01:39:41 -0700 (PDT) X-Google-Smtp-Source: APBJJlFBR98qaWBwtyZTAn8rvsAKZPqGOu5s15meDXDIxCVxbOH7mg+j7KOyshG98iWk2bdgVHBS X-Received: by 2002:a05:6358:52c1:b0:134:ec9d:ef18 with SMTP id z1-20020a05635852c100b00134ec9def18mr5637677rwz.28.1690187981585; Mon, 24 Jul 2023 01:39:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690187981; cv=none; d=google.com; s=arc-20160816; b=hhpz2K7ZuwDof/42Z2++z0NEDFA9M0bq2VMGzVm2dYRJN7luc+9g/UQCPNoXElCvNG fhFkjtrki+EcTYA4T3qSE0nkFDSOPq1E8vCkC0glDSjGM9mqFd3acIhvXwAhHpKkanWF FqV42aoRnslSpcT0g9h5NQygNRQDmTOZzxh4WjriVLXDHRZufeTcnSU1b9PmIQUYkLEs /bBICWzN9owKK5ar09r9UKXEZmO4BlSbYon+8sh2KI4Z7PynkXAxSuZQiFenGv79xOhS K3KjRcjLIT/vVOyMJgBcopPjPD19CShI5uMt0VhdQYsqSWjS+At6utsR/bI5eRtv28e+ 8tGA== 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=XlRIL9y77l4hUsgR6WNGVesaqf711bWwIXAfz4ZM0r8=; fh=6rhI9kvwCMo+fckRKZYXD+Cg7edipvyuIhlyok3MppU=; b=bmJ4CmBD5OQaYtoFo/lrTP27Er+16YRW7e0niDWesty0US/96Jrh2+QijLiTGIzWnL xebqe4SlHijY2o19XqQAWmzSyOBI+bPz4oo0TKuXJ7eOu7Gui4CrtJF8lDCP1r2gqxO9 hjunlRKvDccLmaCYCpoG/Y27+CGB0T34R0fiLBI5rLjrTttebQcjXkRpETS+7qK4FAuq AMWOR2zJQsMHap4Y0CJJ5+pafBePwC8SqwS+D8TiKh93jWcSfNW3Tz2l+P/Gl/YvKzan CazxaVrOADYBFEDg+SGzYp6h9fJbt1a8E61w00++3SeW6vfj9CFww4yKWX6eAbHwQ3iX 0tog== 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 h126-20020a636c84000000b00563b0cbe7fcsi2025535pgc.854.2023.07.24.01.39.28; Mon, 24 Jul 2023 01:39:41 -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 S231454AbjGXIZl (ORCPT + 99 others); Mon, 24 Jul 2023 04:25:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231424AbjGXIZh (ORCPT ); Mon, 24 Jul 2023 04:25:37 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id ED6771B8; Mon, 24 Jul 2023 01:25:34 -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 DB53EFEC; Mon, 24 Jul 2023 01:26:17 -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 081BE3F67D; Mon, 24 Jul 2023 01:25:32 -0700 (PDT) From: Ryan Roberts To: "Andrew Morton" , "Shuah Khan" , =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , "David Hildenbrand" , "Mark Brown" , "John Hubbard" , "Florent Revest" , "Peter Xu" Cc: Ryan Roberts , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org Subject: [PATCH v3 1/8] selftests: Line buffer test program's stdout Date: Mon, 24 Jul 2023 09:25:15 +0100 Message-Id: <20230724082522.1202616-2-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230724082522.1202616-1-ryan.roberts@arm.com> References: <20230724082522.1202616-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772290552859660967 X-GMAIL-MSGID: 1772290552859660967 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(). Additionally, explicitly set line buffer mode in ksft_print_header(), which means that all test programs that use the ksft framework will benefit even if stdbuf is not present on the system. Reviewed-by: Mark Brown Signed-off-by: Ryan Roberts --- tools/testing/selftests/kselftest.h | 9 +++++++++ tools/testing/selftests/kselftest/runner.sh | 7 +++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h index 829be379545a..529d29a35900 100644 --- a/tools/testing/selftests/kselftest.h +++ b/tools/testing/selftests/kselftest.h @@ -113,6 +113,15 @@ static inline int ksft_get_error_cnt(void) { return ksft_cnt.ksft_error; } static inline void ksft_print_header(void) { + /* + * Force line buffering; If stdout is not connected to a terminal, it + * will otherwise default to fully buffered, which can cause output + * duplication if there is content in the buffer when fork()ing. If + * there is a crash, line buffering also means the most recent output + * line will be visible. + */ + setvbuf(stdout, NULL, _IOLBF, 0); + if (!(getenv("KSFT_TAP_LEVEL"))) printf("TAP version 13\n"); } diff --git a/tools/testing/selftests/kselftest/runner.sh b/tools/testing/selftests/kselftest/runner.sh index 1c952d1401d4..261c73cab41b 100644 --- a/tools/testing/selftests/kselftest/runner.sh +++ b/tools/testing/selftests/kselftest/runner.sh @@ -105,15 +105,18 @@ 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" if [ $(head -n 1 "$TEST" | cut -c -2) = "#!" ] then interpreter=$(head -n 1 "$TEST" | cut -c 3-) - cmd="$interpreter ./$BASENAME_TEST" + cmd="$stdbuf $interpreter ./$BASENAME_TEST" else echo "not ok $test_num $TEST_HDR_MSG" return