kunit: tool: make --raw_output=kunit (aka --raw_output) preserve leading spaces
authorDaniel Latypov <dlatypov@google.com>
Wed, 10 Aug 2022 23:02:58 +0000 (16:02 -0700)
committerShuah Khan <skhan@linuxfoundation.org>
Fri, 30 Sep 2022 19:17:17 +0000 (13:17 -0600)
With
$ kunit.py run --raw_output=all ...
you get the raw output from the kernel, e.g. something like
> TAP version 14
> 1..26
>     # Subtest: time_test_cases
>     1..1
>     ok 1 - time64_to_tm_test_date_range
> ok 1 - time_test_cases

But --raw_output=kunit or equivalently --raw_output, you get
> TAP version 14
> 1..26
> # Subtest: time_test_cases
> 1..1
> ok 1 - time64_to_tm_test_date_range
> ok 1 - time_test_cases

It looks less readable in my opinion, and it also isn't "raw output."

This is due to sharing code with kunit_parser.py, which wants to strip
leading whitespace since it uses anchored regexes.
We could update the kunit_parser.py code to tolerate leaading spaces,
but this patch takes the easier way out and adds a bool flag.

Signed-off-by: Daniel Latypov <dlatypov@google.com>
Reviewed-by: David Gow <davidgow@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
tools/testing/kunit/kunit.py
tools/testing/kunit/kunit_parser.py

index e132b06..161a3b1 100755 (executable)
@@ -206,7 +206,7 @@ def parse_tests(request: KunitParseRequest, metadata: kunit_json.Metadata, input
                if request.raw_output == 'all':
                        pass
                elif request.raw_output == 'kunit':
-                       output = kunit_parser.extract_tap_lines(output)
+                       output = kunit_parser.extract_tap_lines(output, lstrip=False)
                for line in output:
                        print(line.rstrip())
 
index 12d3ec7..1ae873e 100644 (file)
@@ -218,7 +218,7 @@ TAP_START = re.compile(r'TAP version ([0-9]+)$')
 KTAP_END = re.compile('(List of all partitions:|'
        'Kernel panic - not syncing: VFS:|reboot: System halted)')
 
-def extract_tap_lines(kernel_output: Iterable[str]) -> LineStream:
+def extract_tap_lines(kernel_output: Iterable[str], lstrip=True) -> LineStream:
        """Extracts KTAP lines from the kernel output."""
        def isolate_ktap_output(kernel_output: Iterable[str]) \
                        -> Iterator[Tuple[int, str]]:
@@ -244,9 +244,11 @@ def extract_tap_lines(kernel_output: Iterable[str]) -> LineStream:
                                # stop extracting KTAP lines
                                break
                        elif started:
-                               # remove prefix and any indention and yield
-                               # line with line number
-                               line = line[prefix_len:].lstrip()
+                               # remove the prefix and optionally any leading
+                               # whitespace. Our parsing logic relies on this.
+                               line = line[prefix_len:]
+                               if lstrip:
+                                       line = line.lstrip()
                                yield line_num, line
        return LineStream(lines=isolate_ktap_output(kernel_output))