Skip to content
/ linux Public
forked from torvalds/linux

Commit

Permalink
kunit: tool: Only print the summary
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
sulix authored and shuahkh committed Nov 19, 2024
1 parent 5017ec6 commit 062a9dd
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 84 deletions.
18 changes: 15 additions & 3 deletions tools/testing/kunit/kunit.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import kunit_json
import kunit_kernel
import kunit_parser
from kunit_printer import stdout
from kunit_printer import stdout, null_printer

class KunitStatus(Enum):
SUCCESS = auto()
Expand All @@ -49,6 +49,7 @@ class KunitBuildRequest(KunitConfigRequest):
class KunitParseRequest:
raw_output: Optional[str]
json: Optional[str]
summary: bool

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

default_printer = stdout
if request.summary:
default_printer = null_printer

# Actually parse the test results.
test = kunit_parser.parse_run_tests(input_data)
test = kunit_parser.parse_run_tests(input_data, default_printer)
parse_time = time.time() - parse_start

kunit_parser.print_summary_line(test, stdout)

if request.json:
json_str = kunit_json.get_json_result(
test=test,
Expand Down Expand Up @@ -413,6 +419,10 @@ def add_parse_opts(parser: argparse.ArgumentParser) -> None:
help='Prints parsed test results as JSON to stdout or a file if '
'a filename is specified. Does nothing if --raw_output is set.',
type=str, const='stdout', default=None, metavar='FILE')
parser.add_argument('--summary',
help='Prints only the summary line for parsed test results.'
'Does nothing if --raw_output is set.',
action='store_true')


def tree_from_args(cli_args: argparse.Namespace) -> kunit_kernel.LinuxSourceTree:
Expand Down Expand Up @@ -448,6 +458,7 @@ def run_handler(cli_args: argparse.Namespace) -> None:
jobs=cli_args.jobs,
raw_output=cli_args.raw_output,
json=cli_args.json,
summary=cli_args.summary,
timeout=cli_args.timeout,
filter_glob=cli_args.filter_glob,
filter=cli_args.filter,
Expand Down Expand Up @@ -495,6 +506,7 @@ def exec_handler(cli_args: argparse.Namespace) -> None:
exec_request = KunitExecRequest(raw_output=cli_args.raw_output,
build_dir=cli_args.build_dir,
json=cli_args.json,
summary=cli_args.summary,
timeout=cli_args.timeout,
filter_glob=cli_args.filter_glob,
filter=cli_args.filter,
Expand All @@ -520,7 +532,7 @@ def parse_handler(cli_args: argparse.Namespace) -> None:
# We know nothing about how the result was created!
metadata = kunit_json.Metadata()
request = KunitParseRequest(raw_output=cli_args.raw_output,
json=cli_args.json)
json=cli_args.json, summary=cli_args.summary)
result, _ = parse_tests(request, metadata, kunit_output)
if result.status != KunitStatus.SUCCESS:
sys.exit(1)
Expand Down
Loading

0 comments on commit 062a9dd

Please sign in to comment.