netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
	shuah@kernel.org, petrm@nvidia.com,
	linux-kselftest@vger.kernel.org, willemdebruijn.kernel@gmail.com,
	Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next v5 5/7] selftests: net: support matching cases by name prefix
Date: Fri, 19 Apr 2024 19:52:35 -0700	[thread overview]
Message-ID: <20240420025237.3309296-6-kuba@kernel.org> (raw)
In-Reply-To: <20240420025237.3309296-1-kuba@kernel.org>

While writing tests with a lot more cases I got tired of having
to jump back and forth to add the name of the test to the ksft_run()
list. Most unittest frameworks do some name matching, e.g. assume
that functions with names starting with test_ are test cases.

Support similar flow in ksft_run(). Let the author list the desired
prefixes. globals() need to be passed explicitly, IDK how to work
around that.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
v4:
 - spell the code out a little to make it clearer
---
 tools/testing/selftests/drivers/net/ping.py |  3 +--
 tools/testing/selftests/net/lib/py/ksft.py  | 13 ++++++++++++-
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/drivers/net/ping.py b/tools/testing/selftests/drivers/net/ping.py
index e75908d7c558..9f65a0764aab 100755
--- a/tools/testing/selftests/drivers/net/ping.py
+++ b/tools/testing/selftests/drivers/net/ping.py
@@ -18,8 +18,7 @@ from lib.py import cmd
 
 def main() -> None:
     with NetDrvEpEnv(__file__) as cfg:
-        ksft_run([test_v4, test_v6],
-                 args=(cfg, ))
+        ksft_run(globs=globals(), case_pfx={"test_"}, args=(cfg, ))
     ksft_exit()
 
 
diff --git a/tools/testing/selftests/net/lib/py/ksft.py b/tools/testing/selftests/net/lib/py/ksft.py
index e7f79f6185b0..f84e9fdd0032 100644
--- a/tools/testing/selftests/net/lib/py/ksft.py
+++ b/tools/testing/selftests/net/lib/py/ksft.py
@@ -99,7 +99,18 @@ KSFT_RESULT_ALL = True
     print(res)
 
 
-def ksft_run(cases, args=()):
+def ksft_run(cases=None, globs=None, case_pfx=None, args=()):
+    cases = cases or []
+
+    if globs and case_pfx:
+        for key, value in globs.items():
+            if not callable(value):
+                continue
+            for prefix in case_pfx:
+                if key.startswith(prefix):
+                    cases.append(value)
+                    break
+
     totals = {"pass": 0, "fail": 0, "skip": 0, "xfail": 0}
 
     print("KTAP version 1")
-- 
2.44.0


  parent reply	other threads:[~2024-04-20  2:52 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-20  2:52 [PATCH net-next v5 0/7] selftests: drv-net: support testing with a remote system Jakub Kicinski
2024-04-20  2:52 ` [PATCH net-next v5 1/7] selftests: drv-net: define endpoint structures Jakub Kicinski
2024-04-20  2:52 ` [PATCH net-next v5 2/7] selftests: drv-net: factor out parsing of the env Jakub Kicinski
2024-04-20  2:52 ` [PATCH net-next v5 3/7] selftests: drv-net: construct environment for running tests which require an endpoint Jakub Kicinski
2024-04-20  2:52 ` [PATCH net-next v5 4/7] selftests: drv-net: add a trivial ping test Jakub Kicinski
2024-04-20  2:52 ` Jakub Kicinski [this message]
2024-04-20  2:52 ` [PATCH net-next v5 6/7] selftests: drv-net: add a TCP ping test case (and useful helpers) Jakub Kicinski
2024-04-20  2:52 ` [PATCH net-next v5 7/7] selftests: drv-net: add require_XYZ() helpers for validating env Jakub Kicinski
2024-04-21 14:59   ` Willem de Bruijn
2024-04-21 14:47 ` [PATCH net-next v5 0/7] selftests: drv-net: support testing with a remote system Willem de Bruijn
2024-04-23 17:57   ` Willem de Bruijn
2024-04-24  1:53     ` Jakub Kicinski
2024-04-24 14:13       ` Willem de Bruijn
2024-04-24 18:57         ` Jakub Kicinski
2024-04-24 20:59           ` Willem de Bruijn
2024-04-23 17:20 ` patchwork-bot+netdevbpf

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=20240420025237.3309296-6-kuba@kernel.org \
    --to=kuba@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=petrm@nvidia.com \
    --cc=shuah@kernel.org \
    --cc=willemdebruijn.kernel@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).