From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
shuah@kernel.org, petrm@nvidia.com,
linux-kselftest@vger.kernel.org, Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next v2 3/6] selftests: net: print report check location in python tests
Date: Fri, 12 Apr 2024 07:14:33 -0700 [thread overview]
Message-ID: <20240412141436.828666-4-kuba@kernel.org> (raw)
In-Reply-To: <20240412141436.828666-1-kuba@kernel.org>
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 --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=""):
--
2.44.0
next prev parent reply other threads:[~2024-04-12 14:14 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-12 14:14 [PATCH net-next v2 0/6] selftests: net: exercise page pool reporting via netlink Jakub Kicinski
2024-04-12 14:14 ` [PATCH net-next v2 1/6] net: netdevsim: add some fake page pool use Jakub Kicinski
2024-04-12 14:14 ` [PATCH net-next v2 2/6] tools: ynl: don't return None for dumps Jakub Kicinski
2024-04-12 14:14 ` Jakub Kicinski [this message]
2024-04-12 14:14 ` [PATCH net-next v2 4/6] selftests: net: print full exception on failure Jakub Kicinski
2024-04-12 14:14 ` [PATCH net-next v2 5/6] selftests: net: support use of NetdevSimDev under "with" in python Jakub Kicinski
2024-04-12 14:14 ` [PATCH net-next v2 6/6] selftests: net: exercise page pool reporting via netlink Jakub Kicinski
2024-04-12 17:00 ` Petr Machata
2024-04-15 18:40 ` [PATCH net-next v2 0/6] " patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240412141436.828666-4-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=petrm@nvidia.com \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).