mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00

Allow only printing the summary at the end of a test run, rather than all individual test results. This summary will list a few failing tests if there are any. To use: ./tools/testing/kunit/kunit.py run --summary Link: https://lore.kernel.org/r/20241113222406.1590372-1-rmoar@google.com Signed-off-by: Rae Moar <rmoar@google.com> Signed-off-by: David Gow <davidgow@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
54 lines
1.3 KiB
Python
54 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
#
|
|
# Utilities for printing and coloring output.
|
|
#
|
|
# Copyright (C) 2022, Google LLC.
|
|
# Author: Daniel Latypov <dlatypov@google.com>
|
|
|
|
import datetime
|
|
import sys
|
|
import typing
|
|
|
|
_RESET = '\033[0;0m'
|
|
|
|
class Printer:
|
|
"""Wraps a file object, providing utilities for coloring output, etc."""
|
|
|
|
def __init__(self, print: bool=True, output: typing.IO[str]=sys.stdout):
|
|
self._output = output
|
|
self._print = print
|
|
if print:
|
|
self._use_color = output.isatty()
|
|
else:
|
|
self._use_color = False
|
|
|
|
def print(self, message: str) -> None:
|
|
if self._print:
|
|
print(message, file=self._output)
|
|
|
|
def print_with_timestamp(self, message: str) -> None:
|
|
ts = datetime.datetime.now().strftime('%H:%M:%S')
|
|
self.print(f'[{ts}] {message}')
|
|
|
|
def _color(self, code: str, text: str) -> str:
|
|
if not self._use_color:
|
|
return text
|
|
return code + text + _RESET
|
|
|
|
def red(self, text: str) -> str:
|
|
return self._color('\033[1;31m', text)
|
|
|
|
def yellow(self, text: str) -> str:
|
|
return self._color('\033[1;33m', text)
|
|
|
|
def green(self, text: str) -> str:
|
|
return self._color('\033[1;32m', text)
|
|
|
|
def color_len(self) -> int:
|
|
"""Returns the length of the color escape codes."""
|
|
return len(self.red(''))
|
|
|
|
# Provides a default instance that prints to stdout
|
|
stdout = Printer()
|
|
null_printer = Printer(print=False)
|