* [PATCH] kunit: tool: Preserve suite ancestry in JUnit test identities
@ 2026-11-14 9:17 Matus Daniil
2026-11-26 12:58 ` David Gow
2026-11-26 15:34 ` [PATCH RESEND v2] " Daniil Matus via B4 Relay
0 siblings, 2 replies; 3+ messages in thread
From: Matus Daniil @ 2026-11-14 9:17 UTC (permalink / raw)
To: Brendan Higgins, David Gow
Cc: Rae Moar, Shuah Khan, Thomas Weißschuh, linux-kselftest,
kunit-dev, linux-kernel
From: Daniil Matus <matus.daniil@mail.ru>
JUnit testcases currently carry only a name. A parameterized KUnit test
becomes a nested testsuite named after the test function. Reusing that
function in several outer suites therefore produces the same immediate
suite name and parameter name in each of them.
For example, cs_dsp_test_run_stop_callbacks is registered in four cs_dsp
callback suites with the same "all ops" parameter. GitLab identifies cases
by suite name, classname and testcase name. Without a classname, these
distinct cases have identical keys in the imported report.
Set classname to the dot-separated ancestor suite names, including the
parser's main root. Preserve the existing suite hierarchy, testcase names,
statuses and logs. Add a regression using the existing nested log fixture,
whose seven testcases otherwise have only five distinct identity tuples.
Validation: all 92 kunit_tool_test.py tests pass. The new regression fails
on the unmodified generator. Comparing all 24 log fixtures shows no XML
changes other than the added classname attributes.
Fixes: e9e05c72752f ("kunit: tool: Add (primitive) support for
outputting JUnit XML")
Signed-off-by: Daniil Matus <matus.daniil@mail.ru>
---
tools/testing/kunit/kunit_junit.py | 10 +++++++---
tools/testing/kunit/kunit_tool_test.py | 14 ++++++++++++++
2 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/tools/testing/kunit/kunit_junit.py
b/tools/testing/kunit/kunit_junit.py
index 362207035..d5730aebe 100644
--- a/tools/testing/kunit/kunit_junit.py
+++ b/tools/testing/kunit/kunit_junit.py
@@ -10,7 +10,8 @@ from kunit_parser import Test, TestStatus
from typing import Optional
# Get a string representing a tes suite (including subtests) in JUnit XML
-def get_test_suite(test: Test, parent: Optional[ET.Element]) -> ET.Element:
+def get_test_suite(test: Test, parent: Optional[ET.Element],
name_prefix: str = '') -> ET.Element:
+ classname = f'{name_prefix}.{test.name}' if name_prefix else test.name
suite_attrs = {
'name': test.name,
'tests': str(test.counts.total()),
@@ -26,9 +27,12 @@ def get_test_suite(test: Test, parent:
Optional[ET.Element]) -> ET.Element:
for subtest in test.subtests:
if subtest.subtests:
- get_test_suite(subtest, test_suite_element)
+ get_test_suite(subtest, test_suite_element, classname)
continue
- test_case_element = ET.SubElement(test_suite_element, 'testcase',
{'name': subtest.name})
+ test_case_element = ET.SubElement(test_suite_element, 'testcase', {
+ 'name': subtest.name,
+ 'classname': classname,
+ })
if subtest.status == TestStatus.FAILURE:
ET.SubElement(test_case_element, 'failure', {}).text = 'Test Failed'
elif subtest.status == TestStatus.SKIPPED:
diff --git a/tools/testing/kunit/kunit_tool_test.py
b/tools/testing/kunit/kunit_tool_test.py
index 85ae21754..d37354c70 100755
--- a/tools/testing/kunit/kunit_tool_test.py
+++ b/tools/testing/kunit/kunit_tool_test.py
@@ -18,6 +18,7 @@ import os
import signal
import subprocess
import sys
+import xml.etree.ElementTree as ET
from typing import Iterable
import kunit_config
@@ -725,6 +726,19 @@ class KUnitJUnitTest(unittest.TestCase):
self.assertTrue("tests=\"0\"" in result)
self.assertFalse("testcase" in result)
+ def test_nested_test_classnames_junit(self):
+ result = self._junit_string('test_is_test_passed-all_passed_nested.log')
+ testcases = ET.fromstring(result).iter('testcase')
+ self.assertEqual([
+ ('main.sysctl_test', 'sysctl_test_dointvec_null_tbl_data'),
+ ('main.sysctl_test.example', 'example_simple_test'),
+ ('main.sysctl_test.example', 'example_mock_test'),
+ ('main.sysctl_test', 'sysctl_test_dointvec_table_len_is_zero'),
+ ('main.sysctl_test', 'sysctl_test_dointvec_table_read_but_position_set'),
+ ('main.example', 'example_simple_test'),
+ ('main.example', 'example_mock_test'),
+ ], [(case.get('classname'), case.get('name')) for case in testcases])
+
class KUnitMainTest(unittest.TestCase):
def setUp(self):
base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] kunit: tool: Preserve suite ancestry in JUnit test identities
2026-11-14 9:17 [PATCH] kunit: tool: Preserve suite ancestry in JUnit test identities Matus Daniil
@ 2026-11-26 12:58 ` David Gow
2026-11-26 15:34 ` [PATCH RESEND v2] " Daniil Matus via B4 Relay
1 sibling, 0 replies; 3+ messages in thread
From: David Gow @ 2026-11-26 12:58 UTC (permalink / raw)
To: Matus Daniil, Brendan Higgins
Cc: Rae Moar, Shuah Khan, Thomas Weißschuh, linux-kselftest,
kunit-dev, linux-kernel
Le 14/11/2026 à 17:17, Matus Daniil a écrit :
> From: Daniil Matus <matus.daniil@mail.ru>
>
> JUnit testcases currently carry only a name. A parameterized KUnit test
> becomes a nested testsuite named after the test function. Reusing that
> function in several outer suites therefore produces the same immediate
> suite name and parameter name in each of them.
>
> For example, cs_dsp_test_run_stop_callbacks is registered in four cs_dsp
> callback suites with the same "all ops" parameter. GitLab identifies cases
> by suite name, classname and testcase name. Without a classname, these
> distinct cases have identical keys in the imported report.
>
> Set classname to the dot-separated ancestor suite names, including the
> parser's main root. Preserve the existing suite hierarchy, testcase names,
> statuses and logs. Add a regression using the existing nested log fixture,
> whose seven testcases otherwise have only five distinct identity tuples.
>
> Validation: all 92 kunit_tool_test.py tests pass. The new regression fails
> on the unmodified generator. Comparing all 24 log fixtures shows no XML
> changes other than the added classname attributes.
>
> Fixes: e9e05c72752f ("kunit: tool: Add (primitive) support for
> outputting JUnit XML")
> Signed-off-by: Daniil Matus <matus.daniil@mail.ru>
> ---
Hi,
Thanks very much for your patch.
Unfortunately, it looks like your email client has mangled it somewhat:
some of the lines have been wrapped.
This is a known issue with some email programs: particularly with gmail.
The file Documentation/process/email-clients.rst has some details about
different clients:
https://docs.kernel.org/process/email-clients.html
But I'd personally recommend either using git send-email:
- https://git-send-email.io
or the b4 tool:
- https://b4.docs.kernel.org/en/latest/
Those will ensure that the patch will be sent properly, so that
maintainers can use git to apply it automatically. I personally use git
send-email for my patches, and once it's set up, it works great.
Cheers,
-- David
> tools/testing/kunit/kunit_junit.py | 10 +++++++---
> tools/testing/kunit/kunit_tool_test.py | 14 ++++++++++++++
> 2 files changed, 21 insertions(+), 3 deletions(-)
>
> diff --git a/tools/testing/kunit/kunit_junit.py
> b/tools/testing/kunit/kunit_junit.py
> index 362207035..d5730aebe 100644
> --- a/tools/testing/kunit/kunit_junit.py
> +++ b/tools/testing/kunit/kunit_junit.py
> @@ -10,7 +10,8 @@ from kunit_parser import Test, TestStatus
> from typing import Optional
>
> # Get a string representing a tes suite (including subtests) in JUnit XML
> -def get_test_suite(test: Test, parent: Optional[ET.Element]) -> ET.Element:
> +def get_test_suite(test: Test, parent: Optional[ET.Element],
> name_prefix: str = '') -> ET.Element:
> + classname = f'{name_prefix}.{test.name}' if name_prefix else test.name
> suite_attrs = {
> 'name': test.name,
> 'tests': str(test.counts.total()),
> @@ -26,9 +27,12 @@ def get_test_suite(test: Test, parent:
> Optional[ET.Element]) -> ET.Element:
>
> for subtest in test.subtests:
> if subtest.subtests:
> - get_test_suite(subtest, test_suite_element)
> + get_test_suite(subtest, test_suite_element, classname)
> continue
> - test_case_element = ET.SubElement(test_suite_element, 'testcase',
> {'name': subtest.name})
> + test_case_element = ET.SubElement(test_suite_element, 'testcase', {
> + 'name': subtest.name,
> + 'classname': classname,
> + })
> if subtest.status == TestStatus.FAILURE:
> ET.SubElement(test_case_element, 'failure', {}).text = 'Test Failed'
> elif subtest.status == TestStatus.SKIPPED:
> diff --git a/tools/testing/kunit/kunit_tool_test.py
> b/tools/testing/kunit/kunit_tool_test.py
> index 85ae21754..d37354c70 100755
> --- a/tools/testing/kunit/kunit_tool_test.py
> +++ b/tools/testing/kunit/kunit_tool_test.py
> @@ -18,6 +18,7 @@ import os
> import signal
> import subprocess
> import sys
> +import xml.etree.ElementTree as ET
> from typing import Iterable
>
> import kunit_config
> @@ -725,6 +726,19 @@ class KUnitJUnitTest(unittest.TestCase):
> self.assertTrue("tests=\"0\"" in result)
> self.assertFalse("testcase" in result)
>
> + def test_nested_test_classnames_junit(self):
> + result = self._junit_string('test_is_test_passed-all_passed_nested.log')
> + testcases = ET.fromstring(result).iter('testcase')
> + self.assertEqual([
> + ('main.sysctl_test', 'sysctl_test_dointvec_null_tbl_data'),
> + ('main.sysctl_test.example', 'example_simple_test'),
> + ('main.sysctl_test.example', 'example_mock_test'),
> + ('main.sysctl_test', 'sysctl_test_dointvec_table_len_is_zero'),
> + ('main.sysctl_test', 'sysctl_test_dointvec_table_read_but_position_set'),
> + ('main.example', 'example_simple_test'),
> + ('main.example', 'example_mock_test'),
> + ], [(case.get('classname'), case.get('name')) for case in testcases])
> +
>
> class KUnitMainTest(unittest.TestCase):
> def setUp(self):
>
> base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH RESEND v2] kunit: tool: Preserve suite ancestry in JUnit test identities
2026-11-14 9:17 [PATCH] kunit: tool: Preserve suite ancestry in JUnit test identities Matus Daniil
2026-11-26 12:58 ` David Gow
@ 2026-11-26 15:34 ` Daniil Matus via B4 Relay
1 sibling, 0 replies; 3+ messages in thread
From: Daniil Matus via B4 Relay @ 2026-11-26 15:34 UTC (permalink / raw)
To: David Gow, Brendan Higgins
Cc: Thomas Weißschuh, Rae Moar, kunit-dev, Shuah Khan,
linux-kernel, linux-kselftest
From: Daniil Matus <matus.daniil@mail.ru>
JUnit testcases currently carry only a name. A parameterized KUnit test
becomes a nested testsuite named after the test function. Reusing that
function in several outer suites therefore produces the same immediate
suite name and parameter name in each of them.
For example, cs_dsp_test_run_stop_callbacks is registered in four cs_dsp
callback suites with the same "all ops" parameter. GitLab identifies cases
by suite name, classname and testcase name. Without a classname, these
distinct cases have identical keys in the imported report.
Set classname to the dot-separated ancestor suite names, including the
parser's main root. Preserve the existing suite hierarchy, testcase names,
statuses and logs. Add a regression using the existing nested log fixture,
whose seven testcases otherwise have only five distinct identity tuples.
Validation: all 92 kunit_tool_test.py tests pass. The new regression fails
on the unmodified generator. Comparing all 24 log fixtures shows no XML
changes other than the added classname attributes.
Fixes: e9e05c72752f ("kunit: tool: Add (primitive) support for outputting JUnit XML")
Signed-off-by: Daniil Matus <matus.daniil@mail.ru>
---
The first posting wrapped several diff lines in transit. This resend uses
b4 as David suggested. The code and commit message are unchanged.
---
tools/testing/kunit/kunit_junit.py | 10 +++++++---
tools/testing/kunit/kunit_tool_test.py | 14 ++++++++++++++
2 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/tools/testing/kunit/kunit_junit.py b/tools/testing/kunit/kunit_junit.py
index 362207035..d5730aebe 100644
--- a/tools/testing/kunit/kunit_junit.py
+++ b/tools/testing/kunit/kunit_junit.py
@@ -10,7 +10,8 @@ from kunit_parser import Test, TestStatus
from typing import Optional
# Get a string representing a tes suite (including subtests) in JUnit XML
-def get_test_suite(test: Test, parent: Optional[ET.Element]) -> ET.Element:
+def get_test_suite(test: Test, parent: Optional[ET.Element], name_prefix: str = '') -> ET.Element:
+ classname = f'{name_prefix}.{test.name}' if name_prefix else test.name
suite_attrs = {
'name': test.name,
'tests': str(test.counts.total()),
@@ -26,9 +27,12 @@ def get_test_suite(test: Test, parent: Optional[ET.Element]) -> ET.Element:
for subtest in test.subtests:
if subtest.subtests:
- get_test_suite(subtest, test_suite_element)
+ get_test_suite(subtest, test_suite_element, classname)
continue
- test_case_element = ET.SubElement(test_suite_element, 'testcase', {'name': subtest.name})
+ test_case_element = ET.SubElement(test_suite_element, 'testcase', {
+ 'name': subtest.name,
+ 'classname': classname,
+ })
if subtest.status == TestStatus.FAILURE:
ET.SubElement(test_case_element, 'failure', {}).text = 'Test Failed'
elif subtest.status == TestStatus.SKIPPED:
diff --git a/tools/testing/kunit/kunit_tool_test.py b/tools/testing/kunit/kunit_tool_test.py
index 85ae21754..d37354c70 100755
--- a/tools/testing/kunit/kunit_tool_test.py
+++ b/tools/testing/kunit/kunit_tool_test.py
@@ -18,6 +18,7 @@ import os
import signal
import subprocess
import sys
+import xml.etree.ElementTree as ET
from typing import Iterable
import kunit_config
@@ -725,6 +726,19 @@ class KUnitJUnitTest(unittest.TestCase):
self.assertTrue("tests=\"0\"" in result)
self.assertFalse("testcase" in result)
+ def test_nested_test_classnames_junit(self):
+ result = self._junit_string('test_is_test_passed-all_passed_nested.log')
+ testcases = ET.fromstring(result).iter('testcase')
+ self.assertEqual([
+ ('main.sysctl_test', 'sysctl_test_dointvec_null_tbl_data'),
+ ('main.sysctl_test.example', 'example_simple_test'),
+ ('main.sysctl_test.example', 'example_mock_test'),
+ ('main.sysctl_test', 'sysctl_test_dointvec_table_len_is_zero'),
+ ('main.sysctl_test', 'sysctl_test_dointvec_table_read_but_position_set'),
+ ('main.example', 'example_simple_test'),
+ ('main.example', 'example_mock_test'),
+ ], [(case.get('classname'), case.get('name')) for case in testcases])
+
class KUnitMainTest(unittest.TestCase):
def setUp(self):
---
base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa
change-id: 20261126-kunit-junit-classname-resend-560a1f9ac2c1
Best regards,
--
Daniil Matus <matus.daniil@gmail.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-26 15:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-14 9:17 [PATCH] kunit: tool: Preserve suite ancestry in JUnit test identities Matus Daniil
2026-11-26 12:58 ` David Gow
2026-11-26 15:34 ` [PATCH RESEND v2] " Daniil Matus via B4 Relay
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®