Commit 43fd0054 authored by David Wei's avatar David Wei Committed by Jakub Kicinski
Browse files

io_uring/zcrx: selftests: switch to using defer() for cleanup



Switch to using defer() for putting the NIC back to the original state
prior to running the selftest.

Signed-off-by: default avatarDavid Wei <dw@davidwei.uk>
Reviewed-by: default avatarSimon Horman <horms@kernel.org>
Reviewed-by: default avatarJoe Damato <jdamato@fastly.com>
Link: https://patch.msgid.link/20250425022049.3474590-2-dw@davidwei.uk


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 4acf6d4f
Loading
Loading
Loading
Loading
+29 −32
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ import re
from os import path
from lib.py import ksft_run, ksft_exit
from lib.py import NetDrvEpEnv
from lib.py import bkg, cmd, ethtool, wait_port_listen
from lib.py import bkg, cmd, defer, ethtool, wait_port_listen


def _get_rx_ring_entries(cfg):
@@ -34,22 +34,21 @@ def test_zcrx(cfg) -> None:
        raise KsftSkipEx('at least 2 combined channels required')
    rx_ring = _get_rx_ring_entries(cfg)

    try:

    ethtool(f"-G {cfg.ifname} tcp-data-split on", host=cfg.remote)
    defer(ethtool, f"-G {cfg.ifname} tcp-data-split auto", host=cfg.remote)
    ethtool(f"-G {cfg.ifname} rx 64", host=cfg.remote)
    defer(ethtool, f"-G {cfg.ifname} rx {rx_ring}", host=cfg.remote)
    ethtool(f"-X {cfg.ifname} equal {combined_chans - 1}", host=cfg.remote)
    defer(ethtool, f"-X {cfg.ifname} default", host=cfg.remote)
    flow_rule_id = _set_flow_rule(cfg, combined_chans - 1)
    defer(ethtool, f"-N {cfg.ifname} delete {flow_rule_id}", host=cfg.remote)

    rx_cmd = f"{cfg.bin_remote} -s -p 9999 -i {cfg.ifname} -q {combined_chans - 1}"
    tx_cmd = f"{cfg.bin_local} -c -h {cfg.remote_addr_v['6']} -p 9999 -l 12840"
    with bkg(rx_cmd, host=cfg.remote, exit_wait=True):
        wait_port_listen(9999, proto="tcp", host=cfg.remote)
        cmd(tx_cmd)
    finally:
        ethtool(f"-N {cfg.ifname} delete {flow_rule_id}", host=cfg.remote)
        ethtool(f"-X {cfg.ifname} default", host=cfg.remote)
        ethtool(f"-G {cfg.ifname} rx {rx_ring}", host=cfg.remote)
        ethtool(f"-G {cfg.ifname} tcp-data-split auto", host=cfg.remote)


def test_zcrx_oneshot(cfg) -> None:
@@ -60,22 +59,20 @@ def test_zcrx_oneshot(cfg) -> None:
        raise KsftSkipEx('at least 2 combined channels required')
    rx_ring = _get_rx_ring_entries(cfg)

    try:
    ethtool(f"-G {cfg.ifname} tcp-data-split on", host=cfg.remote)
    defer(ethtool, f"-G {cfg.ifname} tcp-data-split auto", host=cfg.remote)
    ethtool(f"-G {cfg.ifname} rx 64", host=cfg.remote)
    defer(ethtool, f"-G {cfg.ifname} rx {rx_ring}", host=cfg.remote)
    ethtool(f"-X {cfg.ifname} equal {combined_chans - 1}", host=cfg.remote)
    defer(ethtool, f"-X {cfg.ifname} default", host=cfg.remote)
    flow_rule_id = _set_flow_rule(cfg, combined_chans - 1)
    defer(ethtool, f"-N {cfg.ifname} delete {flow_rule_id}", host=cfg.remote)

    rx_cmd = f"{cfg.bin_remote} -s -p 9999 -i {cfg.ifname} -q {combined_chans - 1} -o 4"
    tx_cmd = f"{cfg.bin_local} -c -h {cfg.remote_addr_v['6']} -p 9999 -l 4096 -z 16384"
    with bkg(rx_cmd, host=cfg.remote, exit_wait=True):
        wait_port_listen(9999, proto="tcp", host=cfg.remote)
        cmd(tx_cmd)
    finally:
        ethtool(f"-N {cfg.ifname} delete {flow_rule_id}", host=cfg.remote)
        ethtool(f"-X {cfg.ifname} default", host=cfg.remote)
        ethtool(f"-G {cfg.ifname} rx {rx_ring}", host=cfg.remote)
        ethtool(f"-G {cfg.ifname} tcp-data-split auto", host=cfg.remote)


def main() -> None: