diff mbox series

[net-next,v3,2/8] selftests: net: set the exit code correctly in Python tests

Message ID 20240417231146.2435572-3-kuba@kernel.org (mailing list archive)
State Superseded
Commit 4fa6bd4b33ac9b914e3d1bb95848239ab8fdde1a
Delegated to: Netdev Maintainers
Headers show
Series selftests: drv-net: support testing with a remote system | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
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, 62 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-18--21-00 (tests: 960)

Commit Message

Jakub Kicinski April 17, 2024, 11:11 p.m. UTC
Test cases need to exit with non-zero status if they failed,
we currently don't do that:

  # KTAP version 1
  # 1..3
  # # At /root/ksft-net-drv/drivers/net/./ping.py line 18:
  # # Check failed 1 != 2
  # not ok 1 ping.test_v4
  # ok 2 ping.test_v6
  # ok 3 ping.test_tcp
  # # Totals: pass:2 fail:1 xfail:0 xpass:0 skip:0 error:0
  ok 1 selftests: drivers/net: ping.py
  ^^^^

It's a bit tempting to make the exit part of ksft_run(),
but that only works well for very trivial setups. We can
revisit this later, if people forget to call ksft_exit().

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 tools/testing/selftests/drivers/net/stats.py |  4 +++-
 tools/testing/selftests/net/lib/py/ksft.py   | 10 ++++++++++
 tools/testing/selftests/net/nl_netdev.py     |  4 +++-
 3 files changed, 16 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/tools/testing/selftests/drivers/net/stats.py b/tools/testing/selftests/drivers/net/stats.py
index 5a9d4e56b28b..947df3eb681f 100755
--- a/tools/testing/selftests/drivers/net/stats.py
+++ b/tools/testing/selftests/drivers/net/stats.py
@@ -1,7 +1,8 @@ 
 #!/usr/bin/env python3
 # SPDX-License-Identifier: GPL-2.0
 
-from lib.py import ksft_run, ksft_in, ksft_true, KsftSkipEx, KsftXfailEx
+from lib.py import ksft_run, ksft_exit
+from lib.py import ksft_in, ksft_true, KsftSkipEx, KsftXfailEx
 from lib.py import EthtoolFamily, NetdevFamily, RtnlFamily, NlError
 from lib.py import NetDrvEnv
 
@@ -80,6 +81,7 @@  rtnl = RtnlFamily()
     with NetDrvEnv(__file__) as cfg:
         ksft_run([check_pause, check_fec, pkt_byte_sum],
                  args=(cfg, ))
+    ksft_exit()
 
 
 if __name__ == "__main__":
diff --git a/tools/testing/selftests/net/lib/py/ksft.py b/tools/testing/selftests/net/lib/py/ksft.py
index 640dfbf47702..25f2572fa540 100644
--- a/tools/testing/selftests/net/lib/py/ksft.py
+++ b/tools/testing/selftests/net/lib/py/ksft.py
@@ -2,11 +2,13 @@ 
 
 import builtins
 import inspect
+import sys
 import time
 import traceback
 from .consts import KSFT_MAIN_NAME
 
 KSFT_RESULT = None
+KSFT_RESULT_ALL = True
 
 
 class KsftSkipEx(Exception):
@@ -63,6 +65,9 @@  KSFT_RESULT = None
 
 
 def ktap_result(ok, cnt=1, case="", comment=""):
+    global KSFT_RESULT_ALL
+    KSFT_RESULT_ALL = KSFT_RESULT_ALL and ok
+
     res = ""
     if not ok:
         res += "not "
@@ -114,3 +119,8 @@  KSFT_RESULT = None
     print(
         f"# Totals: pass:{totals['pass']} fail:{totals['fail']} xfail:{totals['xfail']} xpass:0 skip:{totals['skip']} error:0"
     )
+
+
+def ksft_exit():
+    global KSFT_RESULT_ALL
+    sys.exit(0 if KSFT_RESULT_ALL else 1)
diff --git a/tools/testing/selftests/net/nl_netdev.py b/tools/testing/selftests/net/nl_netdev.py
index 6909b1760739..93d9d914529b 100755
--- a/tools/testing/selftests/net/nl_netdev.py
+++ b/tools/testing/selftests/net/nl_netdev.py
@@ -2,7 +2,8 @@ 
 # SPDX-License-Identifier: GPL-2.0
 
 import time
-from lib.py import ksft_run, ksft_pr, ksft_eq, ksft_ge, ksft_busy_wait
+from lib.py import ksft_run, ksft_exit, ksft_pr
+from lib.py import ksft_eq, ksft_ge, ksft_busy_wait
 from lib.py import NetdevFamily, NetdevSimDev, ip
 
 
@@ -90,6 +91,7 @@  from lib.py import NetdevFamily, NetdevSimDev, ip
     nf = NetdevFamily()
     ksft_run([empty_check, lo_check, page_pool_check],
              args=(nf, ))
+    ksft_exit()
 
 
 if __name__ == "__main__":