Skip to content

Commit ed01ad3

Browse files
rmr167shuahkh
authored andcommitted
kunit: tool: Fix error messages for cases of no tests and wrong TAP header
This patch addresses misleading error messages reported by kunit_tool in two cases. First, in the case of TAP output having an incorrect header format or missing a header, the parser used to output an error message of 'no tests run!'. Now the parser outputs an error message of 'could not parse test results!'. As an example: Before: $ ./tools/testing/kunit/kunit.py parse /dev/null [ERROR] no tests run! ... After: $ ./tools/testing/kunit/kunit.py parse /dev/null [ERROR] could not parse test results! ... Second, in the case of TAP output with the correct header but no tests, the parser used to output an error message of 'could not parse test results!'. Now the parser outputs an error message of 'no tests run!'. As an example: Before: $ echo -e 'TAP version 14\n1..0' | ./tools/testing/kunit/kunit.py parse [ERROR] could not parse test results! After: $ echo -e 'TAP version 14\n1..0' | ./tools/testing/kunit/kunit.py parse [ERROR] no tests run! Additionally, this patch also corrects the tests in kunit_tool_test.py and adds a test to check the error in the case of TAP output with the correct header but no tests. Signed-off-by: Rae Moar <[email protected]> Reviewed-by: David Gow <[email protected]> Reviewed-by: Daniel Latypov <[email protected]> Reviewed-by: Brendan Higgins <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent e73f0f0 commit ed01ad3

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

tools/testing/kunit/kunit_parser.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,11 @@ def bubble_up_suite_errors(test_suites: Iterable[TestSuite]) -> TestStatus:
338338
def parse_test_result(lines: LineStream) -> TestResult:
339339
consume_non_diagnostic(lines)
340340
if not lines or not parse_tap_header(lines):
341-
return TestResult(TestStatus.NO_TESTS, [], lines)
341+
return TestResult(TestStatus.FAILURE_TO_PARSE_TESTS, [], lines)
342342
expected_test_suite_num = parse_test_plan(lines)
343-
if not expected_test_suite_num:
343+
if expected_test_suite_num == 0:
344+
return TestResult(TestStatus.NO_TESTS, [], lines)
345+
elif expected_test_suite_num is None:
344346
return TestResult(TestStatus.FAILURE_TO_PARSE_TESTS, [], lines)
345347
test_suites = []
346348
for i in range(1, expected_test_suite_num + 1):

tools/testing/kunit/kunit_tool_test.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,18 @@ def test_parse_failed_test_log(self):
157157
kunit_parser.TestStatus.FAILURE,
158158
result.status)
159159

160+
def test_no_header(self):
161+
empty_log = test_data_path('test_is_test_passed-no_tests_run_no_header.log')
162+
with open(empty_log) as file:
163+
result = kunit_parser.parse_run_tests(
164+
kunit_parser.extract_tap_lines(file.readlines()))
165+
self.assertEqual(0, len(result.suites))
166+
self.assertEqual(
167+
kunit_parser.TestStatus.FAILURE_TO_PARSE_TESTS,
168+
result.status)
169+
160170
def test_no_tests(self):
161-
empty_log = test_data_path('test_is_test_passed-no_tests_run.log')
171+
empty_log = test_data_path('test_is_test_passed-no_tests_run_with_header.log')
162172
with open(empty_log) as file:
163173
result = kunit_parser.parse_run_tests(
164174
kunit_parser.extract_tap_lines(file.readlines()))
@@ -173,7 +183,7 @@ def test_no_kunit_output(self):
173183
with open(crash_log) as file:
174184
result = kunit_parser.parse_run_tests(
175185
kunit_parser.extract_tap_lines(file.readlines()))
176-
print_mock.assert_any_call(StrContains('no tests run!'))
186+
print_mock.assert_any_call(StrContains('could not parse test results!'))
177187
print_mock.stop()
178188
file.close()
179189

@@ -309,7 +319,7 @@ def test_crashed_test_json(self):
309319
result["sub_groups"][1]["test_cases"][0])
310320

311321
def test_no_tests_json(self):
312-
result = self._json_for('test_is_test_passed-no_tests_run.log')
322+
result = self._json_for('test_is_test_passed-no_tests_run_with_header.log')
313323
self.assertEqual(0, len(result['sub_groups']))
314324

315325
class StrContains(str):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
TAP version 14
2+
1..0

0 commit comments

Comments
 (0)