lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Thu, 14 Sep 2023 21:51:41 +0000
From:   Rae Moar <rmoar@...gle.com>
To:     shuah@...nel.org, davidgow@...gle.com, dlatypov@...gle.com,
        brendan.higgins@...ux.dev
Cc:     linux-kselftest@...r.kernel.org, kunit-dev@...glegroups.com,
        linux-kernel@...r.kernel.org, Rae Moar <rmoar@...gle.com>
Subject: [PATCH 2/2] kunit: tool: add attributes output to kunit.py

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@...gle.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