[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240418233844.2762396-6-kuba@kernel.org>
Date: Thu, 18 Apr 2024 16:38:42 -0700
From: Jakub Kicinski <kuba@...nel.org>
To: davem@...emloft.net
Cc: netdev@...r.kernel.org,
edumazet@...gle.com,
pabeni@...hat.com,
shuah@...nel.org,
petrm@...dia.com,
linux-kselftest@...r.kernel.org,
willemdebruijn.kernel@...il.com,
Jakub Kicinski <kuba@...nel.org>
Subject: [PATCH net-next v4 5/7] selftests: net: support matching cases by name prefix
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@...nel.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 25f2572fa540..8018bf98a9d2 100644
--- a/tools/testing/selftests/net/lib/py/ksft.py
+++ b/tools/testing/selftests/net/lib/py/ksft.py
@@ -81,7 +81,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
Powered by blists - more mailing lists