]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
kunit: tool: fix _list_tests filtering wrong variable when list has TAP prefix
authorMohammad Abu-Khader <mohammad.abukhader@hotmail.com>
Mon, 3 Aug 2026 19:02:17 +0000 (19:02 +0000)
committerShuah Khan <skhan@linuxfoundation.org>
Wed, 12 Aug 2026 16:42:53 +0000 (10:42 -0600)
`_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.

Link: https://lore.kernel.org/r/20260803190059.36491-1-mohammad.abukhader@hotmail.com
Fixes: 723c8258c8fe ("kunit: tool: Add command line interface to filter and report attributes")
Signed-off-by: Mohammad Abu-Khader <mohammad.abukhader@hotmail.com>
Reviewed-by: David Gow <david@davidgow.net>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
tools/testing/kunit/kunit.py
tools/testing/kunit/kunit_tool_test.py

index ac3f7159e67fea8f34599167cf7ecde897c07044..91d234ac3b579260a33557955ecf7979c8439d01 100755 (executable)
@@ -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']
index da88c3a1651d09d671495acd9c0cf96f6f563f25..85ae21754bdf90860ae2e0d2c8e06a8e38536f4b 100755 (executable)
@@ -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']