23
23
import kunit_json
24
24
import kunit_kernel
25
25
import kunit_parser
26
- from kunit_printer import stdout
26
+ from kunit_printer import stdout , null_printer
27
27
28
28
class KunitStatus (Enum ):
29
29
SUCCESS = auto ()
@@ -49,6 +49,7 @@ class KunitBuildRequest(KunitConfigRequest):
49
49
class KunitParseRequest :
50
50
raw_output : Optional [str ]
51
51
json : Optional [str ]
52
+ summary : bool
52
53
53
54
@dataclass
54
55
class KunitExecRequest (KunitParseRequest ):
@@ -235,11 +236,16 @@ def parse_tests(request: KunitParseRequest, metadata: kunit_json.Metadata, input
235
236
parse_time = time .time () - parse_start
236
237
return KunitResult (KunitStatus .SUCCESS , parse_time ), fake_test
237
238
239
+ default_printer = stdout
240
+ if request .summary :
241
+ default_printer = null_printer
238
242
239
243
# 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 )
241
245
parse_time = time .time () - parse_start
242
246
247
+ kunit_parser .print_summary_line (test , stdout )
248
+
243
249
if request .json :
244
250
json_str = kunit_json .get_json_result (
245
251
test = test ,
@@ -413,6 +419,10 @@ def add_parse_opts(parser: argparse.ArgumentParser) -> None:
413
419
help = 'Prints parsed test results as JSON to stdout or a file if '
414
420
'a filename is specified. Does nothing if --raw_output is set.' ,
415
421
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' )
416
426
417
427
418
428
def tree_from_args (cli_args : argparse .Namespace ) -> kunit_kernel .LinuxSourceTree :
@@ -448,6 +458,7 @@ def run_handler(cli_args: argparse.Namespace) -> None:
448
458
jobs = cli_args .jobs ,
449
459
raw_output = cli_args .raw_output ,
450
460
json = cli_args .json ,
461
+ summary = cli_args .summary ,
451
462
timeout = cli_args .timeout ,
452
463
filter_glob = cli_args .filter_glob ,
453
464
filter = cli_args .filter ,
@@ -495,6 +506,7 @@ def exec_handler(cli_args: argparse.Namespace) -> None:
495
506
exec_request = KunitExecRequest (raw_output = cli_args .raw_output ,
496
507
build_dir = cli_args .build_dir ,
497
508
json = cli_args .json ,
509
+ summary = cli_args .summary ,
498
510
timeout = cli_args .timeout ,
499
511
filter_glob = cli_args .filter_glob ,
500
512
filter = cli_args .filter ,
@@ -520,7 +532,7 @@ def parse_handler(cli_args: argparse.Namespace) -> None:
520
532
# We know nothing about how the result was created!
521
533
metadata = kunit_json .Metadata ()
522
534
request = KunitParseRequest (raw_output = cli_args .raw_output ,
523
- json = cli_args .json )
535
+ json = cli_args .json , summary = cli_args . summary )
524
536
result , _ = parse_tests (request , metadata , kunit_output )
525
537
if result .status != KunitStatus .SUCCESS :
526
538
sys .exit (1 )
0 commit comments