netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
	shuah@kernel.org, petrm@nvidia.com,
	linux-kselftest@vger.kernel.org, Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next 6/6] selftests: net: exercise page pool reporting via netlink
Date: Wed, 10 Apr 2024 18:28:15 -0700	[thread overview]
Message-ID: <20240411012815.174400-7-kuba@kernel.org> (raw)
In-Reply-To: <20240411012815.174400-1-kuba@kernel.org>

Add a Python test for the basic ops.

  # ./net/nl_netdev.py
  KTAP version 1
  1..3
  ok 1 nl_netdev.empty_check
  ok 2 nl_netdev.lo_check
  ok 3 nl_netdev.page_pool_check
  # Totals: pass:3 fail:0 xfail:0 xpass:0 skip:0 error:0

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 tools/testing/selftests/net/lib/py/nsim.py |  7 ++
 tools/testing/selftests/net/nl_netdev.py   | 79 +++++++++++++++++++++-
 2 files changed, 84 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/net/lib/py/nsim.py b/tools/testing/selftests/net/lib/py/nsim.py
index 94aa32f59fdb..1fd50a308408 100644
--- a/tools/testing/selftests/net/lib/py/nsim.py
+++ b/tools/testing/selftests/net/lib/py/nsim.py
@@ -28,6 +28,13 @@ from .utils import cmd, ip
         self.dfs_dir = "%s/ports/%u/" % (nsimdev.dfs_dir, port_index)
         ret = ip("-j link show dev %s" % ifname, ns=ns)
         self.dev = json.loads(ret.stdout)[0]
+        self.ifindex = self.dev["ifindex"]
+
+    def up(self):
+        ip("link set dev {} up".format(self.ifname))
+
+    def down(self):
+        ip("link set dev {} down".format(self.ifname))
 
     def dfs_write(self, path, val):
         self.nsimdev.dfs_write(f'ports/{self.port_index}/' + path, val)
diff --git a/tools/testing/selftests/net/nl_netdev.py b/tools/testing/selftests/net/nl_netdev.py
index 2b8b488fb419..afc510c044ce 100755
--- a/tools/testing/selftests/net/nl_netdev.py
+++ b/tools/testing/selftests/net/nl_netdev.py
@@ -1,7 +1,8 @@
 #!/usr/bin/env python3
 # SPDX-License-Identifier: GPL-2.0
 
-from lib.py import ksft_run, ksft_pr, ksft_eq, ksft_ge, NetdevFamily
+import time
+from lib.py import ksft_run, ksft_pr, ksft_eq, ksft_ge, NetdevFamily, NetdevSimDev, ip
 
 
 def empty_check(nf) -> None:
@@ -15,9 +16,83 @@ from lib.py import ksft_run, ksft_pr, ksft_eq, ksft_ge, NetdevFamily
     ksft_eq(len(lo_info['xdp-rx-metadata-features']), 0)
 
 
