2323import kunit_json
2424import kunit_kernel
2525import kunit_parser
26- from kunit_printer import stdout
26+ from kunit_printer import stdout , null_printer
2727
2828class KunitStatus (Enum ):
2929 SUCCESS = auto ()
@@ -49,6 +49,7 @@ class KunitBuildRequest(KunitConfigRequest):
4949class KunitParseRequest :
5050 raw_output : Optional [str ]
5151 json : Optional [str ]
52+ summary : bool
5253
5354@dataclass
5455class 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
418428def 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