Skip to content

Commit cfd70e3

Browse files
TaeheeYookuba-moo
authored andcommitted
selftest: net-drv: hds: add test for HDS feature
HDS/HDS-thresh features were updated/implemented. so add some tests for these features. HDS tests are the same with `ethtool -G eth0 tcp-data-split <on | off | auto >` but `auto` depends on driver specification. So, it doesn't include `auto` case. HDS-thresh tests are same with `ethtool -G eth0 hds-thresh <0 - MAX>` It includes both 0 and MAX cases. It also includes exceed case, MAX + 1. Signed-off-by: Taehee Yoo <ap420073@gmail.com> Link: https://patch.msgid.link/20250114142852.3364986-11-ap420073@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent f394d07 commit cfd70e3

File tree

2 files changed

+121
-0
lines changed

2 files changed

+121
-0
lines changed

tools/testing/selftests/drivers/net/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ TEST_PROGS := \
1212
queues.py \
1313
stats.py \
1414
shaper.py \
15+
hds.py \
1516
# end of TEST_PROGS
1617

1718
include ../../lib.mk
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#!/usr/bin/env python3
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
import errno
5+
from lib.py import ksft_run, ksft_exit, ksft_eq, ksft_raises, KsftSkipEx
6+
from lib.py import EthtoolFamily, NlError
7+
from lib.py import NetDrvEnv
8+
9+
def get_hds(cfg, netnl) -> None:
10+
try:
11+
rings = netnl.rings_get({'header': {'dev-index': cfg.ifindex}})
12+
except NlError as e:
13+
raise KsftSkipEx('ring-get not supported by device')
14+
if 'tcp-data-split' not in rings:
15+
raise KsftSkipEx('tcp-data-split not supported by device')
16+
17+
def get_hds_thresh(cfg, netnl) -> None:
18+
try:
19+
rings = netnl.rings_get({'header': {'dev-index': cfg.ifindex}})
20+
except NlError as e:
21+
raise KsftSkipEx('ring-get not supported by device')
22+
if 'hds-thresh' not in rings:
23+
raise KsftSkipEx('hds-thresh not supported by device')
24+
25+
def set_hds_enable(cfg, netnl) -> None:
26+
try:
27+
netnl.rings_set({'header': {'dev-index': cfg.ifindex}, 'tcp-data-split': 'enabled'})
28+
except NlError as e:
29+
if e.error == errno.EINVAL:
30+
raise KsftSkipEx("disabling of HDS not supported by the device")
31+
elif e.error == errno.EOPNOTSUPP:
32+
raise KsftSkipEx("ring-set not supported by the device")
33+
try:
34+
rings = netnl.rings_get({'header': {'dev-index': cfg.ifindex}})
35+
except NlError as e:
36+
raise KsftSkipEx('ring-get not supported by device')
37+
if 'tcp-data-split' not in rings:
38+
raise KsftSkipEx('tcp-data-split not supported by device')
39+
40+
ksft_eq('enabled', rings['tcp-data-split'])
41+
42+
def set_hds_disable(cfg, netnl) -> None:
43+
try:
44+
netnl.rings_set({'header': {'dev-index': cfg.ifindex}, 'tcp-data-split': 'disabled'})
45+
except NlError as e:
46+
if e.error == errno.EINVAL:
47+
raise KsftSkipEx("disabling of HDS not supported by the device")
48+
elif e.error == errno.EOPNOTSUPP:
49+
raise KsftSkipEx("ring-set not supported by the device")
50+
try:
51+
rings = netnl.rings_get({'header': {'dev-index': cfg.ifindex}})
52+
except NlError as e:
53+
raise KsftSkipEx('ring-get not supported by device')
54+
if 'tcp-data-split' not in rings:
55+
raise KsftSkipEx('tcp-data-split not supported by device')
56+
57+
ksft_eq('disabled', rings['tcp-data-split'])
58+
59+
def set_hds_thresh_zero(cfg, netnl) -> None:
60+
try:
61+
netnl.rings_set({'header': {'dev-index': cfg.ifindex}, 'hds-thresh': 0})
62+
except NlError as e:
63+
if e.error == errno.EINVAL:
64+
raise KsftSkipEx("hds-thresh-set not supported by the device")
65+
elif e.error == errno.EOPNOTSUPP:
66+
raise KsftSkipEx("ring-set not supported by the device")
67+
try:
68+
rings = netnl.rings_get({'header': {'dev-index': cfg.ifindex}})
69+
except NlError as e:
70+
raise KsftSkipEx('ring-get not supported by device')
71+
if 'hds-thresh' not in rings:
72+
raise KsftSkipEx('hds-thresh not supported by device')
73+
74+
ksft_eq(0, rings['hds-thresh'])
75+
76+
def set_hds_thresh_max(cfg, netnl) -> None:
77+
try:
78+
rings = netnl.rings_get({'header': {'dev-index': cfg.ifindex}})
79+
except NlError as e:
80+
raise KsftSkipEx('ring-get not supported by device')
81+
if 'hds-thresh' not in rings:
82+
raise KsftSkipEx('hds-thresh not supported by device')
83+
try:
84+
netnl.rings_set({'header': {'dev-index': cfg.ifindex}, 'hds-thresh': rings['hds-thresh-max']})
85+
except NlError as e:
86+
if e.error == errno.EINVAL:
87+
raise KsftSkipEx("hds-thresh-set not supported by the device")
88+
elif e.error == errno.EOPNOTSUPP:
89+
raise KsftSkipEx("ring-set not supported by the device")
90+
rings = netnl.rings_get({'header': {'dev-index': cfg.ifindex}})
91+
ksft_eq(rings['hds-thresh'], rings['hds-thresh-max'])
92+
93+
def set_hds_thresh_gt(cfg, netnl) -> None:
94+
try:
95+
rings = netnl.rings_get({'header': {'dev-index': cfg.ifindex}})
96+
except NlError as e:
97+
raise KsftSkipEx('ring-get not supported by device')
98+
if 'hds-thresh' not in rings:
99+
raise KsftSkipEx('hds-thresh not supported by device')
100+
if 'hds-thresh-max' not in rings:
101+
raise KsftSkipEx('hds-thresh-max not defined by device')
102+
hds_gt = rings['hds-thresh-max'] + 1
103+
with ksft_raises(NlError) as e:
104+
netnl.rings_set({'header': {'dev-index': cfg.ifindex}, 'hds-thresh': hds_gt})
105+
ksft_eq(e.exception.nl_msg.error, -errno.EINVAL)
106+
107+
def main() -> None:
108+
with NetDrvEnv(__file__, queue_count=3) as cfg:
109+
ksft_run([get_hds,
110+
get_hds_thresh,
111+
set_hds_disable,
112+
set_hds_enable,
113+
set_hds_thresh_zero,
114+
set_hds_thresh_max,
115+
set_hds_thresh_gt],
116+
args=(cfg, EthtoolFamily()))
117+
ksft_exit()
118+
119+
if __name__ == "__main__":
120+
main()

0 commit comments

Comments
 (0)