* [PATCH v2] kunit: tool: Fix bug in parsing test plan
@ 2025-03-06 18:20 Rae Moar
2025-03-07 9:54 ` Brendan Jackman
2025-03-08 8:12 ` David Gow
0 siblings, 2 replies; 3+ messages in thread
From: Rae Moar @ 2025-03-06 18:20 UTC (permalink / raw)
To: shuah, davidgow, jackmanb
Cc: linux-kselftest, kunit-dev, linux-kernel, Rae Moar
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 to correctly parse test plan line.
Signed-off-by: Rae Moar <rmoar@google.com>
---
Changes since v1:
- Remove error reported when test plan is missing.
tools/testing/kunit/kunit_parser.py | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/tools/testing/kunit/kunit_parser.py b/tools/testing/kunit/kunit_parser.py
index 29fc27e8949b..da53a709773a 100644
--- a/tools/testing/kunit/kunit_parser.py
+++ b/tools/testing/kunit/kunit_parser.py
@@ -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
@@ -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
base-commit: 0619a4868fc1b32b07fb9ed6c69adc5e5cf4e4b2
--
2.49.0.rc0.332.g42c0ae87b1-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] kunit: tool: Fix bug in parsing test plan
2025-03-06 18:20 [PATCH v2] kunit: tool: Fix bug in parsing test plan Rae Moar
@ 2025-03-07 9:54 ` Brendan Jackman
2025-03-08 8:12 ` David Gow
1 sibling, 0 replies; 3+ messages in thread
From: Brendan Jackman @ 2025-03-07 9:54 UTC (permalink / raw)
To: Rae Moar; +Cc: shuah, davidgow, linux-kselftest, kunit-dev, linux-kernel
On Thu, 6 Mar 2025 at 19:20, Rae Moar <rmoar@google.com> wrote:
>
> 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 to correctly parse test plan line.
>
> Signed-off-by: Rae Moar <rmoar@google.com>
Hi Rae thanks again for taking a look at this. I just noticed
kunit_tool_test.py has unit tests for the parsing logic. Maybe worth
adding one for the case that was infinite looping before?
(I am not really able to offer an actual review as I couldn't really
understand the parsing code after a quick reading, but if you need it
then let me know and I'll chase you up to ask questions until I can
follow it, then I can review!)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] kunit: tool: Fix bug in parsing test plan
2025-03-06 18:20 [PATCH v2] kunit: tool: Fix bug in parsing test plan Rae Moar
2025-03-07 9:54 ` Brendan Jackman
@ 2025-03-08 8:12 ` David Gow
1 sibling, 0 replies; 3+ messages in thread
From: David Gow @ 2025-03-08 8:12 UTC (permalink / raw)
To: Rae Moar; +Cc: shuah, jackmanb, linux-kselftest, kunit-dev, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 2556 bytes --]
On Fri, 7 Mar 2025 at 02:20, Rae Moar <rmoar@google.com> wrote:
>
> 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 to correctly parse test plan line.
>
> Signed-off-by: Rae Moar <rmoar@google.com>
> ---
Looks good. I agree with Brendan that this probably should have a
test, but I'm happy to take that as a follow-up if you prefer.
Reviewed-by: David Gow <davidgow@google.com>
Cheers,
-- David
> Changes since v1:
> - Remove error reported when test plan is missing.
>
> tools/testing/kunit/kunit_parser.py | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/tools/testing/kunit/kunit_parser.py b/tools/testing/kunit/kunit_parser.py
> index 29fc27e8949b..da53a709773a 100644
> --- a/tools/testing/kunit/kunit_parser.py
> +++ b/tools/testing/kunit/kunit_parser.py
> @@ -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
> @@ -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
>
> base-commit: 0619a4868fc1b32b07fb9ed6c69adc5e5cf4e4b2
> --
> 2.49.0.rc0.332.g42c0ae87b1-goog
>
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 5281 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-03-08 8:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-06 18:20 [PATCH v2] kunit: tool: Fix bug in parsing test plan Rae Moar
2025-03-07 9:54 ` Brendan Jackman
2025-03-08 8:12 ` David Gow
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox