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: 13315412 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 06A79C00528 for ; Mon, 17 Jul 2023 10:32:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 88FBC6B0074; Mon, 17 Jul 2023 06:32:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 83FC26B0075; Mon, 17 Jul 2023 06:32:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 72E778D0001; Mon, 17 Jul 2023 06:32:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 658756B0074 for ; Mon, 17 Jul 2023 06:32:11 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 341E240557 for ; Mon, 17 Jul 2023 10:32:11 +0000 (UTC) X-FDA: 81020738862.26.A4F710B Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf07.hostedemail.com (Postfix) with ESMTP id 5425940018 for ; Mon, 17 Jul 2023 10:32:09 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=none; spf=pass (imf07.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689589929; a=rsa-sha256; cv=none; b=4Dmnj1hP21pnypqYGvbNXj3jA5zizX/4kR5HS1PYwwgJnphr0aRUTMyL8ck0idQeegqK2q vOh4AvRbQMVTTkw912deRVBe3b6yKyfsbDgjffpTlJhHTn/v7LB6fEkcEz0ag+NwyMrN6O LiJ2rMNfULTfz6Bbw/sr5pjMGYKJQwc= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=none; spf=pass (imf07.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689589929; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4IQ8IXDko9tfglX73dLBnmTqnSbgJyeqxWIDPYOqiN0=; b=noWAqozg0D10Gwm287Sz9l6AQDp2EJGiPk2xo04KFpeGxRLi4aocnk3OWoMo4xwAOVLOok lFoany0sMa/YbeFSPmIfLd770+ESvetvGaT33dUQNwITfseLrndjgw71RD4q3umshoD/Jn C/94tgVqJtJnUSu2ejOw7i7wa/VeVkk= 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-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 5425940018 X-Stat-Signature: tq1karrc4z6tc335fwzdgf5j3cdqdjzr X-HE-Tag: 1689589929-600528 X-HE-Meta: U2FsdGVkX1+dhGVGZT9p4eYUHeCS/6WfnXntMp6gk4ybYn9KqjNjuSkEQ9rSGrJNwBefHd5h/jsCp4OS264VEDXc1h07P8mevT5qXTZ4wIIMopnGyK25z9KaXGYMw9RVtRs71idBTXNVXGiQNTehsK+ZK+jEoxuf9TuIMvXkK8pFbOTYycetIvDAeUZwXjvw7G5Fztaj5KehisXC3ny7N4laOVy7tkTieoMVMNjKrTHo19FnxABOZchYSMvfgKIE7UGAzGznUho9f3ejRLW6jkcwWEWS6XmpfYdovs3teWGvZZwDpD4/x8rM7O2w+MEh50ZDgot5IrSITV87LhF5JeCkGUtN7M0BaP5WGYIBb9szc35IGZtWY+k6ZjvMSETSNchzJdcT++zANWdo9mg25Z0qDHz6aA0LlNrhgEfiGszvfuhZuwRPsgh06g5yNeAnSDvl7bD2HoTADijE5MV+2AxuRLz6TPVAUfMTEnVekjOcd+ds9inftcpVG9NGqEbT14/zbgNUJrITi/LFf2s/Cq7SjPSq+Xvh1evAZsryQSVKTghBFr1ZPaf95cP3e4ICAkDA9lFe1/R3qkyN0iZpIEBn0yclbF9tNeAkSw2Fz+3EyVxScOM8x0YRW9TCpU68OCzIkU4nSSaUomr+s9LT+2DQrVObKU8QPb2DwDXXHHiv37yWSO1Bj6q88qIJZ9l9DKQVI6TJImLZqrIzbWo59nZihOWSi8PuGE/U6ammwp+YT9st9sTMzI/yd4xyI2sohH6VfFDzF7QcXyOQk21mfon8PCm7AURfiV5BPErtu4UQxKsUOdoQy2hUXBp++XWxE3UWUVHCNU3+xB9FZeI9v9F/8+RBU/fYjQKX9abLtaPsf+lcoxOEcW4qnHlzQv22l+otZUCXEiVuTJQWmkII4aQtDGSWe8D5Bv2KENJi6qjmETG4rT+HqYlEL9zFeF8ZpmJHEyUWiEK7L/PvUIL PLlzD/dr pUQplLbUtXzK7w+VepiN+msKO9dYgIYzy9oq6QjHJ6PofnlUWbKGXAhZWgQfJWRnVFLw2N8NJp5Uiq8vQCezQHWPbIsPhb4DyZaDnaaU6Dm8Yy1K5srvdb8DOq2Hh9/S75qsY0mW5N9JuWbXR3/qiZCX65Q99cOwVSmAe X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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