From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 458771F91D6; Sat, 10 Jan 2026 00:51:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768006299; cv=none; b=Bn9BqTuHeJ4AI4MB7GhibDbNfS6I9/6CNsUe4gRyPhxWMDCW5IxNwaDKKb6tSXRao+jZ2o2bpJtpFMa5yN9AtYTKkb69CSFWQl/lGDUhMuNvTH21leB4Wk5IOFGKQZt3gYg3cZX0Qqy80B2nus3D4oWdhf8lF5U3ldR9DDDd1wg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768006299; c=relaxed/simple; bh=r8Y7dWVOVxkf7Pjozhyubw7hUj1jnGYJSX7KllDI7rY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D+rPpLKp8++2jeZDEJxkH6ru3zH2/fdJKKHgfPgYTCHRA57abHdQ+jChvk6XJ74I54IH10K2PSZyUrh9337koDTwQoMqgOvNzZhC4uRchvykWs/uSPfS6d55MPHIdq7e0EzoVaG7aWLgcC7YQjGlqjNIH2+9a22Xq0tmlkcaBG0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gKmDnP6F; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gKmDnP6F" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 752A8C19424; Sat, 10 Jan 2026 00:51:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768006298; bh=r8Y7dWVOVxkf7Pjozhyubw7hUj1jnGYJSX7KllDI7rY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gKmDnP6F7PpRvRZk6iaQQhRnugP4+Zx7d7KlIPktRtwNq0CYrSx/zkqz2YcNCNGkq zgpJimCFR2WqAtprDzvb+B4hX3q4PIQDa7lLKw9QcCKJLTwDlwhMV55yJEzzSzMPkh mkaiRVDr09JmLEPPIOs43vbaFDlQHcq2enrb3PGeBmNRbiIvNhwT8pUHBpxNZglqbU JvXspEtjDYLNjQ/WrwAov6R7lKKnIyTT1BfjenPbUVG+r7axCBATnD30MNpPD8B8Kg HHrfN7zmtWNH5pN95nwZ32T8Fq7K9M+pm2/8aCYftXkF9KvcK517FYnbzTghn5BWqX p/LRvBm7V7YuQ== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, andrew+netdev@lunn.ch, horms@kernel.org, shuah@kernel.org, linux-kselftest@vger.kernel.org, sdf@fomichev.me, willemb@google.com, petrm@nvidia.com, Jakub Kicinski Subject: [PATCH net-next v2 1/6] selftests: net: py: teach ksft_pr() multi-line safety Date: Fri, 9 Jan 2026 16:51:16 -0800 Message-ID: <20260110005121.3561437-2-kuba@kernel.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260110005121.3561437-1-kuba@kernel.org> References: <20260110005121.3561437-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Make printing multi-line logs easier by automatically prefixing each line in ksft_pr(). Make use of this when formatting exceptions. Signed-off-by: Jakub Kicinski --- tools/testing/selftests/net/lib/py/ksft.py | 29 ++++++++++++++-------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/net/lib/py/ksft.py b/tools/testing/selftests/net/lib/py/ksft.py index 531e7fa1b3ea..4ca21d829b1c 100644 --- a/tools/testing/selftests/net/lib/py/ksft.py +++ b/tools/testing/selftests/net/lib/py/ksft.py @@ -32,8 +32,23 @@ KSFT_DISRUPTIVE = True def ksft_pr(*objs, **kwargs): + """ + Print logs to stdout. + + Behaves like print() but log lines will be prefixed + with # to prevent breaking the TAP output formatting. + + Extra arguments (on top of what print() supports): + line_pfx - add extra string before each line + """ + sep = kwargs.pop("sep", " ") + pfx = kwargs.pop("line_pfx", "") + pfx = "#" + (" " + pfx if pfx else "") kwargs["flush"] = True - print("#", *objs, **kwargs) + + text = sep.join(str(obj) for obj in objs) + prefixed = f"\n{pfx} ".join(text.split('\n')) + print(pfx, prefixed, **kwargs) def _fail(*args): @@ -165,9 +180,7 @@ KSFT_DISRUPTIVE = True entry.exec_only() except Exception: ksft_pr(f"Exception while handling defer / cleanup (callback {i} of {qlen_start})!") - tb = traceback.format_exc() - for line in tb.strip().split('\n'): - ksft_pr("Defer Exception|", line) + ksft_pr(traceback.format_exc(), line_pfx="Defer Exception|") KSFT_RESULT = False @@ -325,9 +338,7 @@ KsftCaseFunction = namedtuple("KsftCaseFunction", cnt_key = 'xfail' except BaseException as e: stop |= isinstance(e, KeyboardInterrupt) - tb = traceback.format_exc() - for line in tb.strip().split('\n'): - ksft_pr("Exception|", line) + ksft_pr(traceback.format_exc(), line_pfx="Exception|") if stop: ksft_pr(f"Stopping tests due to {type(e).__name__}.") KSFT_RESULT = False @@ -336,9 +347,7 @@ KsftCaseFunction = namedtuple("KsftCaseFunction", try: ksft_flush_defer() except BaseException as e: - tb = traceback.format_exc() - for line in tb.strip().split('\n'): - ksft_pr("Exception|", line) + ksft_pr(traceback.format_exc(), line_pfx="Exception|") if isinstance(e, KeyboardInterrupt): ksft_pr() ksft_pr("WARN: defer() interrupted, cleanup may be incomplete.") -- 2.52.0