~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/net/nl_netdev.py

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #!/usr/bin/env python3
  2 # SPDX-License-Identifier: GPL-2.0
  3 
  4 import time
  5 from lib.py import ksft_run, ksft_exit, ksft_pr
  6 from lib.py import ksft_eq, ksft_ge, ksft_busy_wait
  7 from lib.py import NetdevFamily, NetdevSimDev, ip
  8 
  9 
 10 def empty_check(nf) -> None:
 11     devs = nf.dev_get({}, dump=True)
 12     ksft_ge(len(devs), 1)
 13 
 14 
 15 def lo_check(nf) -> None:
 16     lo_info = nf.dev_get({"ifindex": 1})
 17     ksft_eq(len(lo_info['xdp-features']), 0)
 18     ksft_eq(len(lo_info['xdp-rx-metadata-features']), 0)
 19 
 20 
 21 def page_pool_check(nf) -> None:
 22     with NetdevSimDev() as nsimdev:
 23         nsim = nsimdev.nsims[0]
 24 
 25         def up():
 26             ip(f"link set dev {nsim.ifname} up")
 27 
 28         def down():
 29             ip(f"link set dev {nsim.ifname} down")
 30 
 31         def get_pp():
 32             pp_list = nf.page_pool_get({}, dump=True)
 33             return [pp for pp in pp_list if pp.get("ifindex") == nsim.ifindex]
 34 
 35         # No page pools when down
 36         down()
 37         ksft_eq(len(get_pp()), 0)
 38 
 39         # Up, empty page pool appears
 40         up()
 41         pp_list = get_pp()
 42         ksft_ge(len(pp_list), 0)
 43         refs = sum([pp["inflight"] for pp in pp_list])
 44         ksft_eq(refs, 0)
 45 
 46         # Down, it disappears, again
 47         down()
 48         pp_list = get_pp()
 49         ksft_eq(len(pp_list), 0)
 50 
 51         # Up, allocate a page
 52         up()
 53         nsim.dfs_write("pp_hold", "y")
 54         pp_list = nf.page_pool_get({}, dump=True)
 55         refs = sum([pp["inflight"] for pp in pp_list if pp.get("ifindex") == nsim.ifindex])
 56         ksft_ge(refs, 1)
 57 
 58         # Now let's leak a page
 59         down()
 60         pp_list = get_pp()
 61         ksft_eq(len(pp_list), 1)
 62         refs = sum([pp["inflight"] for pp in pp_list])
 63         ksft_eq(refs, 1)
 64         attached = [pp for pp in pp_list if "detach-time" not in pp]
 65         ksft_eq(len(attached), 0)
 66 
 67         # New pp can get created, and we'll have two
 68         up()
 69         pp_list = get_pp()
 70         attached = [pp for pp in pp_list if "detach-time" not in pp]
 71         detached = [pp for pp in pp_list if "detach-time" in pp]
 72         ksft_eq(len(attached), 1)
 73         ksft_eq(len(detached), 1)
 74 
 75         # Free the old page and the old pp is gone
 76         nsim.dfs_write("pp_hold", "n")
 77         # Freeing check is once a second so we may need to retry
 78         ksft_busy_wait(lambda: len(get_pp()) == 1, deadline=2)
 79 
 80         # And down...
 81         down()
 82         ksft_eq(len(get_pp()), 0)
 83 
 84         # Last, leave the page hanging for destroy, nothing to check
 85         # we're trying to exercise the orphaning path in the kernel
 86         up()
 87         nsim.dfs_write("pp_hold", "y")
 88 
 89 
 90 def main() -> None:
 91     nf = NetdevFamily()
 92     ksft_run([empty_check, lo_check, page_pool_check],
 93              args=(nf, ))
 94     ksft_exit()
 95 
 96 
 97 if __name__ == "__main__":
 98     main()

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php