diff mbox series

[net-next,v2,3/6] selftests: net: print report check location in python tests

Message ID 20240412141436.828666-4-kuba@kernel.org (mailing list archive)
State Accepted
Commit eeb409bde964df1956297b6775ff5f53dd98d556
Delegated to: Netdev Maintainers
Headers show
Series selftests: net: exercise page pool reporting via netlink | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next, async
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 52 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-04-15--15-00 (tests: 961)

Commit Message

Jakub Kicinski April 12, 2024, 2:14 p.m. UTC
Developing Python tests is a bit annoying because when test fails
we only print the fail message and no info about which exact check
led to it. Print the location (the first line of this example is new):

  # At /root/ksft-net-drv/./net/nl_netdev.py line 38:
  # Check failed 0 != 10
  not ok 3 nl_netdev.page_pool_check

Reviewed-by: Petr Machata <petrm@nvidia.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
v2: - pass *args from fail to pr
---
 tools/testing/selftests/net/lib/py/ksft.py | 25 ++++++++++++----------
 1 file changed, 14 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/tools/testing/selftests/net/lib/py/ksft.py b/tools/testing/selftests/net/lib/py/ksft.py
index c7210525981c..b4b0bfff68b0 100644
--- a/tools/testing/selftests/net/lib/py/ksft.py
+++ b/tools/testing/selftests/net/lib/py/ksft.py
@@ -1,6 +1,7 @@ 
 # SPDX-License-Identifier: GPL-2.0
 
 import builtins
+import inspect
 from .consts import KSFT_MAIN_NAME
 
 KSFT_RESULT = None
@@ -18,32 +19,34 @@  KSFT_RESULT = None
     print("#", *objs, **kwargs)
 
 
+def _fail(*args):
+    global KSFT_RESULT
+    KSFT_RESULT = False
+
+    frame = inspect.stack()[2]
+    ksft_pr("At " + frame.filename + " line " + str(frame.lineno) + ":")
+    ksft_pr(*args)
+
+
 def ksft_eq(a, b, comment=""):
     global KSFT_RESULT
     if a != b:
-        KSFT_RESULT = False
-        ksft_pr("Check failed", a, "!=", b, comment)
+        _fail("Check failed", a, "!=", b, comment)
 
 
 def ksft_true(a, comment=""):
-    global KSFT_RESULT
     if not a:
-        KSFT_RESULT = False
-        ksft_pr("Check failed", a, "does not eval to True", comment)
+        _fail("Check failed", a, "does not eval to True", comment)
 
 
 def ksft_in(a, b, comment=""):
-    global KSFT_RESULT
     if a not in b:
-        KSFT_RESULT = False
-        ksft_pr("Check failed", a, "not in", b, comment)
+        _fail("Check failed", a, "not in", b, comment)
 
 
 def ksft_ge(a, b, comment=""):
-    global KSFT_RESULT
     if a < b:
-        KSFT_RESULT = False
-        ksft_pr("Check failed", a, "<", b, comment)
+        _fail("Check failed", a, "<", b, comment)
 
 
 def ktap_result(ok, cnt=1, case="", comment=""):