Skip to content

Commit 45e7b8d

Browse files
committed
selftests: net: support matching cases by name prefix
JIRA: https://issues.redhat.com/browse/RHEL-57764 commit 01b4316 Author: Jakub Kicinski <kuba@kernel.org> Date: Fri Apr 19 19:52:35 2024 -0700 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. Reviewed-by: Willem de Bruijn <willemb@google.com> Link: https://lore.kernel.org/r/20240420025237.3309296-6-kuba@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Ivan Vecera <ivecera@redhat.com>
1 parent 5b68d43 commit 45e7b8d

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

tools/testing/selftests/drivers/net/ping.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ def test_v6(cfg) -> None:
1818

1919
def main() -> None:
2020
with NetDrvEpEnv(__file__) as cfg:
21-
ksft_run([test_v4, test_v6],
22-
args=(cfg, ))
21+
ksft_run(globs=globals(), case_pfx={"test_"}, args=(cfg, ))
2322
ksft_exit()
2423

2524

tools/testing/selftests/net/lib/py/ksft.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,18 @@ def ktap_result(ok, cnt=1, case="", comment=""):
8181
print(res)
8282

8383

84-
def ksft_run(cases, args=()):
84+
def ksft_run(cases=None, globs=None, case_pfx=None, args=()):
85+
cases = cases or []
86+
87+
if globs and case_pfx:
88+
for key, value in globs.items():
89+
if not callable(value):
90+
continue
91+
for prefix in case_pfx:
92+
if key.startswith(prefix):
93+
cases.append(value)
94+
break
95+
8596
totals = {"pass": 0, "fail": 0, "skip": 0, "xfail": 0}
8697

8798
print("KTAP version 1")

0 commit comments

Comments
 (0)