mirror of
https://git.proxmox.com/git/mirror_ubuntu-kernels.git
synced 2025-12-07 20:48:20 +00:00
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>
89 lines
2.6 KiB
Python
Executable File
89 lines
2.6 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
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
|
|
|
|
ethnl = EthtoolFamily()
|
|
netfam = NetdevFamily()
|
|
rtnl = RtnlFamily()
|
|
|
|
|
|
def check_pause(cfg) -> None:
|
|
global ethnl
|
|
|
|
try:
|
|
ethnl.pause_get({"header": {"dev-index": cfg.ifindex}})
|
|
except NlError as e:
|
|
if e.error == 95:
|
|
raise KsftXfailEx("pause not supported by the device")
|
|
raise
|
|
|
|
data = ethnl.pause_get({"header": {"dev-index": cfg.ifindex,
|
|
"flags": {'stats'}}})
|
|
ksft_true(data['stats'], "driver does not report stats")
|
|
|
|
|
|
def check_fec(cfg) -> None:
|
|
global ethnl
|
|
|
|
try:
|
|
ethnl.fec_get({"header": {"dev-index": cfg.ifindex}})
|
|
except NlError as e:
|
|
if e.error == 95:
|
|
raise KsftXfailEx("FEC not supported by the device")
|
|
raise
|
|
|
|
data = ethnl.fec_get({"header": {"dev-index": cfg.ifindex,
|
|
"flags": {'stats'}}})
|
|
ksft_true(data['stats'], "driver does not report stats")
|
|
|
|
|
|
def pkt_byte_sum(cfg) -> None:
|
|
global netfam, rtnl
|
|
|
|
def get_qstat(test):
|
|
global netfam
|
|
stats = netfam.qstats_get({}, dump=True)
|
|
if stats:
|
|
for qs in stats:
|
|
if qs["ifindex"]== test.ifindex:
|
|
return qs
|
|
|
|
qstat = get_qstat(cfg)
|
|
if qstat is None:
|
|
raise KsftSkipEx("qstats not supported by the device")
|
|
|
|
for key in ['tx-packets', 'tx-bytes', 'rx-packets', 'rx-bytes']:
|
|
ksft_in(key, qstat, "Drivers should always report basic keys")
|
|
|
|
# Compare stats, rtnl stats and qstats must match,
|
|
# but the interface may be up, so do a series of dumps
|
|
# each time the more "recent" stats must be higher or same.
|
|
def stat_cmp(rstat, qstat):
|
|
for key in ['tx-packets', 'tx-bytes', 'rx-packets', 'rx-bytes']:
|
|
if rstat[key] != qstat[key]:
|
|
return rstat[key] - qstat[key]
|
|
return 0
|
|
|
|
for _ in range(10):
|
|
rtstat = rtnl.getlink({"ifi-index": cfg.ifindex})['stats']
|
|
if stat_cmp(rtstat, qstat) < 0:
|
|
raise Exception("RTNL stats are lower, fetched later")
|
|
qstat = get_qstat(cfg)
|
|
if stat_cmp(rtstat, qstat) > 0:
|
|
raise Exception("Qstats are lower, fetched later")
|
|
|
|
|
|
def main() -> None:
|
|
with NetDrvEnv(__file__) as cfg:
|
|
ksft_run([check_pause, check_fec, pkt_byte_sum],
|
|
args=(cfg, ))
|
|
ksft_exit()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|