Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: net-drv: exercise queue stats when the device is down

Verify that total device stats don't decrease after it has been turned down.
Also make sure the device doesn't crash when we access per-queue stats
when it's down (in case it tries to access some pointers that are NULL).

KTAP version 1
1..5
ok 1 stats.check_pause
ok 2 stats.check_fec
ok 3 stats.pkt_byte_sum
ok 4 stats.qstat_by_ifindex
ok 5 stats.check_down
# Totals: pass:5 fail:0 xfail:0 xpass:0 skip:0 error:0

v3:
- use errno.EOPNOTSUPP (Petr)
- move qstat[0] under try (Petr)

v2:
- KTAP output formatting (Jakub)
- defer instead of try/finally (Jakub)
- disappearing stats is an error (Jakub)
- ksft_ge instead of open coding (Jakub)

Signed-off-by: Stanislav Fomichev <sdf@fomichev.me>
Link: https://patch.msgid.link/20240802000309.2368-1-sdf@fomichev.me
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Stanislav Fomichev and committed by
Jakub Kicinski
ab100097 49675f5b

+24 -1
+24 -1
tools/testing/selftests/drivers/net/stats.py
··· 1 1 #!/usr/bin/env python3 2 2 # SPDX-License-Identifier: GPL-2.0 3 3 4 + import errno 4 5 from lib.py import ksft_run, ksft_exit, ksft_pr 5 6 from lib.py import ksft_ge, ksft_eq, ksft_in, ksft_true, ksft_raises, KsftSkipEx, KsftXfailEx 6 7 from lib.py import EthtoolFamily, NetdevFamily, RtnlFamily, NlError 7 8 from lib.py import NetDrvEnv 9 + from lib.py import ip, defer 8 10 9 11 ethnl = EthtoolFamily() 10 12 netfam = NetdevFamily() ··· 135 133 ksft_eq(cm.exception.nl_msg.extack['bad-attr'], '.ifindex') 136 134 137 135 136 + def check_down(cfg) -> None: 137 + try: 138 + qstat = netfam.qstats_get({"ifindex": cfg.ifindex}, dump=True)[0] 139 + except NlError as e: 140 + if e.error == errno.EOPNOTSUPP: 141 + raise KsftSkipEx("qstats not supported by the device") 142 + raise 143 + 144 + ip(f"link set dev {cfg.dev['ifname']} down") 145 + defer(ip, f"link set dev {cfg.dev['ifname']} up") 146 + 147 + qstat2 = netfam.qstats_get({"ifindex": cfg.ifindex}, dump=True)[0] 148 + for k, v in qstat.items(): 149 + ksft_ge(qstat2[k], qstat[k], comment=f"{k} went backwards on device down") 150 + 151 + # exercise per-queue API to make sure that "device down" state 152 + # is handled correctly and doesn't crash 153 + netfam.qstats_get({"ifindex": cfg.ifindex, "scope": "queue"}, dump=True) 154 + 155 + 138 156 def main() -> None: 139 157 with NetDrvEnv(__file__) as cfg: 140 - ksft_run([check_pause, check_fec, pkt_byte_sum, qstat_by_ifindex], 158 + ksft_run([check_pause, check_fec, pkt_byte_sum, qstat_by_ifindex, 159 + check_down], 141 160 args=(cfg, )) 142 161 ksft_exit() 143 162