All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next 1/2] selftests: net-drv: exercise queue stats when the device is down
@ 2024-07-29 22:10 Stanislav Fomichev
  2024-07-29 22:10 ` [PATCH net-next 2/2] selftests: net: ksft: support marking tests as disruptive Stanislav Fomichev
  2024-07-30  1:58 ` [PATCH net-next 1/2] selftests: net-drv: exercise queue stats when the device is down Jakub Kicinski
  0 siblings, 2 replies; 6+ messages in thread
From: Stanislav Fomichev @ 2024-07-29 22:10 UTC (permalink / raw)
  To: netdev
  Cc: davem, edumazet, kuba, pabeni, Shuah Khan, Joe Damato,
	Petr Machata, linux-kselftest

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

Signed-off-by: Stanislav Fomichev <sdf@fomichev.me>
--
Cc: Shuah Khan <shuah@kernel.org>
Cc: Joe Damato <jdamato@fastly.com>
Cc: Petr Machata <petrm@nvidia.com>
Cc: linux-kselftest@vger.kernel.org
---
 tools/testing/selftests/drivers/net/stats.py | 31 +++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/drivers/net/stats.py b/tools/testing/selftests/drivers/net/stats.py
index 820b8e0a22c6..6f8bef379565 100755
--- a/tools/testing/selftests/drivers/net/stats.py
+++ b/tools/testing/selftests/drivers/net/stats.py
@@ -5,6 +5,7 @@ from lib.py import ksft_run, ksft_exit, ksft_pr
 from lib.py import ksft_ge, ksft_eq, ksft_in, ksft_true, ksft_raises, KsftSkipEx, KsftXfailEx
 from lib.py import EthtoolFamily, NetdevFamily, RtnlFamily, NlError
 from lib.py import NetDrvEnv
+from lib.py import ip
 
 ethnl = EthtoolFamily()
 netfam = NetdevFamily()
@@ -133,9 +134,37 @@ rtnl = RtnlFamily()
     ksft_eq(cm.exception.nl_msg.extack['bad-attr'], '.ifindex')
 
 
+def check_down(cfg) -> None:
+    try:
+        qstat = netfam.qstats_get({"ifindex": cfg.ifindex}, dump=True)
+    except NlError as e:
+        if e.error == 95:
+            raise KsftSkipEx("qstats not supported by the device")
+        raise
+
+    ip(f"link set dev {cfg.dev['ifname']} down")
+
+    try:
+        qstat = qstat[0]
+        qstat2 = netfam.qstats_get({"ifindex": cfg.ifindex}, dump=True)[0]
+        for k, v in qstat.items():
+            if k not in qstat2:
+                # skip the stats that are not globally preserved
+                continue
+            if qstat2[k] < qstat[k]:
+                raise Exception(f"{k} ({qstat2[k]}) should be preserved but has lower value ({qstat[k]}) when the device is down")
+
+        # exercise per-queue API to make sure that "device down" state
+        # is handled correctly and doesn't crash
+        netfam.qstats_get({"ifindex": cfg.ifindex, "scope": "queue"}, dump=True)
+    finally:
+        ip(f"link set dev {cfg.dev['ifname']} up")
+
+
 def main() -> None:
     with NetDrvEnv(__file__) as cfg:
-        ksft_run([check_pause, check_fec, pkt_byte_sum, qstat_by_ifindex],
+        ksft_run([check_pause, check_fec, pkt_byte_sum, qstat_by_ifindex,
+                  check_down],
                  args=(cfg, ))
     ksft_exit()
 
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-07-30 18:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-29 22:10 [PATCH net-next 1/2] selftests: net-drv: exercise queue stats when the device is down Stanislav Fomichev
2024-07-29 22:10 ` [PATCH net-next 2/2] selftests: net: ksft: support marking tests as disruptive Stanislav Fomichev
2024-07-30  2:00   ` Jakub Kicinski
2024-07-30 16:20     ` Stanislav Fomichev
2024-07-30 18:13       ` Jakub Kicinski
2024-07-30  1:58 ` [PATCH net-next 1/2] selftests: net-drv: exercise queue stats when the device is down Jakub Kicinski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.