+def page_pool_check(nf) -> None:
+    with NetdevSimDev() as nsimdev:
+        nsim = nsimdev.nsims[0]
+
+        # No page pools when down
+        nsim.down()
+        pp_list = nf.page_pool_get({}, dump=True)
+        pp_list = [pp for pp in pp_list if pp.get("ifindex") == nsim.ifindex]
+        ksft_eq(len(pp_list), 0)
+
+        # Up, empty page pool appears
+        nsim.up()
+        pp_list = nf.page_pool_get({}, dump=True)
+        pp_list = [pp for pp in pp_list if pp.get("ifindex") == nsim.ifindex]
+        ksft_ge(len(pp_list), 0)
+        refs = sum([pp["inflight"] for pp in pp_list])
+        ksft_eq(refs, 0)
+
+        # Down, it disappears, again
+        nsim.down()
+        pp_list = nf.page_pool_get({}, dump=True)
+        pp_list = [pp for pp in pp_list if pp.get("ifindex") == nsim.ifindex]
+        ksft_eq(len(pp_list), 0)
+
+        # Up, allocate a page
+        nsim.up()
+        nsim.dfs_write("pp_hold", "y")
+        pp_list = nf.page_pool_get({}, dump=True)
+        refs = sum([pp["inflight"] for pp in pp_list if pp.get("ifindex") == nsim.ifindex])
+        ksft_ge(refs, 1)
+
+        # Now let's leak a page
+        nsim.down()
+        pp_list = nf.page_pool_get({}, dump=True)
+        pp_list = [pp for pp in pp_list if pp.get("ifindex") == nsim.ifindex]
+        ksft_eq(len(pp_list), 1)
+        refs = sum([pp["inflight"] for pp in pp_list if pp.get("ifindex") == nsim.ifindex])
+        ksft_eq(refs, 1)
+        undetached = [pp for pp in pp_list if "detach-time" not in pp]
+        ksft_eq(len(undetached), 0)
+
+        # New pp can get created, and we'll have two
+        nsim.up()
+        pp_list = nf.page_pool_get({}, dump=True)
+        pp_list = [pp for pp in pp_list if pp.get("ifindex") == nsim.ifindex]
+        attached = [pp for pp in pp_list if "detach-time" not in pp]
+        undetached = [pp for pp in pp_list if "detach-time" in pp]
+        ksft_eq(len(attached), 1)
+        ksft_eq(len(undetached), 1)
+
+        # Free the old page and the old pp is gone
+        nsim.dfs_write("pp_hold", "n")
+        # Freeing check is once a second so we may need to retry
+        for i in range(50):
+            pp_list = nf.page_pool_get({}, dump=True)
+            pp_list = [pp for pp in pp_list if pp.get("ifindex") == nsim.ifindex]
+            if len(pp_list) == 1:
+                break
+            time.sleep(0.05)
+        ksft_eq(len(pp_list), 1)
+
+        # And down...
+        nsim.down()
+        pp_list = nf.page_pool_get({}, dump=True)
+        pp_list = [pp for pp in pp_list if pp.get("ifindex") == nsim.ifindex]
+        ksft_eq(len(pp_list), 0)
+
+        # Last, leave the page hanging for destroy, nothing to check
+        # we're trying to exercise the orphaning path in the kernel
+        nsim.up()
+        nsim.dfs_write("pp_hold", "y")
+
+
 def main() -> None:
     nf = NetdevFamily()
-    ksft_run([empty_check, lo_check], args=(nf, ))
+    ksft_run([empty_check, lo_check, page_pool_check],
+             args=(nf, ))
 
 
 if __name__ == "__main__":
-- 
2.44.0


  parent reply	other threads:[~2024-04-11  1:28 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-11  1:28 [PATCH net-next 0/6] selftests: net: exercise page pool reporting via netlink Jakub Kicinski
2024-04-11  1:28 ` [PATCH net-next 1/6] net: netdevsim: add some fake page pool use Jakub Kicinski
2024-04-11  1:28 ` [PATCH net-next 2/6] tools: ynl: don't return None for dumps Jakub Kicinski
2024-04-11 10:12   ` Donald Hunter
2024-04-11  1:28 ` [PATCH net-next 3/6] selftests: net: print report check location in python tests Jakub Kicinski
2024-04-12  7:45   ` Petr Machata
2024-04-11  1:28 ` [PATCH net-next 4/6] selftests: net: print full exception on failure Jakub Kicinski
2024-04-12  8:02   ` Petr Machata
2024-04-11  1:28 ` [PATCH net-next 5/6] selftests: net: support use of NetdevSimDev under "with" in python Jakub Kicinski
2024-04-12  8:07   ` Petr Machata
2024-04-11  1:28 ` Jakub Kicinski [this message]
2024-04-12  8:20   ` [PATCH net-next 6/6] selftests: net: exercise page pool reporting via netlink Petr Machata
2024-04-12 13:48     ` Jakub Kicinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240411012815.174400-7-kuba@kernel.org \
    --to=kuba@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=petrm@nvidia.com \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).