aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2022-02-23 21:53:50 -0800
committerShuah Khan <skhan@linuxfoundation.org>2022-04-04 15:23:50 -0600
commitd34f82d67d2b1bdbed6bf343f0c9e6d828438976 (patch)
treec2a81bf20a04c6fcd4e138bbd811c97539514ade
parentkunit: tool: properly report the used arch for --json, or '' if not known (diff)
downloadlinux-dev-d34f82d67d2b1bdbed6bf343f0c9e6d828438976.tar.xz
linux-dev-d34f82d67d2b1bdbed6bf343f0c9e6d828438976.zip
kunit: tool: Do not colorize output when redirected
Filling log files with color codes makes diffs and other comparisons difficult. Only emit vt100 codes when the stdout is a TTY. Cc: Brendan Higgins <brendanhiggins@google.com> Cc: linux-kselftest@vger.kernel.org Cc: kunit-dev@googlegroups.com Signed-off-by: Kees Cook <keescook@chromium.org> Reviewed-by: David Gow <davidgow@google.com> Reviewed-by: Brendan Higgins <brendanhiggins@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
-rw-r--r--tools/testing/kunit/kunit_parser.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/tools/testing/kunit/kunit_parser.py b/tools/testing/kunit/kunit_parser.py
index 05ff334761dd..807ed2bd6832 100644
--- a/tools/testing/kunit/kunit_parser.py
+++ b/tools/testing/kunit/kunit_parser.py
@@ -11,6 +11,7 @@
from __future__ import annotations
import re
+import sys
import datetime
from enum import Enum, auto
@@ -503,14 +504,20 @@ RESET = '\033[0;0m'
def red(text: str) -> str:
"""Returns inputted string with red color code."""
+ if not sys.stdout.isatty():
+ return text
return '\033[1;31m' + text + RESET
def yellow(text: str) -> str:
"""Returns inputted string with yellow color code."""
+ if not sys.stdout.isatty():
+ return text
return '\033[1;33m' + text + RESET
def green(text: str) -> str:
"""Returns inputted string with green color code."""
+ if not sys.stdout.isatty():
+ return text
return '\033[1;32m' + text + RESET
ANSI_LEN = len(red(''))