Skip to content

Commit e173b8b

Browse files
Uriel Guajardoshuahkh
authored andcommitted
kunit: show error if kunit results are not present
Currently, if the kernel is configured incorrectly or if it crashes before any kunit tests are run, kunit finishes without error, reporting that 0 test cases were run. To fix this, an error is shown when the tap header is not found, which indicates that kunit was not able to run at all. Signed-off-by: Uriel Guajardo <[email protected]> Reviewed-by: Brendan Higgins <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent 3f37d14 commit e173b8b

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

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)