Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp5401679rwp; Mon, 17 Jul 2023 03:37:25 -0700 (PDT) X-Google-Smtp-Source: APBJJlFqT1epgLabuzEyDJiXaTZN9FSDMzQYRBduIIYzdlHm8kfDeYQFz4VJC+NA6VBpop2Ju/Zo X-Received: by 2002:a17:907:91c5:b0:991:f6d0:9bc1 with SMTP id h5-20020a17090791c500b00991f6d09bc1mr9748089ejz.66.1689590245077; Mon, 17 Jul 2023 03:37:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689590245; cv=none; d=google.com; s=arc-20160816; b=p0YGdndXExQp/+L3kTL7Lgm9z/y+Fu/9iQjYzXfcG8fjuumMji89T9C4TUiXOvMzmW 5Ln83POK1UK4awsaGJlpJEtThGV5t33wwSjGsI7LLXWoEYjprVCwJRB1m7H0k6blh4cZ fhnlSWnQ/Lr0jW6UTqIeGqA1wHSRlMWJDubykIxbgAr7fulj95JlRmdpKdgzHHcMA39W Kt+26tPu5WZxWj73JKsddB2h4ucpqsPpcNHHbRk72RR5jfcziFGi17kLIDZsd6uBswY4 Z5/OhESFeER3VX4NdRVqQTOLfm6DW0djENufMg/PDFZ8NzdVZ+G+s7r0b869Lz3BYnEy BaPw== 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=4IQ8IXDko9tfglX73dLBnmTqnSbgJyeqxWIDPYOqiN0=; fh=OUPfCZjK3Gm4uAxJmzTYkNGoALdOI9ZG4q/pkSTXiCE=; b=gdiJXxQIYvA/RBm7UV8yg2ADzq45SsfnJQF7Tt6oQ93jI3h9F74FbNRIVMhYuCXevC jbVq5BP1g+L98zWaymrtge0NucpqF8vg6WfdLauIkTq9TXvrFoQQa0J5mU8ZascyXCtA 1QSR+ZasuN2U4HHYuhDFek09g3WtGpsdZry8evJjEspY+DZeyhpUKDi2fe40+jDaraTI wtTTlnakkIWtH/RMNBX0GSI8DgwYvLFIjA3KgL2w2Nv+hIAMUsct1Oc4lcM5pVYmnZ8b FRNurUDQzs4BjI+iIT1738D7XTspJLXA+TYOssgwJ9kyMuW9OoaVXf86zvKmn/Lckycf o5aQ== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v25-20020a170906489900b00992e21b04aasi11790567ejq.720.2023.07.17.03.37.01; Mon, 17 Jul 2023 03:37:25 -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 S230042AbjGQKcL (ORCPT + 99 others); Mon, 17 Jul 2023 06:32:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229471AbjGQKcK (ORCPT ); Mon, 17 Jul 2023 06:32:10 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8FE8BE9; Mon, 17 Jul 2023 03:32:08 -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 97EC2D75; Mon, 17 Jul 2023 03:32:51 -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 9E9463F67D; Mon, 17 Jul 2023 03:32:06 -0700 (PDT) From: Ryan Roberts To: "Andrew Morton" , "Shuah Khan" , =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , "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 v2 1/8] selftests: Line buffer test program's stdout Date: Mon, 17 Jul 2023 11:31:45 +0100 Message-Id: <20230717103152.202078-2-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230717103152.202078-1-ryan.roberts@arm.com> References: <20230717103152.202078-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: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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 -- 2.25.1