Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kunit: tool: make --raw_output=kunit (aka --raw_output) preserve leading spaces

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>

authored by

Daniel Latypov and committed by
Shuah Khan
a15cfa39 f76349cf

+7 -5
+1 -1
tools/testing/kunit/kunit.py
··· 206 206 if request.raw_output == 'all': 207 207 pass 208 208 elif request.raw_output == 'kunit': 209 - output = kunit_parser.extract_tap_lines(output) 209 + output = kunit_parser.extract_tap_lines(output, lstrip=False) 210 210 for line in output: 211 211 print(line.rstrip()) 212 212
+6 -4
tools/testing/kunit/kunit_parser.py
··· 218 218 KTAP_END = re.compile('(List of all partitions:|' 219 219 'Kernel panic - not syncing: VFS:|reboot: System halted)') 220 220 221 - def extract_tap_lines(kernel_output: Iterable[str]) -> LineStream: 221 + def extract_tap_lines(kernel_output: Iterable[str], lstrip=True) -> LineStream: 222 222 """Extracts KTAP lines from the kernel output.""" 223 223 def isolate_ktap_output(kernel_output: Iterable[str]) \ 224 224 -> Iterator[Tuple[int, str]]: ··· 244 244 # stop extracting KTAP lines 245 245 break 246 246 elif started: 247 - # remove prefix and any indention and yield 248 - # line with line number 249 - line = line[prefix_len:].lstrip() 247 + # remove the prefix and optionally any leading 248 + # whitespace. Our parsing logic relies on this. 249 + line = line[prefix_len:] 250 + if lstrip: 251 + line = line.lstrip() 250 252 yield line_num, line 251 253 return LineStream(lines=isolate_ktap_output(kernel_output)) 252 254