mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] kunit: tool: fix parsing of test attributes
@ 2023-12-05 20:38 Rae Moar
  2023-12-06  8:30 ` David Gow
  0 siblings, 1 reply; 2+ messages in thread
From: Rae Moar @ 2023-12-05 20:38 UTC (permalink / raw)
  To: shuah, davidgow, dlatypov, brendan.higgins
  Cc: linux-kselftest, kunit-dev, linux-kernel, Rae Moar

Add parsing of attributes as diagnostic data. Fixes issue with test plan
being parsed incorrectly as diagnostic data when located after
suite-level attributes.

Note that if there does not exist a test plan line, the diagnostic lines
between the suite header and the first result will be saved in the suite
log rather than the first test case log.

Signed-off-by: Rae Moar <rmoar@google.com>
---

Note this patch is a resend but I removed the second patch in the series
so now it is a standalone patch.

 tools/testing/kunit/kunit_parser.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/testing/kunit/kunit_parser.py b/tools/testing/kunit/kunit_parser.py
index 79d8832c862a..ce34be15c929 100644
--- a/tools/testing/kunit/kunit_parser.py
+++ b/tools/testing/kunit/kunit_parser.py
@@ -450,7 +450,7 @@ def parse_diagnostic(lines: LineStream) -> List[str]:
 	Log of diagnostic lines
 	"""
 	log = []  # type: List[str]
-	non_diagnostic_lines = [TEST_RESULT, TEST_HEADER, KTAP_START, TAP_START]
+	non_diagnostic_lines = [TEST_RESULT, TEST_HEADER, KTAP_START, TAP_START, TEST_PLAN]
 	while lines and not any(re.match(lines.peek())
 			for re in non_diagnostic_lines):
 		log.append(lines.pop())
@@ -726,6 +726,7 @@ def parse_test(lines: LineStream, expected_num: int, log: List[str], is_subtest:
 		# test plan
 		test.name = "main"
 		ktap_line = parse_ktap_header(lines, test)
+		test.log.extend(parse_diagnostic(lines))
 		parse_test_plan(lines, test)
 		parent_test = True
 	else:
@@ -737,6 +738,7 @@ def parse_test(lines: LineStream, expected_num: int, log: List[str], is_subtest:
 		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)
 	expected_count = test.expected_count

base-commit: b85ea95d086471afb4ad062012a4d73cd328fa86
-- 
2.43.0.rc2.451.g8631bc7472-goog


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] kunit: tool: fix parsing of test attributes
  2023-12-05 20:38 [PATCH] kunit: tool: fix parsing of test attributes Rae Moar
@ 2023-12-06  8:30 ` David Gow
  0 siblings, 0 replies; 2+ messages in thread
From: David Gow @ 2023-12-06  8:30 UTC (permalink / raw)
  To: Rae Moar
  Cc: shuah, dlatypov, brendan.higgins, linux-kselftest, kunit-dev,
	linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2706 bytes --]

On Wed, 6 Dec 2023 at 04:39, Rae Moar <rmoar@google.com> wrote:
>
> Add parsing of attributes as diagnostic data. Fixes issue with test plan
> being parsed incorrectly as diagnostic data when located after
> suite-level attributes.
>
> Note that if there does not exist a test plan line, the diagnostic lines
> between the suite header and the first result will be saved in the suite
> log rather than the first test case log.
>
> Signed-off-by: Rae Moar <rmoar@google.com>
> ---

This seems sensible to me, though I'd love to have a test to go along
with it (or at least an example input which shows the problem).

Indeed, none of the logs in tools/testing/kunit/test_output/ seem to
have any KTAP metadata / attributes, so we probably should test that
better.

-- David

>
> Note this patch is a resend but I removed the second patch in the series
> so now it is a standalone patch.
>
>  tools/testing/kunit/kunit_parser.py | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/kunit/kunit_parser.py b/tools/testing/kunit/kunit_parser.py
> index 79d8832c862a..ce34be15c929 100644
> --- a/tools/testing/kunit/kunit_parser.py
> +++ b/tools/testing/kunit/kunit_parser.py
> @@ -450,7 +450,7 @@ def parse_diagnostic(lines: LineStream) -> List[str]:
>         Log of diagnostic lines
>         """
>         log = []  # type: List[str]
> -       non_diagnostic_lines = [TEST_RESULT, TEST_HEADER, KTAP_START, TAP_START]
> +       non_diagnostic_lines = [TEST_RESULT, TEST_HEADER, KTAP_START, TAP_START, TEST_PLAN]
>         while lines and not any(re.match(lines.peek())
>                         for re in non_diagnostic_lines):
>                 log.append(lines.pop())
> @@ -726,6 +726,7 @@ def parse_test(lines: LineStream, expected_num: int, log: List[str], is_subtest:
>                 # test plan
>                 test.name = "main"
>                 ktap_line = parse_ktap_header(lines, test)
> +               test.log.extend(parse_diagnostic(lines))
>                 parse_test_plan(lines, test)
>                 parent_test = True
>         else:
> @@ -737,6 +738,7 @@ def parse_test(lines: LineStream, expected_num: int, log: List[str], is_subtest:
>                 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)
>         expected_count = test.expected_count
>
> base-commit: b85ea95d086471afb4ad062012a4d73cd328fa86
> --
> 2.43.0.rc2.451.g8631bc7472-goog
>

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4003 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-12-06  8:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-05 20:38 [PATCH] kunit: tool: fix parsing of test attributes Rae Moar
2023-12-06  8:30 ` 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®