]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
selftests: net: support matching cases by name prefix
authorJakub Kicinski <kuba@kernel.org>
Sat, 20 Apr 2024 02:52:35 +0000 (19:52 -0700)
committerJakub Kicinski <kuba@kernel.org>
Tue, 23 Apr 2024 17:13:56 +0000 (10:13 -0700)
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>
tools/testing/selftests/drivers/net/ping.py
tools/testing/selftests/net/lib/py/ksft.py

index e75908d7c55859f7d89e47376fdea8c1a9d49f88..9f65a0764aab3dfc66385ab966da8471037fe111 100755 (executable)
@@ -18,8 +18,7 @@ def test_v6(cfg) -> None:
 
 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()
 
 
index e7f79f6185b0182c5878d2cfc0625b8a9403ce89..f84e9fdd0032597417027485e19becaf795cd05f 100644 (file)
@@ -99,7 +99,18 @@ def ktap_result(ok, cnt=1, case="", comment=""):
     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")