public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
To: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jonathan Corbet <corbet@lwn.net>,
	"David S. Miller" <davem@davemloft.net>,
	Alexander Lobakin <aleksander.lobakin@intel.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Jesper Dangaard Brouer <hawk@kernel.org>,
	John Fastabend <john.fastabend@gmail.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Richard Cochran <richardcochran@gmail.com>, <bpf@vger.kernel.org>,
	<intel-wired-lan@lists.osuosl.org>, <linux-doc@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <netdev@vger.kernel.org>,
	Randy Dunlap <rdunlap@infradead.org>,
	Shuah Khan <skhan@linuxfoundation.org>,
	Stanislav Fomichev <sdf@fomichev.me>
Subject: Re: [PATCH v2 00/25] kernel-doc: make it parse new functions and structs
Date: Wed, 28 Jan 2026 23:00:45 +0100	[thread overview]
Message-ID: <20260128230045.781937b5@foz.lan> (raw)
In-Reply-To: <fced629d-2470-4673-ab0b-80de11f0e4c5@intel.com>

On Wed, 28 Jan 2026 10:15:51 -0800
Jacob Keller <jacob.e.keller@intel.com> wrote:

> On 1/28/2026 9:27 AM, Jonathan Corbet wrote:
> > Mauro Carvalho Chehab <mchehab+huawei@kernel.org> writes:
> >   
> >> Hi Jon,
> >>
> >> It is impressive how a single patch became a series with 25 ones ;-)  
> > 
> > *sigh*
> >   
> 
> Splitting things up helped me understand all the changes at least :)
> 
> > I will try to have a good look at these shortly.  It seems pretty clear
> > that this isn't 7.0 material at this point, though.
> > 
> > One thing that jumped at me:
> >   
> >> Ah, due to the complexity of NestedMatch, I opted to write
> >> some unit tests to verify that the logic there is correct.
> >> We can use it to add other border cases.
> >>
> >> Using it is as easy as running:
> >>
> >> 	$ tools/unittests/nested_match.py
> >>
> >> (I opted to create a separate directory for it, as this
> >> is not really documentation)  
> > 
> > Do we really need another unit-testing setup in the kernel?  I can't say
> > I'm familiar enough with kunit to say whether it would work for
> > non-kernel code; have you looked and verified that it isn't suitable?
> >   
> 
> I'm not sure kunit would be suitable here, since its meant for running 
> kernel code and does a lot of stuff to make that possible. It might be 
> able to be extended, but.. this is python code. Why *shouldn't* we use 
> one of the python unit test frameworks for it?

This is not using kunit. It is using standard "import unittest" from
Python internal lib.

> We have other python code in tree. Does any of that code have unit tests?

Good question. On a quick grep, it sounds so:

	$ git grep "import unittest" tools scripts
	scripts/rust_is_available_test.py:import unittest
	tools/crypto/ccp/test_dbc.py:import unittest
	tools/perf/pmu-events/metric_test.py:import unittest
	tools/testing/kunit/kunit_tool_test.py:import unittest
	tools/testing/selftests/bpf/test_bpftool.py:import unittest
	tools/testing/selftests/tpm2/tpm2.py:import unittest
	tools/testing/selftests/tpm2/tpm2_tests.py:import unittest

> I agree that it doesn't make sense to build new bespoke unit tests 
> different or unique per each python module, so if we want to adopt 
> python unit tests we should try to pick something that works for the 
> python tools in the kernel.
> 
> Perhaps finding a way to integrate this with kunit so that you can use 
> "kunit run" and get python tests executed as well would make sense? 
> But.. then again this isn't kernel code so I'm not sure it makes sense 
> to conflate the tests with kernel unit tests.

It shouldn't be hard to add it there - or to have a separate script
to run python unittests.

