Commit 6a499c9c authored by Daniel Latypov's avatar Daniel Latypov Committed by Shuah Khan

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: default avatarDaniel Latypov <dlatypov@google.com>
Reviewed-by: default avatarDavid Gow <davidgow@google.com>
Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
parent 6cb51a18
...@@ -114,9 +114,12 @@ results in TAP format, you can pass the ``--raw_output`` argument. ...@@ -114,9 +114,12 @@ results in TAP format, you can pass the ``--raw_output`` argument.
./tools/testing/kunit/kunit.py run --raw_output ./tools/testing/kunit/kunit.py run --raw_output
.. note:: The raw output from test runs may contain other, non-KUnit kernel log
The raw output from test runs may contain other, non-KUnit kernel log lines. You can see just KUnit output with ``--raw_output=kunit``:
lines.
.. code-block:: bash
./tools/testing/kunit/kunit.py run --raw_output=kunit
If you have KUnit results in their raw TAP format, you can parse them and print If you have KUnit results in their raw TAP format, you can parse them and print
the human-readable summary with the ``parse`` command for kunit_tool. This the human-readable summary with the ``parse`` command for kunit_tool. This
......
...@@ -16,6 +16,7 @@ assert sys.version_info >= (3, 7), "Python version is too old" ...@@ -16,6 +16,7 @@ assert sys.version_info >= (3, 7), "Python version is too old"
from collections import namedtuple from collections import namedtuple
from enum import Enum, auto from enum import Enum, auto
from typing import Iterable
import kunit_config import kunit_config
import kunit_json import kunit_json
...@@ -114,7 +115,16 @@ def parse_tests(request: KunitParseRequest) -> KunitResult: ...@@ -114,7 +115,16 @@ def parse_tests(request: KunitParseRequest) -> KunitResult:
'Tests not Parsed.') 'Tests not Parsed.')
if request.raw_output: if request.raw_output:
kunit_parser.raw_output(request.input_data) output: Iterable[str] = request.input_data
if request.raw_output == 'all':
pass
elif request.raw_output == 'kunit':
output = kunit_parser.extract_tap_lines(output)
else:
print(f'Unknown --raw_output option "{request.raw_output}"', file=sys.stderr)
for line in output:
print(line.rstrip())
else: else:
test_result = kunit_parser.parse_run_tests(request.input_data) test_result = kunit_parser.parse_run_tests(request.input_data)
parse_end = time.time() parse_end = time.time()
...@@ -135,7 +145,6 @@ def parse_tests(request: KunitParseRequest) -> KunitResult: ...@@ -135,7 +145,6 @@ def parse_tests(request: KunitParseRequest) -> KunitResult:
return KunitResult(KunitStatus.SUCCESS, test_result, return KunitResult(KunitStatus.SUCCESS, test_result,
parse_end - parse_start) parse_end - parse_start)
def run_tests(linux: kunit_kernel.LinuxSourceTree, def run_tests(linux: kunit_kernel.LinuxSourceTree,
request: KunitRequest) -> KunitResult: request: KunitRequest) -> KunitResult:
run_start = time.time() run_start = time.time()
...@@ -246,8 +255,9 @@ def add_exec_opts(parser) -> None: ...@@ -246,8 +255,9 @@ def add_exec_opts(parser) -> None:
action='append') action='append')
def add_parse_opts(parser) -> None: def add_parse_opts(parser) -> None:
parser.add_argument('--raw_output', help='don\'t format output from kernel', parser.add_argument('--raw_output', help='If set don\'t format output from kernel. '
action='store_true') 'If set to --raw_output=kunit, filters to just KUnit output.',
type=str, nargs='?', const='all', default=None)
parser.add_argument('--json', parser.add_argument('--json',
nargs='?', nargs='?',
help='Stores test results in a JSON, and either ' help='Stores test results in a JSON, and either '
......
...@@ -106,10 +106,6 @@ def extract_tap_lines(kernel_output: Iterable[str]) -> LineStream: ...@@ -106,10 +106,6 @@ def extract_tap_lines(kernel_output: Iterable[str]) -> LineStream:
yield line_num, line[prefix_len:] yield line_num, line[prefix_len:]
return LineStream(lines=isolate_kunit_output(kernel_output)) return LineStream(lines=isolate_kunit_output(kernel_output))
def raw_output(kernel_output) -> None:
for line in kernel_output:
print(line.rstrip())
DIVIDER = '=' * 60 DIVIDER = '=' * 60
RESET = '\033[0;0m' RESET = '\033[0;0m'
......
...@@ -399,6 +399,15 @@ class KUnitMainTest(unittest.TestCase): ...@@ -399,6 +399,15 @@ class KUnitMainTest(unittest.TestCase):
self.assertNotEqual(call, mock.call(StrContains('Testing complete.'))) self.assertNotEqual(call, mock.call(StrContains('Testing complete.')))
self.assertNotEqual(call, mock.call(StrContains(' 0 tests run'))) self.assertNotEqual(call, mock.call(StrContains(' 0 tests run')))
def test_run_raw_output_kunit(self):
self.linux_source_mock.run_kernel = mock.Mock(return_value=[])
kunit.main(['run', '--raw_output=kunit'], self.linux_source_mock)
self.assertEqual(self.linux_source_mock.build_reconfig.call_count, 1)
self.assertEqual(self.linux_source_mock.run_kernel.call_count, 1)
for call in self.print_mock.call_args_list:
self.assertNotEqual(call, mock.call(StrContains('Testing complete.')))
self.assertNotEqual(call, mock.call(StrContains(' 0 tests run')))
def test_exec_timeout(self): def test_exec_timeout(self):
timeout = 3453 timeout = 3453
kunit.main(['exec', '--timeout', str(timeout)], self.linux_source_mock) kunit.main(['exec', '--timeout', str(timeout)], self.linux_source_mock)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment