Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests: net: py: color the basics in the output

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.

Acked-by: Stanislav Fomichev <sdf@fomichev.me>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Acked-by: Joe Damato <joe@dama.to>
Link: https://patch.msgid.link/20260402215444.1589893-1-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+20
+20
tools/testing/selftests/net/lib/py/ksft.py
··· 2 2 3 3 import functools 4 4 import inspect 5 + import os 5 6 import signal 6 7 import sys 7 8 import time ··· 30 29 31 30 class KsftTerminate(KeyboardInterrupt): 32 31 pass 32 + 33 + 34 + @functools.lru_cache() 35 + def _ksft_supports_color(): 36 + if os.environ.get("NO_COLOR") is not None: 37 + return False 38 + if not hasattr(sys.stdout, "isatty") or not sys.stdout.isatty(): 39 + return False 40 + if os.environ.get("TERM") == "dumb": 41 + return False 42 + return True 33 43 34 44 35 45 def ksft_pr(*objs, **kwargs): ··· 177 165 res += "." + case_name 178 166 if comment: 179 167 res += " # " + comment 168 + if _ksft_supports_color(): 169 + if comment.startswith(("SKIP", "XFAIL")): 170 + color = "\033[33m" 171 + elif ok: 172 + color = "\033[32m" 173 + else: 174 + color = "\033[31m" 175 + res = color + res + "\033[0m" 180 176 print(res, flush=True) 181 177 182 178