Assuming that we place all unittests at the same directory
(tools/unittests), the enclosed path will run all of them
altogether:

	$ tools/unittests/run.py
	Ran 35 tests in 0.001s

	OK
	nested_match:
	    TestStructGroup:
	        test_struct_group_01:            OK
	        test_struct_group_02:            OK
	        test_struct_group_03:            OK
	        test_struct_group_04:            OK
	        test_struct_group_05:            OK
	        test_struct_group_06:            OK
	        test_struct_group_07:            OK
	        test_struct_group_08:            OK
	        test_struct_group_09:            OK
	        test_struct_group_10:            OK
	        test_struct_group_11:            OK
        	test_struct_group_12:            OK
	        test_struct_group_13:            OK
	        test_struct_group_14:            OK
	        test_struct_group_15:            OK
	        test_struct_group_16:            OK
	        test_struct_group_17:            OK
	        test_struct_group_18:            OK
	        test_struct_group_19:            OK
	        test_struct_group_sub:           OK
	    TestSubMacros:
	        test_acquires_multiple:          OK
        	test_acquires_nested_paren:      OK
	        test_acquires_simple:            OK
        	test_mixed_macros:               OK
	        test_must_hold:                  OK
        	test_must_hold_shared:           OK
	        test_no_false_positive:          OK
	        test_no_macro_remains:           OK
	    TestSubReplacement:
	        test_sub_count_parameter:        OK
	        test_sub_mixed_placeholders:     OK
	        test_sub_multiple_placeholders:  OK
	        test_sub_no_placeholder:         OK
	        test_sub_single_placeholder:     OK
	        test_sub_with_capture:           OK
	        test_sub_zero_placeholder:       OK


	Ran 35 tests

And the helper will also provide an argparse to allow filtering
tests, change verbosity and filtering them with a regex:

	$ tools/unittests/run.py --help
	usage: run.py [-h] [-v] [-f] [-k KEYWORD]

	Test runner with regex filtering

	options:
	  -h, --help            show this help message and exit
	  -v, --verbose
	  -f, --failfast
	  -k, --keyword KEYWORD
	                        Regex pattern to filter test methods

That's said, some integration with kunit can be interesting
to have it producing a KTAP output if needed by some CI.

---

[PATCH] [RFC] Run all tests from tools/unittests

This small example runs all unittests from tools/unittests with:

    $ tools/unittests/run.py

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

diff --git a/tools/lib/python/unittest_helper.py b/tools/lib/python/unittest_helper.py
index 3cf1075b1de4..af16acc3af17 100755
--- a/tools/lib/python/unittest_helper.py
+++ b/tools/lib/python/unittest_helper.py
@@ -213,7 +213,7 @@ class TestUnits:
                             help="Regex pattern to filter test methods")
         return parser
 
-    def run(self, caller_file, parser=None, args=None, env=None):
+    def run(self, caller_file, suite=None, parser=None, args=None, env=None):
         """Execute all tests from the unity test file"""
         if not args:
             if not parser:
@@ -232,9 +232,10 @@ class TestUnits:
             unittest.TextTestRunner(verbosity=verbose).run = lambda suite: suite
 
         # Load ONLY tests from the calling file
-        loader = unittest.TestLoader()
-        suite = loader.discover(start_dir=os.path.dirname(caller_file),
-                                pattern=os.path.basename(caller_file))
+        if not suite:
+            loader = unittest.TestLoader()
+            suite = loader.discover(start_dir=os.path.dirname(caller_file),
+                                    pattern=os.path.basename(caller_file))
 
         # Flatten the suite for environment injection
         tests_to_inject = flatten_suite(suite)
diff --git a/tools/unittests/run.py b/tools/unittests/run.py
new file mode 100755
index 000000000000..2a5a754219de
--- /dev/null
+++ b/tools/unittests/run.py
@@ -0,0 +1,17 @@
+#!/bin/env python3
+import os
+import unittest
+import sys
+
+TOOLS_DIR=os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")
+sys.path.insert(0, TOOLS_DIR)
+
+from lib.python.unittest_helper import TestUnits
+
+if __name__ == "__main__":
+    loader = unittest.TestLoader()
+
+    suite = loader.discover(start_dir=os.path.join(TOOLS_DIR, "unittests"),
+                            pattern="*.py")
+
+    TestUnits().run("", suite=suite)

