Skip to content

Commit 062a9dd

Browse files
sulixshuahkh
authored andcommitted
kunit: tool: Only print the summary
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/[email protected] Signed-off-by: Rae Moar <[email protected]> Signed-off-by: David Gow <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent 5017ec6 commit 062a9dd

File tree

4 files changed

+112
-84
lines changed

4 files changed

+112
-84
lines changed

tools/testing/kunit/kunit.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import kunit_json
2424
import kunit_kernel
2525
import kunit_parser
26-
from kunit_printer import stdout
26+
from kunit_printer import stdout, null_printer
2727

2828
class KunitStatus(Enum):
2929
SUCCESS = auto()
@@ -49,6 +49,7 @@ class KunitBuildRequest(KunitConfigRequest):
4949
class KunitParseRequest:
5050
raw_output: Optional[str]
5151
json: Optional[str]
52+
summary: bool
5253

5354
@dataclass
5455
class KunitExecRequest(KunitParseRequest):
@@ -235,11 +236,16 @@ def parse_tests(request: KunitParseRequest, metadata: kunit_json.Metadata, input
235236
parse_time = time.time() - parse_start
236237
return KunitResult(KunitStatus.SUCCESS, parse_time), fake_test
237238

239+
default_printer = stdout
240+
if request.summary:
241+
default_printer = null_printer
238242

239243
# Actually parse the test results.
240-
test = kunit_parser.parse_run_tests(input_data)
244+
test = kunit_parser.parse_run_tests(input_data, default_printer)
241245
parse_time = time.time() - parse_start
242246

247+
kunit_parser.print_summary_line(test, stdout)
248+
243249
if request.json:
244250
json_str = kunit_json.get_json_result(
245251
test=test,
@@ -413,6 +419,10 @@ def add_parse_opts(parser: argparse.ArgumentParser) -> None:
413419
help='Prints parsed test results as JSON to stdout or a file if '
414420
'a filename is specified. Does nothing if --raw_output is set.',
415421
type=str, const='stdout', default=None, metavar='FILE')
422+
parser.add_argument('--summary',
423+
help='Prints only the summary line for parsed test results.'
424+
'Does nothing if --raw_output is set.',
425+
action='store_true')
416426

417427

418428
def tree_from_args(cli_args: argparse.Namespace) -> kunit_kernel.LinuxSourceTree:
@@ -448,6 +458,7 @@ def run_handler(cli_args: argparse.Namespace) -> None:
448458
jobs=cli_args.jobs,
449459
raw_output=cli_args.raw_output,
450460
json=cli_args.json,
461+
summary=cli_args.summary,
451462
timeout=cli_args.timeout,
452463
filter_glob=cli_args.filter_glob,
453464
filter=cli_args.filter,
@@ -495,6 +506,7 @@ def exec_handler(cli_args: argparse.Namespace) -> None:
495506
exec_request = KunitExecRequest(raw_output=cli_args.raw_output,
496507
build_dir=cli_args.build_dir,
497508
json=cli_args.json,
509+
summary=cli_args.summary,
498510
timeout=cli_args.timeout,
499511
filter_glob=cli_args.filter_glob,
500512
filter=cli_args.filter,
@@ -520,7 +532,7 @@ def parse_handler(cli_args: argparse.Namespace) -> None:
520532
# We know nothing about how the result was created!
521533
metadata = kunit_json.Metadata()
522534
request = KunitParseRequest(raw_output=cli_args.raw_output,
523-
json=cli_args.json)
535+
json=cli_args.json, summary=cli_args.summary)
524536
result, _ = parse_tests(request, metadata, kunit_output)
525537
if result.status != KunitStatus.SUCCESS:
526538
sys.exit(1)

0 commit comments

Comments
 (0)