Skip to content

Commit 5584474

Browse files
committed
Merge tag 'linux-kselftest-kunit-fixes-5.8-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pull kunit fixes from Shuah Khan "Fixes for build and run-times failures. Also includes troubleshooting tips updates to kunit user documentation" * tag 'linux-kselftest-kunit-fixes-5.8-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: Documentation: kunit: Add some troubleshooting tips to the FAQ kunit: kunit_tool: Fix invalid result when build fails kunit: show error if kunit results are not present kunit: kunit_config: Fix parsing of CONFIG options with space
2 parents 083176c + c63d2dd commit 5584474

File tree

6 files changed

+59
-6
lines changed

6 files changed

+59
-6
lines changed

Documentation/dev-tools/kunit/faq.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,43 @@ test, or an end-to-end test.
6161
kernel by installing a production configuration of the kernel on production
6262
hardware with a production userspace and then trying to exercise some behavior
6363
that depends on interactions between the hardware, the kernel, and userspace.
64+
65+
KUnit isn't working, what should I do?
66+
======================================
67+
68+
Unfortunately, there are a number of things which can break, but here are some
69+
things to try.
70+
71+
1. Try running ``./tools/testing/kunit/kunit.py run`` with the ``--raw_output``
72+
parameter. This might show details or error messages hidden by the kunit_tool
73+
parser.
74+
2. Instead of running ``kunit.py run``, try running ``kunit.py config``,
75+
``kunit.py build``, and ``kunit.py exec`` independently. This can help track
76+
down where an issue is occurring. (If you think the parser is at fault, you
77+
can run it manually against stdin or a file with ``kunit.py parse``.)
78+
3. Running the UML kernel directly can often reveal issues or error messages
79+
kunit_tool ignores. This should be as simple as running ``./vmlinux`` after
80+
building the UML kernel (e.g., by using ``kunit.py build``). Note that UML
81+
has some unusual requirements (such as the host having a tmpfs filesystem
82+
mounted), and has had issues in the past when built statically and the host
83+
has KASLR enabled. (On older host kernels, you may need to run ``setarch
84+
`uname -m` -R ./vmlinux`` to disable KASLR.)
85+
4. Make sure the kernel .config has ``CONFIG_KUNIT=y`` and at least one test
86+
(e.g. ``CONFIG_KUNIT_EXAMPLE_TEST=y``). kunit_tool will keep its .config
87+
around, so you can see what config was used after running ``kunit.py run``.
88+
It also preserves any config changes you might make, so you can
89+
enable/disable things with ``make ARCH=um menuconfig`` or similar, and then
90+
re-run kunit_tool.
91+
5. Try to run ``make ARCH=um defconfig`` before running ``kunit.py run``. This
92+
may help clean up any residual config items which could be causing problems.
93+
6. Finally, try running KUnit outside UML. KUnit and KUnit tests can run be
94+
built into any kernel, or can be built as a module and loaded at runtime.
95+
Doing so should allow you to determine if UML is causing the issue you're
96+
seeing. When tests are built-in, they will execute when the kernel boots, and
97+
modules will automatically execute associated tests when loaded. Test results
98+
can be collected from ``/sys/kernel/debug/kunit/<test suite>/results``, and
99+
can be parsed with ``kunit.py parse``. For more details, see "KUnit on
100+
non-UML architectures" in :doc:`usage`.
101+
102+
If none of the above tricks help, you are always welcome to email any issues to
103+

tools/testing/kunit/kunit.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ def build_tests(linux: kunit_kernel.LinuxSourceTree,
8282
request.make_options)
8383
build_end = time.time()
8484
if not success:
85-
return KunitResult(KunitStatus.BUILD_FAILURE, 'could not build kernel')
85+
return KunitResult(KunitStatus.BUILD_FAILURE,
86+
'could not build kernel',
87+
build_end - build_start)
8688
if not success:
8789
return KunitResult(KunitStatus.BUILD_FAILURE,
8890
'could not build kernel',

tools/testing/kunit/kunit_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import re
1111

1212
CONFIG_IS_NOT_SET_PATTERN = r'^# CONFIG_(\w+) is not set$'
13-
CONFIG_PATTERN = r'^CONFIG_(\w+)=(\S+)$'
13+
CONFIG_PATTERN = r'^CONFIG_(\w+)=(\S+|".*")$'
1414

1515
KconfigEntryBase = collections.namedtuple('KconfigEntry', ['name', 'value'])
1616

tools/testing/kunit/kunit_parser.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,9 @@ def bubble_up_suite_errors(test_suite_list: List[TestSuite]) -> TestStatus:
265265
return bubble_up_errors(lambda x: x.status, test_suite_list)
266266

267267
def parse_test_result(lines: List[str]) -> TestResult:
268-
if not lines:
269-
return TestResult(TestStatus.NO_TESTS, [], lines)
270268
consume_non_diagnositic(lines)
271-
if not parse_tap_header(lines):
272-
return None
269+
if not lines or not parse_tap_header(lines):
270+
return TestResult(TestStatus.NO_TESTS, [], lines)
273271
test_suites = []
274272
test_suite = parse_test_suite(lines)
275273
while test_suite:
@@ -282,6 +280,8 @@ def parse_run_tests(kernel_output) -> TestResult:
282280
failed_tests = 0
283281
crashed_tests = 0
284282
test_result = parse_test_result(list(isolate_kunit_output(kernel_output)))
283+
if test_result.status == TestStatus.NO_TESTS:
284+
print_with_timestamp(red('[ERROR] ') + 'no kunit output detected')
285285
for test_suite in test_result.suites:
286286
if test_suite.status == TestStatus.SUCCESS:
287287
print_suite_divider(green('[PASSED] ') + test_suite.name)

tools/testing/kunit/kunit_tool_test.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,17 @@ def test_no_tests(self):
170170
result.status)
171171
file.close()
172172

173+
def test_no_kunit_output(self):
174+
crash_log = get_absolute_path(
175+
'test_data/test_insufficient_memory.log')
176+
file = open(crash_log)
177+
print_mock = mock.patch('builtins.print').start()
178+
result = kunit_parser.parse_run_tests(
179+
kunit_parser.isolate_kunit_output(file.readlines()))
180+
print_mock.assert_any_call(StrContains("no kunit output detected"))
181+
print_mock.stop()
182+
file.close()
183+
173184
def test_crashed_test(self):
174185
crashed_log = get_absolute_path(
175186
'test_data/test_is_test_passed-crash.log')

tools/testing/kunit/test_data/test_insufficient_memory.log

Whitespace-only changes.

0 commit comments

Comments
 (0)