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>
import functools
import inspect
+import os
import signal
import sys
import time
pass
+@functools.lru_cache()
+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
+
+
def ksft_pr(*objs, **kwargs):
"""
Print logs to stdout.
res += "." + case_name
if comment:
res += " # " + comment
+ if _ksft_supports_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)