aboutsummaryrefslogtreecommitdiff
path: root/tools/testing/selftests/net/lib/py
diff options
context:
space:
mode:
authorJakub Kicinski <kuba@kernel.org>2024-04-12 07:14:33 -0700
committerJakub Kicinski <kuba@kernel.org>2024-04-15 11:21:12 -0700
commiteeb409bde964df1956297b6775ff5f53dd98d556 (patch)
tree722e3e14deeffa318c5f62ec8b1f48d2869fa64b /tools/testing/selftests/net/lib/py
parent72ba6cba0a6e9f06c09187ddbbdc9f80ee93ffb3 (diff)
downloadlinux-eeb409bde964df1956297b6775ff5f53dd98d556.tar.gz
linux-eeb409bde964df1956297b6775ff5f53dd98d556.tar.bz2
linux-eeb409bde964df1956297b6775ff5f53dd98d556.zip
selftests: net: print report check location in python tests
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> Link: https://lore.kernel.org/r/20240412141436.828666-4-kuba@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'tools/testing/selftests/net/lib/py')
-rw-r--r--tools/testing/selftests/net/lib/py/ksft.py25
1 files changed, 14 insertions, 11 deletions
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 @@ def ksft_pr(*objs, **kwargs):
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=""):