Skip to content

Commit b3820e0

Browse files
kuba-mooPaolo Abeni
authored andcommitted
selftests: drv-net: psp: add tests for destroying devices
Add tests for making sure device can disappear while associations exist. This is netdevsim-only since destroying real devices is more tricky. Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Daniel Zahka <[email protected]> Link: https://patch.msgid.link/[email protected] Reviewed-by: Willem de Bruijn <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 81236c7 commit b3820e0

File tree

5 files changed

+68
-3
lines changed

5 files changed

+68
-3
lines changed

tools/testing/selftests/drivers/net/hw/lib/py/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from net.lib.py import ksft_disruptive, ksft_exit, ksft_pr, ksft_run, \
2323
ksft_setup
2424
from net.lib.py import ksft_eq, ksft_ge, ksft_in, ksft_is, ksft_lt, \
25-
ksft_ne, ksft_not_in, ksft_raises, ksft_true, ksft_gt
25+
ksft_ne, ksft_not_in, ksft_raises, ksft_true, ksft_gt, ksft_not_none
2626
from net.lib.py import NetNSEnter
2727
from drivers.net.lib.py import GenerateTraffic
2828
from drivers.net.lib.py import NetDrvEnv, NetDrvEpEnv

tools/testing/selftests/drivers/net/lib/py/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from net.lib.py import ksft_disruptive, ksft_exit, ksft_pr, ksft_run, \
2222
ksft_setup
2323
from net.lib.py import ksft_eq, ksft_ge, ksft_in, ksft_is, ksft_lt, \
24-
ksft_ne, ksft_not_in, ksft_raises, ksft_true, ksft_gt
24+
ksft_ne, ksft_not_in, ksft_raises, ksft_true, ksft_gt, ksft_not_none
2525
except ModuleNotFoundError as e:
2626
ksft_pr("Failed importing `net` library from kernel sources")
2727
ksft_pr(str(e))

tools/testing/selftests/drivers/net/lib/py/env.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ def require_ipver(self, ipver):
245245
if not self.addr_v[ipver] or not self.remote_addr_v[ipver]:
246246
raise KsftSkipEx(f"Test requires IPv{ipver} connectivity")
247247

248+
def require_nsim(self):
249+
if self._ns is None:
250+
raise KsftXfailEx("Test only works on netdevsim")
251+
248252
def _require_cmd(self, comm, key, host=None):
249253
cached = self._required_cmd.get(comm, {})
250254
if cached.get(key) is None:

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

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from lib.py import defer
1414
from lib.py import ksft_run, ksft_exit, ksft_pr
1515
from lib.py import ksft_true, ksft_eq, ksft_ne, ksft_gt, ksft_raises
16+
from lib.py import ksft_not_none
1617
from lib.py import KsftSkipEx
1718
from lib.py import NetDrvEpEnv, PSPFamily, NlError
1819
from lib.py import bkg, rand_port, wait_port_listen
@@ -500,6 +501,61 @@ def data_stale_key(cfg):
500501
_close_psp_conn(cfg, s)
501502

502503

504+
def __nsim_psp_rereg(cfg):
505+
# The PSP dev ID will change, remember what was there before
506+
before = set([x['id'] for x in cfg.pspnl.dev_get({}, dump=True)])
507+
508+
cfg._ns.nsims[0].dfs_write('psp_rereg', '1')
509+
510+
after = set([x['id'] for x in cfg.pspnl.dev_get({}, dump=True)])
511+
512+
new_devs = list(after - before)
513+
ksft_eq(len(new_devs), 1)
514+
cfg.psp_dev_id = list(after - before)[0]
515+
516+
517+
def removal_device_rx(cfg):
518+
""" Test removing a netdev / PSD with active Rx assoc """
519+
520+
# We could technically devlink reload real devices, too
521+
# but that kills the control socket. So test this on
522+
# netdevsim only for now
523+
cfg.require_nsim()
524+
525+
s = _make_clr_conn(cfg)
526+
try:
527+
rx_assoc = cfg.pspnl.rx_assoc({"version": 0,
528+
"dev-id": cfg.psp_dev_id,
529+
"sock-fd": s.fileno()})
530+
ksft_not_none(rx_assoc)
531+
532+
__nsim_psp_rereg(cfg)
533+
finally:
534+
_close_conn(cfg, s)
535+
536+
537+
def removal_device_bi(cfg):
538+
""" Test removing a netdev / PSD with active Rx/Tx assoc """
539+
540+
# We could technically devlink reload real devices, too
541+
# but that kills the control socket. So test this on
542+
# netdevsim only for now
543+
cfg.require_nsim()
544+
545+
s = _make_clr_conn(cfg)
546+
try:
547+
rx_assoc = cfg.pspnl.rx_assoc({"version": 0,
548+
"dev-id": cfg.psp_dev_id,
549+
"sock-fd": s.fileno()})
550+
cfg.pspnl.tx_assoc({"dev-id": cfg.psp_dev_id,
551+
"version": 0,
552+
"tx-key": rx_assoc['rx-key'],
553+
"sock-fd": s.fileno()})
554+
__nsim_psp_rereg(cfg)
555+
finally:
556+
_close_conn(cfg, s)
557+
558+
503559
def psp_ip_ver_test_builder(name, test_func, psp_ver, ipver):
504560
"""Build test cases for each combo of PSP version and IP version"""
505561
def test_case(cfg):
@@ -551,7 +607,7 @@ def main() -> None:
551607
]
552608

553609
ksft_run(cases=cases, globs=globals(),
554-
case_pfx={"dev_", "data_", "assoc_"},
610+
case_pfx={"dev_", "data_", "assoc_", "removal_"},
555611
args=(cfg, ))
556612

557613
cfg.comm_sock.send(b"exit\0")

tools/testing/selftests/net/lib/py/ksft.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ def ksft_true(a, comment=""):
7272
_fail("Check failed", a, "does not eval to True", comment)
7373

7474

75+
def ksft_not_none(a, comment=""):
76+
if a is None:
77+
_fail("Check failed", a, "is None", comment)
78+
79+
7580
def ksft_in(a, b, comment=""):
7681
if a not in b:
7782
_fail("Check failed", a, "not in", b, comment)

0 commit comments

Comments
 (0)