Skip to content

Commit 6a499c9

Browse files
dlatypovshuahkh
authored andcommitted
kunit: tool: make --raw_output support only showing kunit output
--raw_output is nice, but it would be nicer if could show only output after KUnit tests have started. So change the flag to allow specifying a string ('kunit'). Make it so `--raw_output` alone will default to `--raw_output=all` and have the same original behavior. Drop the small kunit_parser.raw_output() function since it feels wrong to put it in "kunit_parser.py" when the point of it is to not parse anything. E.g. $ ./tools/testing/kunit/kunit.py run --raw_output=kunit ... [15:24:07] Starting KUnit Kernel ... TAP version 14 1..1 # Subtest: example 1..3 # example_simple_test: initializing ok 1 - example_simple_test # example_skip_test: initializing # example_skip_test: You should not see a line below. ok 2 - example_skip_test # SKIP this test should be skipped # example_mark_skipped_test: initializing # example_mark_skipped_test: You should see a line below. # example_mark_skipped_test: You should see this line. ok 3 - example_mark_skipped_test # SKIP this test should be skipped ok 1 - example [15:24:10] Elapsed time: 6.487s total, 0.001s configuring, 3.510s building, 0.000s running Signed-off-by: Daniel Latypov <dlatypov@google.com> Reviewed-by: David Gow <davidgow@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent 6cb51a1 commit 6a499c9

4 files changed

Lines changed: 30 additions & 12 deletions

File tree

Documentation/dev-tools/kunit/kunit-tool.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,12 @@ results in TAP format, you can pass the ``--raw_output`` argument.
114114
115115
./tools/testing/kunit/kunit.py run --raw_output
116116
117-
.. note::
118-
The raw output from test runs may contain other, non-KUnit kernel log
119-
lines.
117+
The raw output from test runs may contain other, non-KUnit kernel log
118+
lines. You can see just KUnit output with ``--raw_output=kunit``:
119+
120+
.. code-block:: bash
121+
122+
./tools/testing/kunit/kunit.py run --raw_output=kunit
120123
121124
If you have KUnit results in their raw TAP format, you can parse them and print
122125
the human-readable summary with the ``parse`` command for kunit_tool. This

tools/testing/kunit/kunit.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from collections import namedtuple
1818
from enum import Enum, auto
19+
from typing import Iterable
1920

2021
import kunit_config
2122
import kunit_json
@@ -114,7 +115,16 @@ def parse_tests(request: KunitParseRequest) -> KunitResult:
114115
'Tests not Parsed.')
115116

116117
if request.raw_output:
117-
kunit_parser.raw_output(request.input_data)
118+
output: Iterable[str] = request.input_data
119+
if request.raw_output == 'all':
120+
pass
121+
elif request.raw_output == 'kunit':
122+
output = kunit_parser.extract_tap_lines(output)
123+
else:
124+
print(f'Unknown --raw_output option "{request.raw_output}"', file=sys.stderr)
125+
for line in output:
126+
print(line.rstrip())
127+
118128
else:
119129
test_result = kunit_parser.parse_run_tests(request.input_data)
120130
parse_end = time.time()
@@ -135,7 +145,6 @@ def parse_tests(request: KunitParseRequest) -> KunitResult:
135145
return KunitResult(KunitStatus.SUCCESS, test_result,
136146
parse_end - parse_start)
137147

138-
139148
def run_tests(linux: kunit_kernel.LinuxSourceTree,
140149
request: KunitRequest) -> KunitResult:
141150
run_start = time.time()
@@ -181,7 +190,7 @@ def add_common_opts(parser) -> None:
181190
parser.add_argument('--build_dir',
182191
help='As in the make command, it specifies the build '
183192
'directory.',
184-
type=str, default='.kunit', metavar='build_dir')
193+
type=str, default='.kunit', metavar='build_dir')
185194
parser.add_argument('--make_options',
186195
help='X=Y make option, can be repeated.',
187196
action='append')
@@ -246,8 +255,9 @@ def add_exec_opts(parser) -> None:
246255
action='append')
247256

248257
def add_parse_opts(parser) -> None:
249-
parser.add_argument('--raw_output', help='don\'t format output from kernel',
250-
action='store_true')
258+
parser.add_argument('--raw_output', help='If set don\'t format output from kernel. '
259+
'If set to --raw_output=kunit, filters to just KUnit output.',
260+
type=str, nargs='?', const='all', default=None)
251261
parser.add_argument('--json',
252262
nargs='?',
253263
help='Stores test results in a JSON, and either '

tools/testing/kunit/kunit_parser.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,6 @@ def isolate_kunit_output(kernel_output: Iterable[str]) -> Iterator[Tuple[int, st
106106
yield line_num, line[prefix_len:]
107107
return LineStream(lines=isolate_kunit_output(kernel_output))
108108

109-
def raw_output(kernel_output) -> None:
110-
for line in kernel_output:
111-
print(line.rstrip())
112-
113109
DIVIDER = '=' * 60
114110

115111
RESET = '\033[0;0m'

tools/testing/kunit/kunit_tool_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,15 @@ def test_run_raw_output(self):
399399
self.assertNotEqual(call, mock.call(StrContains('Testing complete.')))
400400
self.assertNotEqual(call, mock.call(StrContains(' 0 tests run')))
401401

402+
def test_run_raw_output_kunit(self):
403+
self.linux_source_mock.run_kernel = mock.Mock(return_value=[])
404+
kunit.main(['run', '--raw_output=kunit'], self.linux_source_mock)
405+
self.assertEqual(self.linux_source_mock.build_reconfig.call_count, 1)
406+
self.assertEqual(self.linux_source_mock.run_kernel.call_count, 1)
407+
for call in self.print_mock.call_args_list:
408+
self.assertNotEqual(call, mock.call(StrContains('Testing complete.')))
409+
self.assertNotEqual(call, mock.call(StrContains(' 0 tests run')))
410+
402411
def test_exec_timeout(self):
403412
timeout = 3453
404413
kunit.main(['exec', '--timeout', str(timeout)], self.linux_source_mock)

0 commit comments

Comments
 (0)