* [PATCH v2 0/2] kunit: tool: Preserve failures in parsed KTAP results
@ 2026-11-24 16:43 Louis H. Poulin II via B4 Relay
2026-11-24 16:43 ` [PATCH v2 1/2] kunit: tool: Count failed suites with only skipped tests Louis H. Poulin II via B4 Relay
2026-11-24 16:43 ` [PATCH v2 2/2] kunit: tool: Fail on out-of-sequence test numbers Louis H. Poulin II via B4 Relay
0 siblings, 2 replies; 5+ messages in thread
From: Louis H. Poulin II via B4 Relay @ 2026-11-24 16:43 UTC (permalink / raw)
To: Brendan Higgins, David Gow
Cc: Rae Moar, linux-kselftest, kunit-dev, linux-kernel, Louis H. Poulin II
The KUnit tool's saved-log parser does not consistently propagate two
failure conditions. A suite reporting not ok with only skipped children
leaves the run SKIPPED. A result with an out-of-sequence number can
still be counted as successful, so kunit.py parse may exit 0 for that
malformed log.
Patch 1 preserves the suite's reported failure in aggregate counts.
Patch 2 marks out-of-sequence result records as failed. It depends on
patch 1 for a malformed parent suite whose child tests are all skipped.
Tested: kunit_tool_test.py (100 tests, all pass) and strict checkpatch
on both patches. No live kernel run was performed.
Changes in v2:
- Resend using b4; v1 was mangled by line wrapping in the mail client
(reported by David Gow).
- Rebase onto v7.4-rc1; no changes under tools/testing/kunit since v1.
- Patch 1: move the Fixes: tag adjacent to Signed-off-by:. No code change.
- Patch 2: no change.
v1: https://lore.kernel.org/r/CAGQButum4PYb4A%2Bhmqg-bJZbf4L3KkH6rT9tn-0_NTs3xLhGYw@mail.gmail.com
Signed-off-by: Louis H. Poulin II <poulin.louis@student.oaklandcc.edu>
---
Louis H. Poulin II (2):
kunit: tool: Count failed suites with only skipped tests
kunit: tool: Fail on out-of-sequence test numbers
tools/testing/kunit/kunit_parser.py | 15 +++---
tools/testing/kunit/kunit_tool_test.py | 92 ++++++++++++++++++++++++++++++++--
2 files changed, 98 insertions(+), 9 deletions(-)
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261124-kunit-v2-d08e69968672
Best regards,
--
Louis H. Poulin II <poulin.louis@student.oaklandcc.edu>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/2] kunit: tool: Count failed suites with only skipped tests
2026-11-24 16:43 [PATCH v2 0/2] kunit: tool: Preserve failures in parsed KTAP results Louis H. Poulin II via B4 Relay
@ 2026-11-24 16:43 ` Louis H. Poulin II via B4 Relay
2026-11-25 5:22 ` David Gow
2026-11-24 16:43 ` [PATCH v2 2/2] kunit: tool: Fail on out-of-sequence test numbers Louis H. Poulin II via B4 Relay
1 sibling, 1 reply; 5+ messages in thread
From: Louis H. Poulin II via B4 Relay @ 2026-11-24 16:43 UTC (permalink / raw)
To: Brendan Higgins, David Gow
Cc: Rae Moar, linux-kselftest, kunit-dev, linux-kernel, Louis H. Poulin II
From: "Louis H. Poulin II" <poulin.louis@student.oaklandcc.edu>
A suite can report not ok while all its child cases are skipped.
The parser retains the suite status as FAILURE but counts only the
skipped children. The run status is then derived from those counts and
incorrectly reports SKIPPED.
When a suite reports failure and the child aggregate is SKIPPED, add
a failed count for the suite, as is already done when child aggregate
is SUCCESS. Cover a correctly numbered failing suite with a skipped
child.
Fixes: d65d07cb5b01 ("kunit: tool: improve compatibility of kunit_parser with KTAP specification")
Signed-off-by: Louis H. Poulin II <poulin.louis@student.oaklandcc.edu>
---
tools/testing/kunit/kunit_parser.py | 4 +++-
tools/testing/kunit/kunit_tool_test.py | 13 +++++++++++++
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/tools/testing/kunit/kunit_parser.py b/tools/testing/kunit/kunit_parser.py
index d722874b..dce365d1 100644
--- a/tools/testing/kunit/kunit_parser.py
+++ b/tools/testing/kunit/kunit_parser.py
@@ -694,7 +694,9 @@ def bubble_up_test_results(test: Test) -> None:
elif test.counts.get_status() == TestStatus.TEST_CRASHED:
test.status = TestStatus.TEST_CRASHED
- if status == TestStatus.FAILURE and test.counts.get_status() == TestStatus.SUCCESS:
+ # Preserve a failing suite result when its children all pass or skip.
+ if (status == TestStatus.FAILURE and
+ test.counts.get_status() in (TestStatus.SUCCESS, TestStatus.SKIPPED)):
counts.add_status(status)
def parse_test(lines: LineStream, expected_num: int, log: List[str], is_subtest: bool, printer: Printer) -> Test:
diff --git a/tools/testing/kunit/kunit_tool_test.py b/tools/testing/kunit/kunit_tool_test.py
index 85ae2175..5fd386d0 100755
--- a/tools/testing/kunit/kunit_tool_test.py
+++ b/tools/testing/kunit/kunit_tool_test.py
@@ -265,6 +265,19 @@ class KUnitParserTest(unittest.TestCase):
self.assertEqual(kunit_parser.TestStatus.SKIPPED, result.status)
self.assertEqual(result.counts, kunit_parser.TestCounts(skipped=5))
+ def test_failed_suite_with_skipped_child_fails(self):
+ output = ['KTAP version 1', '1..1',
+ ' KTAP version 1', ' # Subtest: suite', ' 1..1',
+ ' ok 1 - case # SKIP reason', 'not ok 1 - suite']
+ result = kunit_parser.parse_run_tests(output, stdout)
+ suite = result.subtests[0]
+ self.assertEqual(kunit_parser.TestStatus.SKIPPED, suite.subtests[0].status)
+ self.assertEqual(kunit_parser.TestStatus.FAILURE, suite.status)
+ self.assertEqual(suite.counts,
+ kunit_parser.TestCounts(failed=1, skipped=1))
+ self.assertEqual(kunit_parser.TestStatus.FAILURE, result.status)
+ self.assertEqual(result.counts, suite.counts)
+
def test_ignores_hyphen(self):
hyphen_log = _test_data_path('test_strip_hyphen.log')
with open(hyphen_log) as file:
--
2.56.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 2/2] kunit: tool: Fail on out-of-sequence test numbers
2026-11-24 16:43 [PATCH v2 0/2] kunit: tool: Preserve failures in parsed KTAP results Louis H. Poulin II via B4 Relay
2026-11-24 16:43 ` [PATCH v2 1/2] kunit: tool: Count failed suites with only skipped tests Louis H. Poulin II via B4 Relay
@ 2026-11-24 16:43 ` Louis H. Poulin II via B4 Relay
2026-11-25 5:22 ` David Gow
1 sibling, 1 reply; 5+ messages in thread
From: Louis H. Poulin II via B4 Relay @ 2026-11-24 16:43 UTC (permalink / raw)
To: Brendan Higgins, David Gow
Cc: Rae Moar, linux-kselftest, kunit-dev, linux-kernel, Louis H. Poulin II
From: "Louis H. Poulin II" <poulin.louis@student.oaklandcc.edu>
KTAP requires numbering to start at 1 and increase by one at each
nesting level. The parser notes a mismatch as an error but can still
mark an ok or skipped result as successful. A saved log with duplicate
numbers can make kunit.py parse exit 0.
After decoding ok or SKIP, mark a wrongly numbered result as FAILURE.
The result record is malformed even if the test assertion printed ok.
It then contributes to both failed and error counts. This avoids a
broader policy of failing on every parse error, which would also
change late-plan handling. The preceding patch preserves this failure
when a parent suite has only skipped children.
This change covers numbering mismatches only. A missing numbered line
can flag subsequent results whose numbers differ from their expected
positions. Other malformed or truncated logs retain their existing
status policy.
Commit 14e594a1fc8b ("kunit: tool: fix count of tests if late test
plan") deliberately kept a parsed pass despite missing results after
a late plan. Its fixture also had an unrelated ok 4 result. Number
that result as ok 1 to keep the plan test focused, and cover a wrong
first number separately. Add duplicate, SKIP, nested-suite, missing
number and CLI exit-code tests.
Signed-off-by: Louis H. Poulin II <poulin.louis@student.oaklandcc.edu>
---
tools/testing/kunit/kunit_parser.py | 11 ++---
tools/testing/kunit/kunit_tool_test.py | 79 ++++++++++++++++++++++++++++++++--
2 files changed, 82 insertions(+), 8 deletions(-)
diff --git a/tools/testing/kunit/kunit_parser.py b/tools/testing/kunit/kunit_parser.py
index dce365d1..38547312 100644
--- a/tools/testing/kunit/kunit_parser.py
+++ b/tools/testing/kunit/kunit_parser.py
@@ -423,11 +423,6 @@ def parse_test_result(lines: LineStream, test: Test,
else:
test.name = match.group(4)
- # Check test num
- num = int(match.group(2))
- if num != expected_num:
- test.add_error(printer, f'Expected test number {expected_num} but found {num}')
-
# Set status of test object
status = match.group(1)
if skip_match:
@@ -437,6 +432,12 @@ def parse_test_result(lines: LineStream, test: Test,
test.status = TestStatus.SUCCESS
else:
test.status = TestStatus.FAILURE
+
+ # A malformed result must not make the run successful.
+ num = int(match.group(2))
+ if num != expected_num:
+ test.add_error(printer, f'Expected test number {expected_num} but found {num}')
+ test.status = TestStatus.FAILURE
return True
def parse_diagnostic(lines: LineStream) -> List[str]:
diff --git a/tools/testing/kunit/kunit_tool_test.py b/tools/testing/kunit/kunit_tool_test.py
index 5fd386d0..6a3011de 100755
--- a/tools/testing/kunit/kunit_tool_test.py
+++ b/tools/testing/kunit/kunit_tool_test.py
@@ -410,13 +410,78 @@ class KUnitParserTest(unittest.TestCase):
def test_parse_late_test_plan(self):
output = """
TAP version 13
- ok 4 test4
+ ok 1 test1
1..4
"""
result = kunit_parser.parse_run_tests(output.splitlines(), stdout)
- # Missing test results after test plan should alert a suspected test crash.
+ # Keep this test focused on a late plan, not result numbering.
self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status)
- self.assertEqual(result.counts, kunit_parser.TestCounts(passed=1, errors=2))
+ self.assertEqual(result.counts, kunit_parser.TestCounts(passed=1, errors=1))
+
+ def test_wrong_first_number_fails(self):
+ output = ['KTAP version 1', '1..1', 'ok 4 - fourth']
+ result = kunit_parser.parse_run_tests(output, stdout)
+ self.assertEqual(kunit_parser.TestStatus.FAILURE, result.status)
+ self.assertEqual(result.counts, kunit_parser.TestCounts(failed=1, errors=1))
+
+ def test_repeated_test_number_fails(self):
+ output = ['KTAP version 1', '1..2', 'ok 1 - first', 'ok 1 - second']
+ result = kunit_parser.parse_run_tests(output, stdout)
+ self.assertEqual(kunit_parser.TestStatus.FAILURE, result.status)
+ self.assertEqual(result.counts,
+ kunit_parser.TestCounts(passed=1, failed=1, errors=1))
+
+ def test_missing_number_fails_later_results(self):
+ output = ['KTAP version 1', '1..3',
+ 'ok 1 - first', 'ok 3 - third', 'ok 4 - fourth']
+ result = kunit_parser.parse_run_tests(output, stdout)
+ self.assertEqual(kunit_parser.TestStatus.FAILURE, result.status)
+ self.assertEqual(result.counts,
+ kunit_parser.TestCounts(passed=1, failed=2, errors=2))
+
+ def test_wrong_numbered_skip_fails(self):
+ output = ['KTAP version 1', '1..1', 'ok 2 - skipped # SKIP reason']
+ result = kunit_parser.parse_run_tests(output, stdout)
+ self.assertEqual(kunit_parser.TestStatus.FAILURE, result.status)
+ self.assertEqual(result.counts, kunit_parser.TestCounts(failed=1, errors=1))
+
+ def test_wrong_numbered_suite_result_fails(self):
+ output = ['KTAP version 1', '1..1',
+ ' KTAP version 1', ' # Subtest: suite', ' 1..1',
+ ' ok 1 - case', 'ok 2 - suite']
+ result = kunit_parser.parse_run_tests(output, stdout)
+ suite = result.subtests[0]
+ self.assertEqual(kunit_parser.TestStatus.SUCCESS, suite.subtests[0].status)
+ self.assertEqual(kunit_parser.TestStatus.FAILURE, suite.status)
+ self.assertEqual(suite.counts,
+ kunit_parser.TestCounts(passed=1, failed=1, errors=1))
+ self.assertEqual(kunit_parser.TestStatus.FAILURE, result.status)
+ self.assertEqual(result.counts, suite.counts)
+
+ def test_wrong_numbered_nested_case_fails(self):
+ output = ['KTAP version 1', '1..1',
+ ' KTAP version 1', ' # Subtest: suite', ' 1..1',
+ ' ok 2 - case', 'ok 1 - suite']
+ result = kunit_parser.parse_run_tests(output, stdout)
+ suite = result.subtests[0]
+ self.assertEqual(kunit_parser.TestStatus.FAILURE, suite.subtests[0].status)
+ self.assertEqual(suite.counts,
+ kunit_parser.TestCounts(failed=1, errors=1))
+ self.assertEqual(kunit_parser.TestStatus.FAILURE, result.status)
+ self.assertEqual(result.counts, suite.counts)
+
+ def test_wrong_numbered_suite_with_skipped_child_fails(self):
+ output = ['KTAP version 1', '1..1',
+ ' KTAP version 1', ' # Subtest: suite', ' 1..1',
+ ' ok 1 - case # SKIP reason', 'ok 2 - suite']
+ result = kunit_parser.parse_run_tests(output, stdout)
+ suite = result.subtests[0]
+ self.assertEqual(kunit_parser.TestStatus.SKIPPED, suite.subtests[0].status)
+ self.assertEqual(kunit_parser.TestStatus.FAILURE, suite.status)
+ self.assertEqual(suite.counts,
+ kunit_parser.TestCounts(failed=1, skipped=1, errors=1))
+ self.assertEqual(kunit_parser.TestStatus.FAILURE, result.status)
+ self.assertEqual(result.counts, suite.counts)
def line_stream_from_strs(strs: Iterable[str]) -> kunit_parser.LineStream:
return kunit_parser.LineStream(enumerate(strs, start=1))
@@ -797,6 +862,14 @@ class KUnitMainTest(unittest.TestCase):
self.assertEqual(self.linux_source_mock.run_kernel.call_count, 1)
self.print_mock.assert_any_call(StrContains('Could not find any KTAP output.'))
+ def test_parse_duplicate_number_exits_failure(self):
+ with tempfile.NamedTemporaryFile(mode='w+', delete=True) as log:
+ log.write('KTAP version 1\n1..2\nok 1 - first\nok 1 - second\n')
+ log.flush()
+ with self.assertRaises(SystemExit) as result:
+ kunit.main(['parse', log.name])
+ self.assertEqual(result.exception.code, 1)
+
def test_exec_no_tests(self):
self.linux_source_mock.run_kernel = mock.Mock(return_value=['TAP version 14', '1..0'])
with self.assertRaises(SystemExit) as e:
--
2.56.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/2] kunit: tool: Count failed suites with only skipped tests
2026-11-24 16:43 ` [PATCH v2 1/2] kunit: tool: Count failed suites with only skipped tests Louis H. Poulin II via B4 Relay
@ 2026-11-25 5:22 ` David Gow
0 siblings, 0 replies; 5+ messages in thread
From: David Gow @ 2026-11-25 5:22 UTC (permalink / raw)
To: poulin.louis, Brendan Higgins
Cc: Rae Moar, linux-kselftest, kunit-dev, linux-kernel
Le 25/11/2026 à 00:43, Louis H. Poulin II via B4 Relay a écrit :
> From: "Louis H. Poulin II" <poulin.louis@student.oaklandcc.edu>
>
> A suite can report not ok while all its child cases are skipped.
> The parser retains the suite status as FAILURE but counts only the
> skipped children. The run status is then derived from those counts and
> incorrectly reports SKIPPED.
>
> When a suite reports failure and the child aggregate is SKIPPED, add
> a failed count for the suite, as is already done when child aggregate
> is SUCCESS. Cover a correctly numbered failing suite with a skipped
> child.
>
> Fixes: d65d07cb5b01 ("kunit: tool: improve compatibility of kunit_parser with KTAP specification")
> Signed-off-by: Louis H. Poulin II <poulin.louis@student.oaklandcc.edu>
> ---
Thanks very much: this patch survived the sending process successfully.
I do think that it's a little bit confusing to, depending on the status
of the suite, suddenly get an extra test failure in the result count.
But ultimately, it's probably less confusing than having the failure
disappear altogether, so I'm okay with it.
Two other suggestions:
- The test data should live in tools/testing/kunit/test_data alongside
all of the other test KTAP.
- It'd be nice to update _summarize_failed_tests() to count these. It
should be as simple as extending the 'len(failed_subtests) ==
len(test.subtests)' check to also compare against 0, as far as I can
tell. (Note, though, that this doesn't trigger by default unless there
are >=100 tests run, so you may wish to hack that out to test it.)
With those, I think this would be good.
Cheers,
-- David
> tools/testing/kunit/kunit_parser.py | 4 +++-
> tools/testing/kunit/kunit_tool_test.py | 13 +++++++++++++
> 2 files changed, 16 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/kunit/kunit_parser.py b/tools/testing/kunit/kunit_parser.py
> index d722874b..dce365d1 100644
> --- a/tools/testing/kunit/kunit_parser.py
> +++ b/tools/testing/kunit/kunit_parser.py
> @@ -694,7 +694,9 @@ def bubble_up_test_results(test: Test) -> None:
> elif test.counts.get_status() == TestStatus.TEST_CRASHED:
> test.status = TestStatus.TEST_CRASHED
>
> - if status == TestStatus.FAILURE and test.counts.get_status() == TestStatus.SUCCESS:
> + # Preserve a failing suite result when its children all pass or skip.
> + if (status == TestStatus.FAILURE and
> + test.counts.get_status() in (TestStatus.SUCCESS, TestStatus.SKIPPED)):
> counts.add_status(status)
>
> def parse_test(lines: LineStream, expected_num: int, log: List[str], is_subtest: bool, printer: Printer) -> Test:
> diff --git a/tools/testing/kunit/kunit_tool_test.py b/tools/testing/kunit/kunit_tool_test.py
> index 85ae2175..5fd386d0 100755
> --- a/tools/testing/kunit/kunit_tool_test.py
> +++ b/tools/testing/kunit/kunit_tool_test.py
> @@ -265,6 +265,19 @@ class KUnitParserTest(unittest.TestCase):
> self.assertEqual(kunit_parser.TestStatus.SKIPPED, result.status)
> self.assertEqual(result.counts, kunit_parser.TestCounts(skipped=5))
>
> + def test_failed_suite_with_skipped_child_fails(self):
> + output = ['KTAP version 1', '1..1',
> + ' KTAP version 1', ' # Subtest: suite', ' 1..1',
> + ' ok 1 - case # SKIP reason', 'not ok 1 - suite']
For consistency, can we put this in a file in
tools/testing/kunit/test_data -- that's what the other tests here do,
and it makes it easier to debug the failures, IMO.
If you _really_ want to keep it here (which is fine if you have a really
good reason, though I'd want to hear it), can we at least reformat it to
have one line per line: as is, it's quite difficult to read.
> + result = kunit_parser.parse_run_tests(output, stdout)
> + suite = result.subtests[0]
> + self.assertEqual(kunit_parser.TestStatus.SKIPPED, suite.subtests[0].status)
> + self.assertEqual(kunit_parser.TestStatus.FAILURE, suite.status)
> + self.assertEqual(suite.counts,
> + kunit_parser.TestCounts(failed=1, skipped=1))
> + self.assertEqual(kunit_parser.TestStatus.FAILURE, result.status)
> + self.assertEqual(result.counts, suite.counts)
> +
> def test_ignores_hyphen(self):
> hyphen_log = _test_data_path('test_strip_hyphen.log')
> with open(hyphen_log) as file:
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 2/2] kunit: tool: Fail on out-of-sequence test numbers
2026-11-24 16:43 ` [PATCH v2 2/2] kunit: tool: Fail on out-of-sequence test numbers Louis H. Poulin II via B4 Relay
@ 2026-11-25 5:22 ` David Gow
0 siblings, 0 replies; 5+ messages in thread
From: David Gow @ 2026-11-25 5:22 UTC (permalink / raw)
To: poulin.louis, Brendan Higgins
Cc: Rae Moar, linux-kselftest, kunit-dev, linux-kernel
Le 25/11/2026 à 00:43, Louis H. Poulin II via B4 Relay a écrit :
> From: "Louis H. Poulin II" <poulin.louis@student.oaklandcc.edu>
>
> KTAP requires numbering to start at 1 and increase by one at each
> nesting level. The parser notes a mismatch as an error but can still
> mark an ok or skipped result as successful. A saved log with duplicate
> numbers can make kunit.py parse exit 0.
>
> After decoding ok or SKIP, mark a wrongly numbered result as FAILURE.
> The result record is malformed even if the test assertion printed ok.
> It then contributes to both failed and error counts. This avoids a
> broader policy of failing on every parse error, which would also
> change late-plan handling. The preceding patch preserves this failure
> when a parent suite has only skipped children.
>
> This change covers numbering mismatches only. A missing numbered line
> can flag subsequent results whose numbers differ from their expected
> positions. Other malformed or truncated logs retain their existing
> status policy.
>
> Commit 14e594a1fc8b ("kunit: tool: fix count of tests if late test
> plan") deliberately kept a parsed pass despite missing results after
> a late plan. Its fixture also had an unrelated ok 4 result. Number
> that result as ok 1 to keep the plan test focused, and cover a wrong
> first number separately. Add duplicate, SKIP, nested-suite, missing
> number and CLI exit-code tests.
>
> Signed-off-by: Louis H. Poulin II <poulin.louis@student.oaklandcc.edu>
> ---
Hmm... I distinctly recall there being a reason we didn't fail in this
case: I think it was due to some tests being triggered early, so having
two concatenated KTAP outputs in the kernel log at boot. That seems
fixed, though, so I don't have a fundamental objection to this.
That being said, if anyone's using the KUnit KTAP parser for non-KUnit-y
things which would fall afoul of this, now's the time to speak up!
As for the patch itself, it looks fine: the only real issues are with
the comments and tests. For the comments: I think they need to be more
specific about what we're doing (and targeted at people reading the
code, not people looking at the changes in the patch).
As for the tests: they're extremely thorough -- perhaps excessively so.
Do you think it'd be sensible to consolidate a few of them into a
smaller number of more complicated examples. kunit_tool_test is already
getting quite large and complicated, and this is a small, unlikely
possibility which will probably need debugging only rarely, so a more
complicated example shouldn't be a problem.
Equally, as with the previous patch, it'd be great to have the test
inputs in separate files in tools/testing/kunit/test_data/ as with most
of the other tests.
Cheers,
-- David
> tools/testing/kunit/kunit_parser.py | 11 ++---
> tools/testing/kunit/kunit_tool_test.py | 79 ++++++++++++++++++++++++++++++++--
> 2 files changed, 82 insertions(+), 8 deletions(-)
>
> diff --git a/tools/testing/kunit/kunit_parser.py b/tools/testing/kunit/kunit_parser.py
> index dce365d1..38547312 100644
> --- a/tools/testing/kunit/kunit_parser.py
> +++ b/tools/testing/kunit/kunit_parser.py
> @@ -423,11 +423,6 @@ def parse_test_result(lines: LineStream, test: Test,
> else:
> test.name = match.group(4)
>
> - # Check test num
> - num = int(match.group(2))
> - if num != expected_num:
> - test.add_error(printer, f'Expected test number {expected_num} but found {num}')
> -
> # Set status of test object
> status = match.group(1)
> if skip_match:
> @@ -437,6 +432,12 @@ def parse_test_result(lines: LineStream, test: Test,
> test.status = TestStatus.SUCCESS
> else:
> test.status = TestStatus.FAILURE
> +
> + # A malformed result must not make the run successful.
Let's be more specific about what sort of malformed result we're
checking here.
Something like "Mark the test as failed if it is not correctly numbered."
> + num = int(match.group(2))
> + if num != expected_num:
> + test.add_error(printer, f'Expected test number {expected_num} but found {num}')
> + test.status = TestStatus.FAILURE
> return True
>
> def parse_diagnostic(lines: LineStream) -> List[str]:
> diff --git a/tools/testing/kunit/kunit_tool_test.py b/tools/testing/kunit/kunit_tool_test.py
> index 5fd386d0..6a3011de 100755
> --- a/tools/testing/kunit/kunit_tool_test.py
> +++ b/tools/testing/kunit/kunit_tool_test.py
> @@ -410,13 +410,78 @@ class KUnitParserTest(unittest.TestCase):
> def test_parse_late_test_plan(self):
> output = """
> TAP version 13
> - ok 4 test4
> + ok 1 test1
> 1..4
> """
> result = kunit_parser.parse_run_tests(output.splitlines(), stdout)
> - # Missing test results after test plan should alert a suspected test crash.
> + # Keep this test focused on a late plan, not result numbering.
Let's keep the original comment: this one describes the _changes_ this
patch is making, but doesn't describe the purpose of the test any more.
> self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status)
> - self.assertEqual(result.counts, kunit_parser.TestCounts(passed=1, errors=2))
> + self.assertEqual(result.counts, kunit_parser.TestCounts(passed=1, errors=1))
> +
> + def test_wrong_first_number_fails(self):
> + output = ['KTAP version 1', '1..1', 'ok 4 - fourth']
Again, let's put this a separate result file. Or, if you must have it
inline, do it as a string (like the existing test_parse_late_test_plan()
example), as it's much easier to read and/or copy out into a separate
file for debugging.
> + result = kunit_parser.parse_run_tests(output, stdout)
> + self.assertEqual(kunit_parser.TestStatus.FAILURE, result.status)
> + self.assertEqual(result.counts, kunit_parser.TestCounts(failed=1, errors=1))
> +
> + def test_repeated_test_number_fails(self):
> + output = ['KTAP version 1', '1..2', 'ok 1 - first', 'ok 1 - second']
Let's make this a file (or at least a string), too.
> + result = kunit_parser.parse_run_tests(output, stdout)
> + self.assertEqual(kunit_parser.TestStatus.FAILURE, result.status)
> + self.assertEqual(result.counts,
> + kunit_parser.TestCounts(passed=1, failed=1, errors=1))
> +
> + def test_missing_number_fails_later_results(self):
> + output = ['KTAP version 1', '1..3',
> + 'ok 1 - first', 'ok 3 - third', 'ok 4 - fourth']
Ditto.
> + result = kunit_parser.parse_run_tests(output, stdout)
> + self.assertEqual(kunit_parser.TestStatus.FAILURE, result.status)
> + self.assertEqual(result.counts,
> + kunit_parser.TestCounts(passed=1, failed=2, errors=2))
> +
> + def test_wrong_numbered_skip_fails(self):
> + output = ['KTAP version 1', '1..1', 'ok 2 - skipped # SKIP reason']
Ditto.
> + result = kunit_parser.parse_run_tests(output, stdout)
> + self.assertEqual(kunit_parser.TestStatus.FAILURE, result.status)
> + self.assertEqual(result.counts, kunit_parser.TestCounts(failed=1, errors=1))
> +
> + def test_wrong_numbered_suite_result_fails(self):
> + output = ['KTAP version 1', '1..1',
> + ' KTAP version 1', ' # Subtest: suite', ' 1..1',
> + ' ok 1 - case', 'ok 2 - suite']
And again... :-)
> + result = kunit_parser.parse_run_tests(output, stdout)
> + suite = result.subtests[0]
> + self.assertEqual(kunit_parser.TestStatus.SUCCESS, suite.subtests[0].status)
> + self.assertEqual(kunit_parser.TestStatus.FAILURE, suite.status)
> + self.assertEqual(suite.counts,
> + kunit_parser.TestCounts(passed=1, failed=1, errors=1))
> + self.assertEqual(kunit_parser.TestStatus.FAILURE, result.status)
> + self.assertEqual(result.counts, suite.counts)
> +
> + def test_wrong_numbered_nested_case_fails(self):
> + output = ['KTAP version 1', '1..1',
> + ' KTAP version 1', ' # Subtest: suite', ' 1..1',
> + ' ok 2 - case', 'ok 1 - suite']
Ditto.
> + result = kunit_parser.parse_run_tests(output, stdout)
> + suite = result.subtests[0]
> + self.assertEqual(kunit_parser.TestStatus.FAILURE, suite.subtests[0].status)
> + self.assertEqual(suite.counts,
> + kunit_parser.TestCounts(failed=1, errors=1))
> + self.assertEqual(kunit_parser.TestStatus.FAILURE, result.status)
> + self.assertEqual(result.counts, suite.counts)
> +
> + def test_wrong_numbered_suite_with_skipped_child_fails(self):
> + output = ['KTAP version 1', '1..1',
> + ' KTAP version 1', ' # Subtest: suite', ' 1..1',
> + ' ok 1 - case # SKIP reason', 'ok 2 - suite']
Ditto.
> + result = kunit_parser.parse_run_tests(output, stdout)
> + suite = result.subtests[0]
> + self.assertEqual(kunit_parser.TestStatus.SKIPPED, suite.subtests[0].status)
> + self.assertEqual(kunit_parser.TestStatus.FAILURE, suite.status)
> + self.assertEqual(suite.counts,
> + kunit_parser.TestCounts(failed=1, skipped=1, errors=1))
> + self.assertEqual(kunit_parser.TestStatus.FAILURE, result.status)
> + self.assertEqual(result.counts, suite.counts)
>
> def line_stream_from_strs(strs: Iterable[str]) -> kunit_parser.LineStream:
> return kunit_parser.LineStream(enumerate(strs, start=1))
> @@ -797,6 +862,14 @@ class KUnitMainTest(unittest.TestCase):
> self.assertEqual(self.linux_source_mock.run_kernel.call_count, 1)
> self.print_mock.assert_any_call(StrContains('Could not find any KTAP output.'))
>
> + def test_parse_duplicate_number_exits_failure(self):
> + with tempfile.NamedTemporaryFile(mode='w+', delete=True) as log:
> + log.write('KTAP version 1\n1..2\nok 1 - first\nok 1 - second\n')
> + log.flush()
> + with self.assertRaises(SystemExit) as result:
> + kunit.main(['parse', log.name])
Couldn't this, too, be another file. Then we wouldn't need a complicated
NamedTemporaryFile thing at all.
That being said, I'm not sure we need to separately verify that this
causes a specific exit code given we're already testing that it gives
tests with TestStatus.FAILURE above, but if you think there's a
particularly good reason for it, I'm not absolutely set against it.
> + self.assertEqual(result.exception.code, 1)
> +
> def test_exec_no_tests(self):
> self.linux_source_mock.run_kernel = mock.Mock(return_value=['TAP version 14', '1..0'])
> with self.assertRaises(SystemExit) as e:
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-25 5:23 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-24 16:43 [PATCH v2 0/2] kunit: tool: Preserve failures in parsed KTAP results Louis H. Poulin II via B4 Relay
2026-11-24 16:43 ` [PATCH v2 1/2] kunit: tool: Count failed suites with only skipped tests Louis H. Poulin II via B4 Relay
2026-11-25 5:22 ` David Gow
2026-11-24 16:43 ` [PATCH v2 2/2] kunit: tool: Fail on out-of-sequence test numbers Louis H. Poulin II via B4 Relay
2026-11-25 5:22 ` David Gow
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®