public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
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 <kuba@kernel.org>
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	[thread overview]
Message-ID: <20260110005121.3561437-2-kuba@kernel.org> (raw)
In-Reply-To: <20260110005121.3561437-1-kuba@kernel.org>

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 <kuba@kernel.org>
---
 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


  reply	other threads:[~2026-01-10  0:51 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-10  0:51 [PATCH net-next v2 0/6] selftests: drv-net: gro: enable HW GRO and LRO testing Jakub Kicinski
2026-01-10  0:51 ` Jakub Kicinski [this message]
2026-01-12 10:37   ` [PATCH net-next v2 1/6] selftests: net: py: teach ksft_pr() multi-line safety Petr Machata
2026-01-10  0:51 ` [PATCH net-next v2 2/6] selftests: net: py: teach cmd() how to print itself Jakub Kicinski
2026-01-12 10:37   ` Petr Machata
2026-01-10  0:51 ` [PATCH net-next v2 3/6] selftests: drv-net: gro: use cmd print Jakub Kicinski
2026-01-12 10:37   ` Petr Machata
2026-01-10  0:51 ` [PATCH net-next v2 4/6] selftests: drv-net: gro: improve feature config Jakub Kicinski
2026-01-10 17:43   ` Jakub Kicinski
2026-01-11 17:08   ` Willem de Bruijn
2026-01-10  0:51 ` [PATCH net-next v2 5/6] selftests: drv-net: gro: run the test against HW GRO and LRO Jakub Kicinski
2026-01-11 17:08   ` Willem de Bruijn
2026-01-10  0:51 ` [PATCH net-next v2 6/6] selftests: drv-net: gro: break out all individual test cases Jakub Kicinski
2026-01-11 17:12   ` Willem de Bruijn
2026-01-13  0:16     ` Jakub Kicinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260110005121.3561437-2-kuba@kernel.org \
    --to=kuba@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=petrm@nvidia.com \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox