[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240416051527.1657233-3-dw@davidwei.uk>
Date: Mon, 15 Apr 2024 22:15:27 -0700
From: David Wei <dw@...idwei.uk>
To: netdev@...r.kernel.org
Cc: Jakub Kicinski <kuba@...nel.org>,
"David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Paolo Abeni <pabeni@...hat.com>
Subject: [PATCH v1 2/2] net: selftest: add test for netdev netlink queue-get API
Add a selftest for Netdev Netlink queue-get API. The ground truth is
determined by sysfs.
The test works with netdevsim by default or with a real device by
setting NETIF.
Minor changes to NetdevSimDev to accept the number of queues to create
per port and pass through NetdevSimDev args in NetDrvEnv ctor.
Signed-off-by: David Wei <dw@...idwei.uk>
---
tools/testing/selftests/drivers/net/Makefile | 1 +
.../selftests/drivers/net/lib/py/env.py | 10 ++-
tools/testing/selftests/drivers/net/queues.py | 67 +++++++++++++++++++
tools/testing/selftests/net/lib/py/nsim.py | 4 +-
4 files changed, 78 insertions(+), 4 deletions(-)
create mode 100755 tools/testing/selftests/drivers/net/queues.py
diff --git a/tools/testing/selftests/drivers/net/Makefile b/tools/testing/selftests/drivers/net/Makefile
index 379cdb1960a7..118a73650dbc 100644
--- a/tools/testing/selftests/drivers/net/Makefile
+++ b/tools/testing/selftests/drivers/net/Makefile
@@ -3,5 +3,6 @@
TEST_INCLUDES := $(wildcard lib/py/*.py)
TEST_PROGS := stats.py
+TEST_PROGS += queues.py
include ../../lib.mk
diff --git a/tools/testing/selftests/drivers/net/lib/py/env.py b/tools/testing/selftests/drivers/net/lib/py/env.py
index e1abe9491daf..7187aca5c516 100644
--- a/tools/testing/selftests/drivers/net/lib/py/env.py
+++ b/tools/testing/selftests/drivers/net/lib/py/env.py
@@ -7,7 +7,7 @@ from lib.py import ip
from lib.py import NetdevSimDev
class NetDrvEnv:
- def __init__(self, src_path):
+ def __init__(self, src_path, **kwargs):
self._ns = None
self.env = os.environ.copy()
@@ -16,7 +16,7 @@ class NetDrvEnv:
if 'NETIF' in self.env:
self.dev = ip("link show dev " + self.env['NETIF'], json=True)[0]
else:
- self._ns = NetdevSimDev()
+ self._ns = NetdevSimDev(**kwargs)
self.dev = self._ns.nsims[0].dev
self.ifindex = self.dev['ifindex']
@@ -50,3 +50,9 @@ class NetDrvEnv:
else:
self.env[k] = token
k = None
+
+ def dev_up(self):
+ ip(f"link set dev {self.dev['ifname']} up")
+
+ def dev_down(self):
+ ip(f"link set dev {self.dev['ifname']} down")
diff --git a/tools/testing/selftests/drivers/net/queues.py b/tools/testing/selftests/drivers/net/queues.py
new file mode 100755
index 000000000000..de2820f2759a
--- /dev/null
+++ b/tools/testing/selftests/drivers/net/queues.py
@@ -0,0 +1,67 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+from lib.py import ksft_run, ksft_in, ksft_true, ksft_eq, KsftSkipEx, KsftXfailEx
+from lib.py import NetdevFamily, NlError
+from lib.py import NetDrvEnv
+from lib.py import cmd
+import glob
+
+netnl = NetdevFamily()
+
+
+def sys_get_queues(ifname) -> int:
+ folders = glob.glob(f'/sys/class/net/{ifname}/queues/rx-*')
+ return len(folders)
+
+
+def nl_get_queues(cfg):
+ global netnl
+ queues = netnl.queue_get({'ifindex': cfg.ifindex}, dump=True)
+ if queues:
+ return len([q for q in queues if q['type'] == 'rx'])
+ return None
+
+
+def get_queues(cfg) -> None:
+ global netnl
+
+ queues = nl_get_queues(cfg)
+ if not queues:
+ raise KsftSkipEx("queue-get not supported by device")
+
+ expected = sys_get_queues(cfg.dev['ifname'])
+ ksft_eq(queues, expected)
+
+
+def addremove_queues(cfg) -> None:
+ global netnl
+
+ queues = nl_get_queues(cfg)
+ if not queues:
+ raise KsftSkipEx("queue-get not supported by device")
+
+ expected = sys_get_queues(cfg.dev['ifname'])
+ ksft_eq(queues, expected)
+
+ # reduce queue count by 1
+ expected = expected - 1
+ cmd(f"ethtool -L {cfg.dev['ifname']} combined {expected}")
+ queues = nl_get_queues(cfg)
+ ksft_eq(queues, expected)
+
+ # increase queue count by 1
+ expected = expected + 1
+ cmd(f"ethtool -L {cfg.dev['ifname']} combined {expected}")
+ queues = nl_get_queues(cfg)
+ ksft_eq(queues, expected)
+
+
+def main() -> None:
+ with NetDrvEnv(__file__, queue_count=3) as cfg:
+ cfg.dev_up()
+ ksft_run([get_queues, addremove_queues], args=(cfg, ))
+
+
+if __name__ == "__main__":
+ main()
diff --git a/tools/testing/selftests/net/lib/py/nsim.py b/tools/testing/selftests/net/lib/py/nsim.py
index 06896cdf7c18..f571a8b3139b 100644
--- a/tools/testing/selftests/net/lib/py/nsim.py
+++ b/tools/testing/selftests/net/lib/py/nsim.py
@@ -49,7 +49,7 @@ class NetdevSimDev:
with open(fullpath, "w") as f:
f.write(val)
- def __init__(self, port_count=1, ns=None):
+ def __init__(self, port_count=1, queue_count=1, ns=None):
# nsim will spawn in init_net, we'll set to actual ns once we switch it there
self.ns = None
@@ -59,7 +59,7 @@ class NetdevSimDev:
addr = random.randrange(1 << 15)
while True:
try:
- self.ctrl_write("new_device", "%u %u" % (addr, port_count))
+ self.ctrl_write("new_device", "%u %u %u" % (addr, port_count, queue_count))
except OSError as e:
if e.errno == errno.ENOSPC:
addr = random.randrange(1 << 15)
--
2.43.0
Powered by blists - more mailing lists