Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: drv-net: base device access API test

Simple PSP test to getting info about PSP devices.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Daniel Zahka <daniel.zahka@gmail.com>
Link: https://patch.msgid.link/20250927225420.1443468-3-kuba@kernel.org
Reviewed-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Jakub Kicinski and committed by
Paolo Abeni
8a5f956a f857478d

+93 -3
+1
tools/testing/selftests/drivers/net/Makefile
··· 19 19 netcons_sysdata.sh \ 20 20 netpoll_basic.py \ 21 21 ping.py \ 22 + psp.py \ 22 23 queues.py \ 23 24 stats.py \ 24 25 shaper.py \
+1
tools/testing/selftests/drivers/net/config
··· 1 1 CONFIG_CONFIGFS_FS=y 2 2 CONFIG_DEBUG_INFO_BTF=y 3 3 CONFIG_DEBUG_INFO_BTF_MODULES=n 4 + CONFIG_INET_PSP=y 4 5 CONFIG_IPV6=y 5 6 CONFIG_NETDEVSIM=m 6 7 CONFIG_NETCONSOLE=m
+1 -1
tools/testing/selftests/drivers/net/hw/lib/py/__init__.py
··· 13 13 14 14 # Import one by one to avoid pylint false positives 15 15 from net.lib.py import EthtoolFamily, NetdevFamily, NetshaperFamily, \ 16 - NlError, RtnlFamily, DevlinkFamily 16 + NlError, RtnlFamily, DevlinkFamily, PSPFamily 17 17 from net.lib.py import CmdExitFailure 18 18 from net.lib.py import bkg, cmd, defer, ethtool, fd_read_timeout, ip, \ 19 19 rand_port, tool, wait_port_listen
+1 -1
tools/testing/selftests/drivers/net/lib/py/__init__.py
··· 12 12 13 13 # Import one by one to avoid pylint false positives 14 14 from net.lib.py import EthtoolFamily, NetdevFamily, NetshaperFamily, \ 15 - NlError, RtnlFamily, DevlinkFamily 15 + NlError, RtnlFamily, DevlinkFamily, PSPFamily 16 16 from net.lib.py import CmdExitFailure 17 17 from net.lib.py import bkg, cmd, bpftool, bpftrace, defer, ethtool, \ 18 18 fd_read_timeout, ip, rand_port, tool, wait_port_listen, wait_file
+83
tools/testing/selftests/drivers/net/psp.py
··· 1 + #!/usr/bin/env python3 2 + # SPDX-License-Identifier: GPL-2.0 3 + 4 + """Test suite for PSP capable drivers.""" 5 + 6 + import errno 7 + 8 + from lib.py import defer 9 + from lib.py import ksft_run, ksft_exit 10 + from lib.py import ksft_true, ksft_eq 11 + from lib.py import KsftSkipEx 12 + from lib.py import NetDrvEpEnv, PSPFamily, NlError 13 + 14 + # 15 + # Test case boiler plate 16 + # 17 + 18 + def _init_psp_dev(cfg): 19 + if not hasattr(cfg, 'psp_dev_id'): 20 + # Figure out which local device we are testing against 21 + for dev in cfg.pspnl.dev_get({}, dump=True): 22 + if dev['ifindex'] == cfg.ifindex: 23 + cfg.psp_info = dev 24 + cfg.psp_dev_id = cfg.psp_info['id'] 25 + break 26 + else: 27 + raise KsftSkipEx("No PSP devices found") 28 + 29 + # Enable PSP if necessary 30 + cap = cfg.psp_info['psp-versions-cap'] 31 + ena = cfg.psp_info['psp-versions-ena'] 32 + if cap != ena: 33 + cfg.pspnl.dev_set({'id': cfg.psp_dev_id, 'psp-versions-ena': cap}) 34 + defer(cfg.pspnl.dev_set, {'id': cfg.psp_dev_id, 35 + 'psp-versions-ena': ena }) 36 + 37 + # 38 + # Test cases 39 + # 40 + 41 + def dev_list_devices(cfg): 42 + """ Dump all devices """ 43 + _init_psp_dev(cfg) 44 + 45 + devices = cfg.pspnl.dev_get({}, dump=True) 46 + 47 + found = False 48 + for dev in devices: 49 + found |= dev['id'] == cfg.psp_dev_id 50 + ksft_true(found) 51 + 52 + 53 + def dev_get_device(cfg): 54 + """ Get the device we intend to use """ 55 + _init_psp_dev(cfg) 56 + 57 + dev = cfg.pspnl.dev_get({'id': cfg.psp_dev_id}) 58 + ksft_eq(dev['id'], cfg.psp_dev_id) 59 + 60 + 61 + def dev_get_device_bad(cfg): 62 + """ Test getting device which doesn't exist """ 63 + raised = False 64 + try: 65 + cfg.pspnl.dev_get({'id': 1234567}) 66 + except NlError as e: 67 + ksft_eq(e.nl_msg.error, -errno.ENODEV) 68 + raised = True 69 + ksft_true(raised) 70 + 71 + 72 + def main() -> None: 73 + """ Ksft boiler plate main """ 74 + 75 + with NetDrvEpEnv(__file__) as cfg: 76 + cfg.pspnl = PSPFamily() 77 + 78 + ksft_run(globs=globals(), case_pfx={"dev_",}, args=(cfg, )) 79 + ksft_exit() 80 + 81 + 82 + if __name__ == "__main__": 83 + main()
+1 -1
tools/testing/selftests/net/lib/py/__init__.py
··· 6 6 from .nsim import * 7 7 from .utils import * 8 8 from .ynl import NlError, YnlFamily, EthtoolFamily, NetdevFamily, RtnlFamily, RtnlAddrFamily 9 - from .ynl import NetshaperFamily, DevlinkFamily 9 + from .ynl import NetshaperFamily, DevlinkFamily, PSPFamily
+5
tools/testing/selftests/net/lib/py/ynl.py
··· 61 61 def __init__(self, recv_size=0): 62 62 super().__init__((SPEC_PATH / Path('devlink.yaml')).as_posix(), 63 63 schema='', recv_size=recv_size) 64 + 65 + class PSPFamily(YnlFamily): 66 + def __init__(self, recv_size=0): 67 + super().__init__((SPEC_PATH / Path('psp.yaml')).as_posix(), 68 + schema='', recv_size=recv_size)