Subject: [PATCH net-next] selftests: net: py: color the basics in the output

From: Jakub Kicinski <[email-masked]>
Date: Wed, 1 Apr 2026 11:33:09 -0700

Sometimes it's hard to spot the ok / not ok lines in the output.
This is especially true for the GRO tests which retries a lot
so there's a wall of non-fatal output printed.

Try to color the crucial lines green / red / yellow when running
in a terminal.

Signed-off-by: Jakub Kicinski <[email-masked]>
---
This is a bit of RFC, I'm not super convinced this is worth
carrying in the tree? Please Ack/Review I'll apply if we get
3 supporting tags.
---
CC: [email-masked]
CC: [email-masked]
CC: [email-masked]
CC: [email-masked]
---
 tools/testing/selftests/net/lib/py/ksft.py | 29 ++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/tools/testing/selftests/net/lib/py/ksft.py b/tools/testing/selftests/net/lib/py/ksft.py
index 28a7a994526d..2a6e9113ef5b 100644
--- a/tools/testing/selftests/net/lib/py/ksft.py
+++ b/tools/testing/selftests/net/lib/py/ksft.py
@@ -4,6 +4,7 @@ import argparse
 import fnmatch
 import functools
 import inspect
+import os
 import signal
 import sys
 import time
@@ -17,6 +18,26 @@ KSFT_RESULT_ALL = True
 KSFT_DISRUPTIVE = True

+def _ksft_supports_color():
+    if os.environ.get("NO_COLOR") is not None:
+        return False
+    if not hasattr(sys.stdout, "isatty") or not sys.stdout.isatty():
+        return False
+    if os.environ.get("TERM") == "dumb":
+        return False
+    return True
+
+
+_KSFT_COLOR = None
+
+
+def _ksft_color():
+    global _KSFT_COLOR
+    if _KSFT_COLOR is None:
+        _KSFT_COLOR = _ksft_supports_color()
+    return _KSFT_COLOR
+
+
 class KsftFailEx(Exception):
     pass
 
@@ -167,6 +188,14 @@ KSFT_DISRUPTIVE = True
         res += "." + case_name
     if comment:
         res += " # " + comment
+    if _ksft_color():
+        if comment.startswith(("SKIP", "XFAIL")):
+            color = "\033[33m"
+        elif ok:
+            color = "\033[32m"
+        else:
+            color = "\033[31m"
+        res = color + res + "\033[0m"
     print(res, flush=True)

-- 
2.53.0