All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rae Moar <rmoar@google.com>
To: shuah@kernel.org, davidgow@google.com, dlatypov@google.com,
	brendan.higgins@linux.dev
Cc: linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com,
	linux-kernel@vger.kernel.org, Rae Moar <rmoar@google.com>
Subject: [PATCH 2/2] kunit: tool: add attributes output to kunit.py
Date: Thu, 14 Sep 2023 21:51:41 +0000	[thread overview]
Message-ID: <20230914215141.3399584-2-rmoar@google.com> (raw)
In-Reply-To: <20230914215141.3399584-1-rmoar@google.com>

Output attributes in kunit.py results.

Example of format:

[21:33:23] =================== example (7 subtests) ===================
[21:33:23] module: kunit_example_test
[21:33:23] [PASSED] example_simple_test
...
[21:33:23] [PASSED] example_slow_test
[21:33:23] speed: slow
[21:33:23] =================== [PASSED] example =======================

The attributes are outputted directly below the associated test.

Note that the attributes lines are saved in the log and then the log is
parsed for attributes rather than saving attributes in their own field.

This is due to diagnostic lines being saved prior to the creation of the
associated test object.

Signed-off-by: Rae Moar <rmoar@google.com>
---
 tools/testing/kunit/kunit_parser.py | 31 +++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/tools/testing/kunit/kunit_parser.py b/tools/testing/kunit/kunit_parser.py
index ce34be15c929..ffa9cfdcf5d6 100644
--- a/tools/testing/kunit/kunit_parser.py
+++ b/tools/testing/kunit/kunit_parser.py
@@ -509,6 +509,34 @@ def print_test_header(test: Test) -> None:
 			message += f'({test.expected_count} subtests)'
 	stdout.print_with_timestamp(format_test_divider(message, len(message)))
 
+TEST_HEADER_ATTR = re.compile(r'^\s*# (.*): (.*)$')
+TEST_ATTR = re.compile(r'^\s*# (.*)\.(.*): (.*)$')
+
+def print_test_attr(test: Test) -> None:
+	"""
+	Attributes, if present, will be printed in a list separated by
+	commas.
+
+	Example:
+	'module: example_test, speed: slow'
+
+	Parameters:
+	test - Test object representing current test being printed
+	"""
+	attr_list = ["module", "speed"]
+	output = []
+
+	for line in test.log:
+		test_match = TEST_ATTR.match(line)
+		header_match = TEST_HEADER_ATTR.match(line)
+		if test_match and (test_match.group(1) == test.name
+					  and (test_match.group(2) in attr_list)):
+			output.append(test_match.group(2) + ": " + test_match.group(3))
+		elif header_match and (header_match.group(1) in attr_list):
+			output.append(header_match.group(1) + ": " + header_match.group(2))
+	if output:
+		stdout.print_with_timestamp(", ".join(output))
+
 def print_log(log: Iterable[str]) -> None:
 	"""Prints all strings in saved log for test in yellow."""
 	formatted = textwrap.dedent('\n'.join(log))
@@ -741,6 +769,7 @@ def parse_test(lines: LineStream, expected_num: int, log: List[str], is_subtest:
 			test.log.extend(parse_diagnostic(lines))
 			parse_test_plan(lines, test)
 			print_test_header(test)
+			print_test_attr(test)
 	expected_count = test.expected_count
 	subtests = []
 	test_num = 1
@@ -763,6 +792,7 @@ def parse_test(lines: LineStream, expected_num: int, log: List[str], is_subtest:
 				test.counts.add_status(
 					TestStatus.TEST_CRASHED)
 				print_test_result(sub_test)
+				print_test_attr(sub_test)
 			else:
 				test.log.extend(sub_log)
 				break
@@ -796,6 +826,7 @@ def parse_test(lines: LineStream, expected_num: int, log: List[str], is_subtest:
 		print_test_footer(test)
 	elif is_subtest:
 		print_test_result(test)
+		print_test_attr(test)
 	return test
 
 def parse_run_tests(kernel_output: Iterable[str]) -> Test:
-- 
2.42.0.459.ge4e396fd5e-goog


      reply	other threads:[~2023-09-14 21:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-14 21:51 [PATCH 1/2] kunit: tool: add parsing of test attributes Rae Moar
2023-09-14 21:51 ` Rae Moar [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230914215141.3399584-2-rmoar@google.com \
    --to=rmoar@google.com \
    --cc=brendan.higgins@linux.dev \
    --cc=davidgow@google.com \
    --cc=dlatypov@google.com \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.