Skip to content

Commit 8a5f956

Browse files
kuba-mooPaolo Abeni
authored andcommitted
selftests: drv-net: base device access API test
Simple PSP test to getting info about PSP devices. 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 f857478 commit 8a5f956

File tree

7 files changed

+93
-3
lines changed

7 files changed

+93
-3
lines changed

tools/testing/selftests/drivers/net/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ TEST_PROGS := \
1919
netcons_sysdata.sh \
2020
netpoll_basic.py \
2121
ping.py \
22+
psp.py \
2223
queues.py \
2324
stats.py \
2425
shaper.py \

tools/testing/selftests/drivers/net/config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
CONFIG_CONFIGFS_FS=y
22
CONFIG_DEBUG_INFO_BTF=y
33
CONFIG_DEBUG_INFO_BTF_MODULES=n
4+
CONFIG_INET_PSP=y
45
CONFIG_IPV6=y
56
CONFIG_NETDEVSIM=m
67
CONFIG_NETCONSOLE=m

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
# Import one by one to avoid pylint false positives
1515
from net.lib.py import EthtoolFamily, NetdevFamily, NetshaperFamily, \
16-
NlError, RtnlFamily, DevlinkFamily
16+
NlError, RtnlFamily, DevlinkFamily, PSPFamily
1717
from net.lib.py import CmdExitFailure
1818
from net.lib.py import bkg, cmd, defer, ethtool, fd_read_timeout, ip, \
1919
rand_port, tool, wait_port_listen

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
# Import one by one to avoid pylint false positives
1414
from net.lib.py import EthtoolFamily, NetdevFamily, NetshaperFamily, \
15-
NlError, RtnlFamily, DevlinkFamily
15+
NlError, RtnlFamily, DevlinkFamily, PSPFamily
1616
from net.lib.py import CmdExitFailure
1717
from net.lib.py import bkg, cmd, bpftool, bpftrace, defer, ethtool, \
1818
fd_read_timeout, ip, rand_port, tool, wait_port_listen, wait_file
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
from .nsim import *
77
from .utils import *
88
from .ynl import NlError, YnlFamily, EthtoolFamily, NetdevFamily, RtnlFamily, RtnlAddrFamily
9-
from .ynl import NetshaperFamily, DevlinkFamily
9+
from .ynl import NetshaperFamily, DevlinkFamily, PSPFamily

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,8 @@ class DevlinkFamily(YnlFamily):
6161
def __init__(self, recv_size=0):
6262
super().__init__((SPEC_PATH / Path('devlink.yaml')).as_posix(),
6363
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)

0 commit comments

Comments
 (0)