From patchwork Mon Jul 17 10:31:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 121196 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp1026156vqt; Mon, 17 Jul 2023 03:39:25 -0700 (PDT) X-Google-Smtp-Source: APBJJlGJUp8jr9fVfKzswizsjpcoGlYd8whIV8FUlJeF7wJGVwKNuZ+BRxtqYEu1nmsUd/zHTkWG X-Received: by 2002:a17:906:74cf:b0:994:5577:aef1 with SMTP id z15-20020a17090674cf00b009945577aef1mr8061505ejl.7.1689590364956; Mon, 17 Jul 2023 03:39:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689590364; cv=none; d=google.com; s=arc-20160816; b=YeZAm8WWUs9kbgSJ4OgPYzKxthLt5p4L9yCN9sRXHN/YLsryZKLqQDUbhENk5iBdS0 W3teHUpcjrnmHhcSJQmepJzP36nuuL5IqHvXBu3b0UquyS2lOe2ebAyO2dFxklFx2wrj 5F+UEmK7xdqv+7+YAuJfIGEL0r+bwP3CApGrtCPTHN6K191OIKrHXcEum/8AgcJsRQVC DEvsKalh3Ik4s90X4d7wGrDT5WrH6KsV03z9D6tjvlOADYMix87FuBe05qYr4ADqsynQ oVONq3dHnmX4cUWJDEe8aZbdmTqPJ6WxGMEacm9DO+kueFILGREgHcJ+ViujnNFZCA4I BrRw== 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 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.39.00; Mon, 17 Jul 2023 03:39:24 -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 S230053AbjGQKcL (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?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 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 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771663906663082810 X-GMAIL-MSGID: 1771663906663082810 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 Reviewed-by: Mark Brown --- 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