[PATCH] kunit: tool: fix _list_tests filtering wrong variable when list has TAP prefix

3 views
Skip to first unread message

mohammad....@hotmail.com

unread,
Jul 29, 2026, 12:19:50 PMJul 29
to brendan...@linux.dev, da...@davidgow.net, raem...@gmail.com, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org
From: Mohammad Abu-Khader <mohammad....@hotmail.com>

`_list_tests()` runs the kernel to list tests, strips printk timestamp
lines via `extract_tap_lines()`, then drops the dummy TAP header from
the cleaned `lines`. However the subsequent regex filter mistakenly
operates on the original `output` instead of the cleaned `lines`. When
the kernel output includes timestamp prefixes (common with UML or slower
setups), e.g.:

[ 0.100000] suite.test1
[ 0.100000] suite.test2

the anchored regex `^[^\s.]+\.[^\s.]+$` rejects them and `--list_tests`
returns an empty list.

Filter `lines` instead of `output`, matching the behavior of the
adjacent `_list_tests_attr()` which already returns the cleaned list.

Add a regression test with timestamp-prefixed input to verify the fix.

Fixes: 723c8258c8fe ("kunit: tool: Add command line interface to filter and report attributes")
---
tools/testing/kunit/kunit.py | 2 +-
tools/testing/kunit/kunit_tool_test.py | 12 ++++++++++++
2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/tools/testing/kunit/kunit.py b/tools/testing/kunit/kunit.py
index ac3f7159e67f..91d234ac3b57 100755
--- a/tools/testing/kunit/kunit.py
+++ b/tools/testing/kunit/kunit.py
@@ -126,7 +126,7 @@ def _list_tests(linux: kunit_kernel.LinuxSourceTree, request: KunitExecRequest)
lines.pop()

# Filter out any extraneous non-test output that might have gotten mixed in.
- return [l for l in output if re.match(r'^[^\s.]+\.[^\s.]+$', l)]
+ return [l for l in lines if re.match(r'^[^\s.]+\.[^\s.]+$', l)]

def _list_tests_attr(linux: kunit_kernel.LinuxSourceTree, request: KunitExecRequest) -> Iterable[str]:
args = ['kunit.action=list_attr']
diff --git a/tools/testing/kunit/kunit_tool_test.py b/tools/testing/kunit/kunit_tool_test.py
index da88c3a1651d..85ae21754bdf 100755
--- a/tools/testing/kunit/kunit_tool_test.py
+++ b/tools/testing/kunit/kunit_tool_test.py
@@ -979,6 +979,18 @@ class KUnitMainTest(unittest.TestCase):
self.linux_source_mock.run_kernel.assert_called_once_with(
args=['kunit.action=list'], build_dir='.kunit', filter_glob='suite*', filter='', filter_action=None, timeout=300)

+ def test_list_tests_with_prefix(self):
+ want = ['suite.test1', 'suite.test2', 'suite2.test1']
+ self.linux_source_mock.run_kernel.return_value = [
+ '[ 0.100000] TAP version 14',
+ '[ 0.200000] suite.test1',
+ '[ 0.200000] suite.test2',
+ '[ 0.300000] suite2.test1']
+
+ got = kunit._list_tests(self.linux_source_mock,
+ kunit.KunitExecRequest(None, None, None, False, False, '.kunit', 300, 'suite*', '', None, None, 'suite', False, False, False))
+ self.assertEqual(got, want)
+
@mock.patch.object(kunit, '_list_tests')
def test_run_isolated_by_suite(self, mock_tests):
mock_tests.return_value = ['suite.test1', 'suite.test2', 'suite2.test1']
--
2.55.0

David Gow

unread,
Jul 30, 2026, 8:12:13 AMJul 30
to mohammad....@hotmail.com, brendan...@linux.dev, raem...@gmail.com, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org
Le 30/07/2026 à 12:19 AM, mohammad....@hotmail.com a écrit :
> From: Mohammad Abu-Khader <mohammad....@hotmail.com>
>
> `_list_tests()` runs the kernel to list tests, strips printk timestamp
> lines via `extract_tap_lines()`, then drops the dummy TAP header from
> the cleaned `lines`. However the subsequent regex filter mistakenly
> operates on the original `output` instead of the cleaned `lines`. When
> the kernel output includes timestamp prefixes (common with UML or slower
> setups), e.g.:
>
> [ 0.100000] suite.test1
> [ 0.100000] suite.test2
>
> the anchored regex `^[^\s.]+\.[^\s.]+$` rejects them and `--list_tests`
> returns an empty list.
>
> Filter `lines` instead of `output`, matching the behavior of the
> adjacent `_list_tests_attr()` which already returns the cleaned list.
>
> Add a regression test with timestamp-prefixed input to verify the fix.
>
> Fixes: 723c8258c8fe ("kunit: tool: Add command line interface to filter and report attributes")
> ---

