mirror of
https://github.com/torvalds/linux.git
synced 2026-06-02 19:43:40 +02:00
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>
This commit is contained in:
parent
f857478d62
commit
8a5f956a9f
|
|
@ -19,6 +19,7 @@ TEST_PROGS := \
|
|||
netcons_sysdata.sh \
|
||||
netpoll_basic.py \
|
||||
ping.py \
|
||||
psp.py \
|
||||
queues.py \
|
||||
stats.py \
|
||||
shaper.py \
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
CONFIG_CONFIGFS_FS=y
|
||||
CONFIG_DEBUG_INFO_BTF=y
|
||||
CONFIG_DEBUG_INFO_BTF_MODULES=n
|
||||
CONFIG_INET_PSP=y
|
||||
CONFIG_IPV6=y
|
||||
CONFIG_NETDEVSIM=m
|
||||
CONFIG_NETCONSOLE=m
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ try:
|
|||
|
||||
# Import one by one to avoid pylint false positives
|
||||
from net.lib.py import EthtoolFamily, NetdevFamily, NetshaperFamily, \
|
||||
NlError, RtnlFamily, DevlinkFamily
|
||||
NlError, RtnlFamily, DevlinkFamily, PSPFamily
|
||||
from net.lib.py import CmdExitFailure
|
||||
from net.lib.py import bkg, cmd, defer, ethtool, fd_read_timeout, ip, \
|
||||
rand_port, tool, wait_port_listen
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ try:
|
|||
|
||||
# Import one by one to avoid pylint false positives
|
||||
from net.lib.py import EthtoolFamily, NetdevFamily, NetshaperFamily, \
|
||||
NlError, RtnlFamily, DevlinkFamily
|
||||
NlError, RtnlFamily, DevlinkFamily, PSPFamily
|
||||
from net.lib.py import CmdExitFailure
|
||||
from net.lib.py import bkg, cmd, bpftool, bpftrace, defer, ethtool, \
|
||||
fd_read_timeout, ip, rand_port, tool, wait_port_listen, wait_file
|
||||
|
|
|
|||
83
tools/testing/selftests/drivers/net/psp.py
Executable file
83
tools/testing/selftests/drivers/net/psp.py
Executable file
|
|
@ -0,0 +1,83 @@
|
|||
#!/usr/bin/env python3
|
||||
# SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
"""Test suite for PSP capable drivers."""
|
||||
|
||||
import errno
|
||||
|
||||
from lib.py import defer
|
||||
from lib.py import ksft_run, ksft_exit
|
||||
from lib.py import ksft_true, ksft_eq
|
||||
from lib.py import KsftSkipEx
|
||||
from lib.py import NetDrvEpEnv, PSPFamily, NlError
|
||||
|
||||
#
|
||||
# Test case boiler plate
|
||||
#
|
||||
|
||||
def _init_psp_dev(cfg):
|
||||
if not hasattr(cfg, 'psp_dev_id'):
|
||||
# Figure out which local device we are testing against
|
||||
for dev in cfg.pspnl.dev_get({}, dump=True):
|
||||
if dev['ifindex'] == cfg.ifindex:
|
||||
cfg.psp_info = dev
|
||||
cfg.psp_dev_id = cfg.psp_info['id']
|
||||
break
|
||||
else:
|
||||
raise KsftSkipEx("No PSP devices found")
|
||||
|
||||
# Enable PSP if necessary
|
||||
cap = cfg.psp_info['psp-versions-cap']
|
||||
ena = cfg.psp_info['psp-versions-ena']
|
||||
if cap != ena:
|
||||
cfg.pspnl.dev_set({'id': cfg.psp_dev_id, 'psp-versions-ena': cap})
|
||||
defer(cfg.pspnl.dev_set, {'id': cfg.psp_dev_id,
|
||||
'psp-versions-ena': ena })
|
||||
|
||||
#
|
||||
# Test cases
|
||||
#
|
||||
|
||||
def dev_list_devices(cfg):
|
||||
""" Dump all devices """
|
||||
_init_psp_dev(cfg)
|
||||
|
||||
devices = cfg.pspnl.dev_get({}, dump=True)
|
||||
|
||||
found = False
|
||||
for dev in devices:
|
||||
found |= dev['id'] == cfg.psp_dev_id
|
||||
ksft_true(found)
|
||||
|
||||
|
||||
def dev_get_device(cfg):
|
||||
""" Get the device we intend to use """
|
||||
_init_psp_dev(cfg)
|
||||
|
||||
dev = cfg.pspnl.dev_get({'id': cfg.psp_dev_id})
|
||||
ksft_eq(dev['id'], cfg.psp_dev_id)
|
||||
|
||||
|
||||
def dev_get_device_bad(cfg):
|
||||
""" Test getting device which doesn't exist """
|
||||
raised = False
|
||||
try:
|
||||
cfg.pspnl.dev_get({'id': 1234567})
|
||||
except NlError as e:
|
||||
ksft_eq(e.nl_msg.error, -errno.ENODEV)
|
||||
raised = True
|
||||
ksft_true(raised)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
""" Ksft boiler plate main """
|
||||
|
||||
with NetDrvEpEnv(__file__) as cfg:
|
||||
cfg.pspnl = PSPFamily()
|
||||
|
||||
ksft_run(globs=globals(), case_pfx={"dev_",}, args=(cfg, ))
|
||||
ksft_exit()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
@ -6,4 +6,4 @@ from .netns import NetNS, NetNSEnter
|
|||
from .nsim import *
|
||||
from .utils import *
|
||||
from .ynl import NlError, YnlFamily, EthtoolFamily, NetdevFamily, RtnlFamily, RtnlAddrFamily
|
||||
from .ynl import NetshaperFamily, DevlinkFamily
|
||||
from .ynl import NetshaperFamily, DevlinkFamily, PSPFamily
|
||||
|
|
|
|||
|
|
@ -61,3 +61,8 @@ class DevlinkFamily(YnlFamily):
|
|||
def __init__(self, recv_size=0):
|
||||
super().__init__((SPEC_PATH / Path('devlink.yaml')).as_posix(),
|
||||
schema='', recv_size=recv_size)
|
||||
|
||||
class PSPFamily(YnlFamily):
|
||||
def __init__(self, recv_size=0):
|
||||
super().__init__((SPEC_PATH / Path('psp.yaml')).as_posix(),
|
||||
schema='', recv_size=recv_size)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user