Skip to content

Commit 29afed1

Browse files
sulixshuahkh
authored andcommitted
kunit:tool: Don't write to stdout when it should be disabled
The kunit_parser module accepts a 'printer' object which is used as a destination for all output. This is typically set to stdout, so that the parsed results are visible, but can be set to a special 'null_printer' to implement options where not all results are always printed. However, there are a few places where use of stdout is hardcoded, notably in handling crashed tests and in outputting the colour escape sequences. Properly use the specified printer for all output. This is okay for the colour handling (as this is already gated behind isatty() anyway), and also for the crash handling, as cases where printer != stdout are separately printed afterwards. Link: https://lore.kernel.org/r/20260606020317.264178-1-david@davidgow.net Fixes: 062a9dd ("kunit: tool: Only print the summary") Signed-off-by: David Gow <david@davidgow.net> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent e9e05c7 commit 29afed1

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

tools/testing/kunit/kunit_parser.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from enum import Enum, auto
1818
from typing import Iterable, Iterator, List, Optional, Tuple
1919

20-
from kunit_printer import Printer, stdout
20+
from kunit_printer import Printer
2121

2222
class Test:
2323
"""
@@ -58,7 +58,7 @@ def __repr__(self) -> str:
5858
def add_error(self, printer: Printer, error_message: str) -> None:
5959
"""Records an error that occurred while parsing this test."""
6060
self.counts.errors += 1
61-
printer.print_with_timestamp(stdout.red('[ERROR]') + f' Test: {self.name}: {error_message}')
61+
printer.print_with_timestamp(printer.red('[ERROR]') + f' Test: {self.name}: {error_message}')
6262

6363
def ok_status(self) -> bool:
6464
"""Returns true if the status was ok, i.e. passed or skipped."""
@@ -549,7 +549,7 @@ def format_test_result(test: Test, printer: Printer) -> str:
549549
return printer.yellow('[NO TESTS RUN] ') + test.name
550550
if test.status == TestStatus.TEST_CRASHED:
551551
print_log(test.log, printer)
552-
return stdout.red('[CRASHED] ') + test.name
552+
return printer.red('[CRASHED] ') + test.name
553553
print_log(test.log, printer)
554554
return printer.red('[FAILED] ') + test.name
555555

@@ -656,11 +656,11 @@ def print_summary_line(test: Test, printer: Printer) -> None:
656656
printer - Printer object to output results
657657
"""
658658
if test.status == TestStatus.SUCCESS:
659-
color = stdout.green
659+
color = printer.green
660660
elif test.status in (TestStatus.SKIPPED, TestStatus.NO_TESTS):
661-
color = stdout.yellow
661+
color = printer.yellow
662662
else:
663-
color = stdout.red
663+
color = printer.red
664664
printer.print_with_timestamp(color(f'Testing complete. {test.counts}'))
665665

666666
# Summarize failures that might have gone off-screen since we had a lot

0 commit comments

Comments
 (0)