Skip to content

Commit ab10009

Browse files
Stanislav Fomichevkuba-moo
authored andcommitted
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 <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 49675f5 commit ab10009

File tree

1 file changed

+24
-1
lines changed
  • tools/testing/selftests/drivers/net

1 file changed

+24
-1
lines changed

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

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

4+
import errno
45
from lib.py import ksft_run, ksft_exit, ksft_pr
56
from lib.py import ksft_ge, ksft_eq, ksft_in, ksft_true, ksft_raises, KsftSkipEx, KsftXfailEx
67
from lib.py import EthtoolFamily, NetdevFamily, RtnlFamily, NlError
78
from lib.py import NetDrvEnv
9+
from lib.py import ip, defer
810

911
ethnl = EthtoolFamily()
1012
netfam = NetdevFamily()
@@ -133,9 +135,30 @@ def qstat_by_ifindex(cfg) -> None:
133135
ksft_eq(cm.exception.nl_msg.extack['bad-attr'], '.ifindex')
134136

135137

138+
def check_down(cfg) -> None:
139+
try:
140+
qstat = netfam.qstats_get({"ifindex": cfg.ifindex}, dump=True)[0]
141+
except NlError as e:
142+
if e.error == errno.EOPNOTSUPP:
143+
raise KsftSkipEx("qstats not supported by the device")
144+
raise
145+
146+
ip(f"link set dev {cfg.dev['ifname']} down")
147+
defer(ip, f"link set dev {cfg.dev['ifname']} up")
148+
149+
qstat2 = netfam.qstats_get({"ifindex": cfg.ifindex}, dump=True)[0]
150+
for k, v in qstat.items():
151+
ksft_ge(qstat2[k], qstat[k], comment=f"{k} went backwards on device down")
152+
153+
# exercise per-queue API to make sure that "device down" state
154+
# is handled correctly and doesn't crash
155+
netfam.qstats_get({"ifindex": cfg.ifindex, "scope": "queue"}, dump=True)
156+
157+
136158
def main() -> None:
137159
with NetDrvEnv(__file__) as cfg:
138-
ksft_run([check_pause, check_fec, pkt_byte_sum, qstat_by_ifindex],
160+
ksft_run([check_pause, check_fec, pkt_byte_sum, qstat_by_ifindex,
161+
check_down],
139162
args=(cfg, ))
140163
ksft_exit()
141164

0 commit comments

Comments
 (0)