kunit: tool: fix count of tests if late test plan
authorRae Moar <rmoar@google.com>
Wed, 19 Mar 2025 22:33:51 +0000 (22:33 +0000)
committerShuah Khan <skhan@linuxfoundation.org>
Tue, 8 Apr 2025 20:57:24 +0000 (14:57 -0600)
Fix test count with late test plan.

For example,
  TAP version 13
  ok 1 test1
  1..4

Returns a count of 1 passed, 1 crashed (because it expects tests after
the test plan): returning the total count of 2 tests

Change this to be 1 passed, 1 error: total count of 1 test

Link: https://lore.kernel.org/r/20250319223351.1517262-1-rmoar@google.com
Signed-off-by: Rae Moar <rmoar@google.com>
Reviewed-by: David Gow <davidgow@google.com>
Signed-off-by: Shuah Khan <shuah@kernel.org>
tools/testing/kunit/kunit_parser.py
tools/testing/kunit/kunit_tool_test.py

index da53a709773a23252703b74109142294899b1bbb..c176487356e6c94882046b19ea696d750905b8d5 100644 (file)
@@ -809,6 +809,10 @@ def parse_test(lines: LineStream, expected_num: int, log: List[str], is_subtest:
                test.log.extend(parse_diagnostic(lines))
                if test.name != "" and not peek_test_name_match(lines, test):
                        test.add_error(printer, 'missing subtest result line!')
+               elif not lines:
+                       print_log(test.log, printer)
+                       test.status = TestStatus.NO_TESTS
+                       test.add_error(printer, 'No more test results!')
                else:
                        parse_test_result(lines, test, expected_num, printer)
 
index 5ff4f6ffd8736de3fca17dd9fcceabd7a68f9f98..bbba921e0eacb18663abfcabb2bccf330d8666f5 100755 (executable)
@@ -371,8 +371,8 @@ class KUnitParserTest(unittest.TestCase):
                """
                result = kunit_parser.parse_run_tests(output.splitlines(), stdout)
                # Missing test results after test plan should alert a suspected test crash.
-               self.assertEqual(kunit_parser.TestStatus.TEST_CRASHED, result.status)
-               self.assertEqual(result.counts, kunit_parser.TestCounts(passed=1, crashed=1, errors=1))
+               self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status)
+               self.assertEqual(result.counts, kunit_parser.TestCounts(passed=1, errors=2))
 
 def line_stream_from_strs(strs: Iterable[str]) -> kunit_parser.LineStream:
        return kunit_parser.LineStream(enumerate(strs, start=1))