Thanks,
Mauro

  reply	other threads:[~2026-01-28 22:00 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-28 16:49 [PATCH v2 00/25] kernel-doc: make it parse new functions and structs Mauro Carvalho Chehab
2026-01-28 16:49 ` [PATCH v2 01/25] docs: kdoc_re: add support for groups() Mauro Carvalho Chehab
2026-01-28 17:44   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-28 16:50 ` [PATCH v2 02/25] docs: kdoc_re: don't go past the end of a line Mauro Carvalho Chehab
2026-01-28 17:44   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-28 16:50 ` [PATCH v2 03/25] docs: kdoc_parser: move var transformers to the beginning Mauro Carvalho Chehab
2026-01-28 17:44   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-28 16:50 ` [PATCH v2 04/25] docs: kdoc_parser: don't mangle with function defines Mauro Carvalho Chehab
2026-01-28 17:45   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-28 16:50 ` [PATCH v2 05/25] docs: kdoc_parser: add functions support for NestedMatch Mauro Carvalho Chehab
2026-01-28 16:50 ` [PATCH v2 06/25] docs: kdoc_parser: use NestedMatch to handle __attribute__ on functions Mauro Carvalho Chehab
2026-01-28 16:50 ` [PATCH v2 07/25] docs: kdoc_parser: fix variable regexes to work with size_t Mauro Carvalho Chehab
2026-01-28 17:45   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-28 16:50 ` [PATCH v2 08/25] docs: kdoc_parser: fix the default_value logic for variables Mauro Carvalho Chehab
2026-01-28 17:45   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-28 16:50 ` [PATCH v2 09/25] docs: kdoc_parser: add some debug for variable parsing Mauro Carvalho Chehab
2026-01-28 17:46   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-28 16:50 ` [PATCH v2 10/25] docs: kdoc_parser: don't exclude defaults from prototype Mauro Carvalho Chehab
2026-01-28 17:46   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-28 16:50 ` [PATCH v2 11/25] docs: kdoc_parser: fix parser to support multi-word types Mauro Carvalho Chehab
2026-01-28 17:47   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-28 16:50 ` [PATCH v2 12/25] docs: kdoc_parser: ignore context analysis and lock attributes Mauro Carvalho Chehab
2026-01-28 17:47   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-28 16:50 ` [PATCH v2 13/25] docs: kdoc_parser: add support for LIST_HEAD Mauro Carvalho Chehab
2026-01-28 17:47   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-28 16:50 ` [PATCH v2 14/25] kdoc_parser: handle struct member macro VIRTIO_DECLARE_FEATURES(name) Mauro Carvalho Chehab
2026-01-28 17:47   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-28 16:50 ` [PATCH v2 15/25] docs: kdoc_re: properly handle strings and escape chars on it Mauro Carvalho Chehab
2026-01-28 17:47   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-28 16:50 ` [PATCH v2 16/25] docs: kdoc_re: better show KernRe() at documentation Mauro Carvalho Chehab
2026-01-28 17:48   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-28 16:50 ` [PATCH v2 17/25] docs: kdoc_re: don't recompile NextMatch regex every time Mauro Carvalho Chehab
2026-01-28 17:48   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-28 16:50 ` [PATCH v2 18/25] docs: kdoc_re: Change NestedMath args replacement to \0 Mauro Carvalho Chehab
2026-01-28 17:48   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-28 16:50 ` [PATCH v2 19/25] docs: kdoc_re: make NextedMatch use KernRe Mauro Carvalho Chehab
2026-01-28 16:50 ` [PATCH v2 20/25] tools: kdoc_re: add support on NestedMatch for argument replacement Mauro Carvalho Chehab
2026-01-28 17:49   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-28 16:50 ` [PATCH v2 21/25] tools: python: add helpers to run unit tests Mauro Carvalho Chehab
2026-01-28 16:50 ` [PATCH v2 22/25] unittests: add tests for NestedMatch class Mauro Carvalho Chehab
2026-01-28 16:50 ` [PATCH v2 23/25] tools/lib/python/unittest_helper.py Mauro Carvalho Chehab
2026-01-28 17:17   ` Mauro Carvalho Chehab
2026-01-28 17:32   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-28 18:09   ` Jacob Keller
2026-01-28 21:02     ` Mauro Carvalho Chehab
2026-01-28 22:04       ` Jacob Keller
2026-01-28 16:50 ` [PATCH v2 24/25] docs: kdoc_parser: better handle struct_group macros Mauro Carvalho Chehab
2026-01-28 17:49   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-28 16:50 ` [PATCH v2 25/25] docs: kdoc_re: fix a parse bug on struct page_pool_params Mauro Carvalho Chehab
2026-01-28 17:49   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-28 17:27 ` [PATCH v2 00/25] kernel-doc: make it parse new functions and structs Jonathan Corbet
2026-01-28 18:15   ` Jacob Keller
2026-01-28 22:00     ` Mauro Carvalho Chehab [this message]
2026-01-28 22:08       ` Jacob Keller
2026-01-29  8:14         ` Mauro Carvalho Chehab
2026-02-10 15:27   ` Mauro Carvalho Chehab

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=20260128230045.781937b5@foz.lan \
    --to=mchehab+huawei@kernel.org \
    --cc=aleksander.lobakin@intel.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=corbet@lwn.net \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=hawk@kernel.org \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=jacob.e.keller@intel.com \
    --cc=john.fastabend@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=richardcochran@gmail.com \
    --cc=sdf@fomichev.me \
    --cc=skhan@linuxfoundation.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox