Skip to content

Commit

Permalink
selftests: drv-net: test random value for hds-thresh
Browse files Browse the repository at this point in the history
hds.py has been testing 0(set_hds_thresh_zero()),
MAX(set_hds_thresh_max()), GT(set_hds_thresh_gt()) values for hds-thresh.
However if a hds-thresh value was already 0, set_hds_thresh_zero()
can't test properly.
So, it tests random value first and then tests 0, MAX, GT values.

Testing bnxt:
    TAP version 13
    1..13
    ok 1 hds.get_hds
    ok 2 hds.get_hds_thresh
    ok 3 hds.set_hds_disable # SKIP disabling of HDS not supported by
    the device
    ok 4 hds.set_hds_enable
    ok 5 hds.set_hds_thresh_random
    ok 6 hds.set_hds_thresh_zero
    ok 7 hds.set_hds_thresh_max
    ok 8 hds.set_hds_thresh_gt
    ok 9 hds.set_xdp
    ok 10 hds.enabled_set_xdp
    ok 11 hds.ioctl
    ok 12 hds.ioctl_set_xdp
    ok 13 hds.ioctl_enabled_set_xdp
    # Totals: pass:12 fail:0 xfail:0 xpass:0 skip:1 error:0

Testing lo:
    TAP version 13
    1..13
    ok 1 hds.get_hds # SKIP tcp-data-split not supported by device
    ok 2 hds.get_hds_thresh # SKIP hds-thresh not supported by device
    ok 3 hds.set_hds_disable # SKIP ring-set not supported by the device
    ok 4 hds.set_hds_enable # SKIP ring-set not supported by the device
    ok 5 hds.set_hds_thresh_random # SKIP hds-thresh not supported by
    device
    ok 6 hds.set_hds_thresh_zero # SKIP ring-set not supported by the
    device
    ok 7 hds.set_hds_thresh_max # SKIP hds-thresh not supported by
    device
    ok 8 hds.set_hds_thresh_gt # SKIP hds-thresh not supported by device
    ok 9 hds.set_xdp # SKIP tcp-data-split not supported by device
    ok 10 hds.enabled_set_xdp # SKIP tcp-data-split not supported by
    device
    ok 11 hds.ioctl # SKIP tcp-data-split not supported by device
    ok 12 hds.ioctl_set_xdp # SKIP tcp-data-split not supported by
    device
    ok 13 hds.ioctl_enabled_set_xdp # SKIP tcp-data-split not supported
    by device
    # Totals: pass:0 fail:0 xfail:0 xpass:0 skip:13 error:0

Signed-off-by: Taehee Yoo <ap420073@gmail.com>
Link: https://patch.msgid.link/20250404122126.1555648-3-ap420073@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Taehee Yoo authored and Jakub Kicinski committed Apr 7, 2025
1 parent 216a61d commit 22d3a63
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion tools/testing/selftests/drivers/net/hds.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from lib.py import ksft_run, ksft_exit, ksft_eq, ksft_raises, KsftSkipEx
from lib.py import CmdExitFailure, EthtoolFamily, NlError
from lib.py import NetDrvEnv
from lib.py import defer, ethtool, ip
from lib.py import defer, ethtool, ip, random


def _get_hds_mode(cfg, netnl) -> str:
Expand Down Expand Up @@ -109,6 +109,36 @@ def set_hds_thresh_zero(cfg, netnl) -> None:

ksft_eq(0, rings['hds-thresh'])

def set_hds_thresh_random(cfg, netnl) -> None:
try:
rings = netnl.rings_get({'header': {'dev-index': cfg.ifindex}})
except NlError as e:
raise KsftSkipEx('ring-get not supported by device')
if 'hds-thresh' not in rings:
raise KsftSkipEx('hds-thresh not supported by device')
if 'hds-thresh-max' not in rings:
raise KsftSkipEx('hds-thresh-max not defined by device')

if rings['hds-thresh-max'] < 2:
raise KsftSkipEx('hds-thresh-max is too small')
elif rings['hds-thresh-max'] == 2:
hds_thresh = 1
else:
while True:
hds_thresh = random.randint(1, rings['hds-thresh-max'] - 1)
if hds_thresh != rings['hds-thresh']:
break

try:
netnl.rings_set({'header': {'dev-index': cfg.ifindex}, 'hds-thresh': hds_thresh})
except NlError as e:
if e.error == errno.EINVAL:
raise KsftSkipEx("hds-thresh-set not supported by the device")
elif e.error == errno.EOPNOTSUPP:
raise KsftSkipEx("ring-set not supported by the device")
rings = netnl.rings_get({'header': {'dev-index': cfg.ifindex}})
ksft_eq(hds_thresh, rings['hds-thresh'])

def set_hds_thresh_max(cfg, netnl) -> None:
try:
rings = netnl.rings_get({'header': {'dev-index': cfg.ifindex}})
Expand Down Expand Up @@ -243,6 +273,7 @@ def main() -> None:
get_hds_thresh,
set_hds_disable,
set_hds_enable,
set_hds_thresh_random,
set_hds_thresh_zero,
set_hds_thresh_max,
set_hds_thresh_gt,
Expand Down

0 comments on commit 22d3a63

Please sign in to comment.