Skip to content

Commit ba9cfe0

Browse files
committed
selftests: net: set the exit code correctly in Python tests
JIRA: https://issues.redhat.com/browse/RHEL-57764 commit 4fa6bd4 Author: Jakub Kicinski <kuba@kernel.org> Date: Wed Apr 17 16:11:40 2024 -0700 selftests: net: set the exit code correctly in Python tests 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(). Link: https://lore.kernel.org/r/20240417231146.2435572-3-kuba@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Ivan Vecera <ivecera@redhat.com>
1 parent 4a4366e commit ba9cfe0

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

tools/testing/selftests/drivers/net/stats.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/env python3
22
# SPDX-License-Identifier: GPL-2.0
33

4-
from lib.py import ksft_run, ksft_in, ksft_true, KsftSkipEx, KsftXfailEx
4+
from lib.py import ksft_run, ksft_exit
5+
from lib.py import ksft_in, ksft_true, KsftSkipEx, KsftXfailEx
56
from lib.py import EthtoolFamily, NetdevFamily, RtnlFamily, NlError
67
from lib.py import NetDrvEnv
78

@@ -80,6 +81,7 @@ def main() -> None:
8081
with NetDrvEnv(__file__) as cfg:
8182
ksft_run([check_pause, check_fec, pkt_byte_sum],
8283
args=(cfg, ))
84+
ksft_exit()
8385

8486

8587
if __name__ == "__main__":

tools/testing/selftests/net/lib/py/ksft.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
import builtins
44
import inspect
5+
import sys
56
import time
67
import traceback
78
from .consts import KSFT_MAIN_NAME
89

910
KSFT_RESULT = None
11+
KSFT_RESULT_ALL = True
1012

1113

1214
class KsftSkipEx(Exception):
@@ -63,6 +65,9 @@ def ksft_busy_wait(cond, sleep=0.005, deadline=1, comment=""):
6365

6466

6567
def ktap_result(ok, cnt=1, case="", comment=""):
68+
global KSFT_RESULT_ALL
69+
KSFT_RESULT_ALL = KSFT_RESULT_ALL and ok
70+
6671
res = ""
6772
if not ok:
6873
res += "not "
@@ -114,3 +119,8 @@ def ksft_run(cases, args=()):
114119
print(
115120
f"# Totals: pass:{totals['pass']} fail:{totals['fail']} xfail:{totals['xfail']} xpass:0 skip:{totals['skip']} error:0"
116121
)
122+
123+
124+
def ksft_exit():
125+
global KSFT_RESULT_ALL
126+
sys.exit(0 if KSFT_RESULT_ALL else 1)

tools/testing/selftests/net/nl_netdev.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
# SPDX-License-Identifier: GPL-2.0
33

44
import time
5-
from lib.py import ksft_run, ksft_pr, ksft_eq, ksft_ge, ksft_busy_wait
5+
from lib.py import ksft_run, ksft_exit, ksft_pr
6+
from lib.py import ksft_eq, ksft_ge, ksft_busy_wait
67
from lib.py import NetdevFamily, NetdevSimDev, ip
78

89

@@ -90,6 +91,7 @@ def main() -> None:
9091
nf = NetdevFamily()
9192
ksft_run([empty_check, lo_check, page_pool_check],
9293
args=(nf, ))
94+
ksft_exit()
9395

9496

9597
if __name__ == "__main__":

0 commit comments

Comments
 (0)