On Thu, Feb 22, 2024 at 2:18 PM Rae Moar <rmoar@xxxxxxxxxx> wrote: > > Add ability to parse all files within a directory. Additionally add the > ability to parse all results in the KUnit debugfs repository. Nice, I'd been hoping for this. It's enough to pull me back in for a bit :) <snip> > tools/testing/kunit/kunit.py | 45 ++++++++++++++++++++++++++---------- > 1 file changed, 33 insertions(+), 12 deletions(-) > > diff --git a/tools/testing/kunit/kunit.py b/tools/testing/kunit/kunit.py > index bc74088c458a..827e6dac40ae 100755 > --- a/tools/testing/kunit/kunit.py > +++ b/tools/testing/kunit/kunit.py > @@ -511,19 +511,40 @@ def exec_handler(cli_args: argparse.Namespace) -> None: > > > def parse_handler(cli_args: argparse.Namespace) -> None: > - if cli_args.file is None: > + parsed_files = [] optional: can we annotate the type? parsed_files = [] # type: List[str] > + total_test = kunit_parser.Test() > + total_test.status = kunit_parser.TestStatus.SUCCESS > + if cli_args.file_path is None: > sys.stdin.reconfigure(errors='backslashreplace') # type: ignore > kunit_output = sys.stdin # type: Iterable[str] This branch no longer does anything, since we only parse what's in `parsed_files` E.g. if you try $ kunit.py parse $FILENAME it'll work whereas $ kunit.py parse < $FILENAME will do nothing We'll need to rework the control flow somehow > - else: > - with open(cli_args.file, 'r', errors='backslashreplace') as f: > + elif cli_args.file_path == "debugfs": > + for (root, _, files) in os.walk("/sys/kernel/debug/kunit"): > + for file in files: > + if file == "results": > + parsed_files.append(os.path.join(root, file)) > + elif os.path.isdir(cli_args.file_path): > + for (root, _, files) in os.walk(cli_args.file_path): > + for file in files: > + parsed_files.append(os.path.join(root, file)) just a note here, we could make this a bit terser via parsed_files.extend(os.path.join(root, f) for f in files) and the debugfs branch could be rendered as parsed_files.extend(os.path.join(root, f) for f in files if f == "results") > + elif os.path.isfile(cli_args.file_path): > + parsed_files.append(cli_args.file_path) nit: should there be an `else` here that prints a warning? Example that would trigger this case and silently do nothing $ mkfifo /tmp/example_fifo $ ./tools/testing/kunit/kunit.py parse /tmp/example_fifo <no output> <snip> > @@ -569,8 +590,8 @@ def main(argv: Sequence[str]) -> None: > help='Parses KUnit results from a file, ' > 'and parses formatted results.') > add_parse_opts(parse_parser) > - parse_parser.add_argument('file', > - help='Specifies the file to read results from.', > + parse_parser.add_argument('file_path', > + help='Specifies the file path to read results from.', Should this mention that the make `debugfs` string works? > type=str, nargs='?', metavar='input_file') Tangent: would it be useful to allow the user to pass in multiple files now and set this to nargs='*'? E.g. $ kunit.py parse /my/dir/some_prefix* It would also let people implement their own version of the debugfs logic via $ find /other/debugfs/dir -name 'results' | xargs kunit.py parse That could be useful if the user has recursively copied off the debugfs from a test machine and wants to inspect it elsewhere, for example. Thanks, Daniel