Thanks: nice catch. I rarely run with CONFIG_PRINTK_TIME=y, so didn't
notice.

Reviewed-by: David Gow <da...@davidgow.net>

Cheers,
-- David

Shuah Khan

unread,
Aug 3, 2026, 11:56:11 AM (13 days ago) Aug 3
to David Gow, mohammad....@hotmail.com, brendan...@linux.dev, raem...@gmail.com, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org, Shuah Khan
On 7/30/26 06:12, David Gow wrote:
> Le 30/07/2026 à 12:19 AM, mohammad....@hotmail.com a écrit :
>> From: Mohammad Abu-Khader <mohammad....@hotmail.com>
>>
>> `_list_tests()` runs the kernel to list tests, strips printk timestamp
>> lines via `extract_tap_lines()`, then drops the dummy TAP header from
>> the cleaned `lines`. However the subsequent regex filter mistakenly
>> operates on the original `output` instead of the cleaned `lines`. When
>> the kernel output includes timestamp prefixes (common with UML or slower
>> setups), e.g.:
>>
>> [ 0.100000] suite.test1
>> [ 0.100000] suite.test2
>>
>> the anchored regex `^[^\s.]+\.[^\s.]+$` rejects them and `--list_tests`
>> returns an empty list.
>>
>> Filter `lines` instead of `output`, matching the behavior of the
>> adjacent `_list_tests_attr()` which already returns the cleaned list.
>>
>> Add a regression test with timestamp-prefixed input to verify the fix.
>>
>> Fixes: 723c8258c8fe ("kunit: tool: Add command line interface to filter and report attributes")

Missing Signed-off-by

Unfortunately I can't apply this patch. Please fix it and resend.
I will try my best to get this into Linux 7.2

thanks,
-- Shuah

Mohammad abukhader

unread,
Aug 3, 2026, 3:02:21 PM (13 days ago) Aug 3
to brendan...@linux.dev, da...@davidgow.net, raem...@gmail.com, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org
From: Mohammad Abu-Khader <mohammad....@hotmail.com>

`_list_tests()` runs the kernel to list tests, strips printk timestamp
lines via `extract_tap_lines()`, then drops the dummy TAP header from
the cleaned `lines`. However the subsequent regex filter mistakenly
operates on the original `output` instead of the cleaned `lines`. When
the kernel output includes timestamp prefixes (common with UML or slower
setups), e.g.:

[ 0.100000] suite.test1
[ 0.100000] suite.test2

the anchored regex `^[^\s.]+\.[^\s.]+$` rejects them and `--list_tests`
returns an empty list.

Filter `lines` instead of `output`, matching the behavior of the
adjacent `_list_tests_attr()` which already returns the cleaned list.

Add a regression test with timestamp-prefixed input to verify the fix.

Fixes: 723c8258c8fe ("kunit: tool: Add command line interface to filter and report attributes")

Signed-off-by: Mohammad Abu-Khader <mohammad....@hotmail.com>
---

--
2.55.0

David Gow

unread,
Aug 12, 2026, 10:37:02 AM (4 days ago) Aug 12
to Mohammad abukhader, brendan...@linux.dev, raem...@gmail.com, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org
Le 04/08/2026 à 3:02 AM, Mohammad abukhader a écrit :
> From: Mohammad Abu-Khader <mohammad....@hotmail.com>
>
> `_list_tests()` runs the kernel to list tests, strips printk timestamp
> lines via `extract_tap_lines()`, then drops the dummy TAP header from
> the cleaned `lines`. However the subsequent regex filter mistakenly
> operates on the original `output` instead of the cleaned `lines`. When
> the kernel output includes timestamp prefixes (common with UML or slower
> setups), e.g.:
>
> [ 0.100000] suite.test1
> [ 0.100000] suite.test2
>
> the anchored regex `^[^\s.]+\.[^\s.]+$` rejects them and `--list_tests`
> returns an empty list.
>
> Filter `lines` instead of `output`, matching the behavior of the
> adjacent `_list_tests_attr()` which already returns the cleaned list.
>
> Add a regression test with timestamp-prefixed input to verify the fix.
>
> Fixes: 723c8258c8fe ("kunit: tool: Add command line interface to filter and report attributes")
> Signed-off-by: Mohammad Abu-Khader <mohammad....@hotmail.com>
> ---

Reviewed-by: David Gow <da...@davidgow.net>

Cheers,
-- David

Reply all
Reply to author
Forward
0 new messages