Skip to content

Commit

Permalink
kunit: tool: Fix bug in parsing test plan
Browse files Browse the repository at this point in the history
A bug was identified where the KTAP below caused an infinite loop:

 TAP version 13
 ok 4 test_case
 1..4

The infinite loop was caused by the parser not parsing a test plan
if following a test result line.

Fix this bug by parsing test plan line to avoid the infinite loop.

Link: https://lore.kernel.org/r/20250313192714.1380005-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>
  • Loading branch information
Rae Moar authored and Shuah Khan committed Mar 16, 2025
1 parent c104c16 commit 1d4c06d
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions tools/testing/kunit/kunit_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ def parse_test(lines: LineStream, expected_num: int, log: List[str], is_subtest:
# If parsing the main/top-level test, parse KTAP version line and
# test plan
test.name = "main"
ktap_line = parse_ktap_header(lines, test, printer)
parse_ktap_header(lines, test, printer)
test.log.extend(parse_diagnostic(lines))
parse_test_plan(lines, test)
parent_test = True
Expand All @@ -768,13 +768,12 @@ def parse_test(lines: LineStream, expected_num: int, log: List[str], is_subtest:
# the KTAP version line and/or subtest header line
ktap_line = parse_ktap_header(lines, test, printer)
subtest_line = parse_test_header(lines, test)
test.log.extend(parse_diagnostic(lines))
parse_test_plan(lines, test)
parent_test = (ktap_line or subtest_line)
if parent_test:
# If KTAP version line and/or subtest header is found, attempt
# to parse test plan and print test header
test.log.extend(parse_diagnostic(lines))
parse_test_plan(lines, test)
print_test_header(test, printer)

expected_count = test.expected_count
subtests = []
test_num = 1
Expand Down

0 comments on commit 1d4c06d

Please sign in to comment.