Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests/net: parametrise iou-zcrx.py with ksft_variants

Use ksft_variants to parametrise tests in iou-zcrx.py to either use
single queues or RSS contexts, reducing duplication.

Signed-off-by: David Wei <dw@davidwei.uk>
Link: https://patch.msgid.link/20260108234521.3619621-1-dw@davidwei.uk
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

David Wei and committed by
Jakub Kicinski
de7c600e 9086984f

+82 -98
+82 -98
tools/testing/selftests/drivers/net/hw/iou-zcrx.py
··· 3 3 4 4 import re 5 5 from os import path 6 - from lib.py import ksft_run, ksft_exit, KsftSkipEx 6 + from lib.py import ksft_run, ksft_exit, KsftSkipEx, ksft_variants, KsftNamedVariant 7 7 from lib.py import NetDrvEpEnv 8 8 from lib.py import bkg, cmd, defer, ethtool, rand_port, wait_port_listen 9 + from lib.py import EthtoolFamily 9 10 10 11 11 - def _get_current_settings(cfg): 12 - output = ethtool(f"-g {cfg.ifname}", json=True)[0] 13 - return (output['rx'], output['hds-thresh']) 14 - 15 - 16 - def _get_combined_channels(cfg): 17 - output = ethtool(f"-l {cfg.ifname}").stdout 18 - values = re.findall(r'Combined:\s+(\d+)', output) 19 - return int(values[1]) 20 - 21 - 22 - def _create_rss_ctx(cfg, chan): 23 - output = ethtool(f"-X {cfg.ifname} context new start {chan} equal 1").stdout 12 + def create_rss_ctx(cfg): 13 + output = ethtool(f"-X {cfg.ifname} context new start {cfg.target} equal 1").stdout 24 14 values = re.search(r'New RSS context is (\d+)', output).group(1) 25 - ctx_id = int(values) 26 - return (ctx_id, defer(ethtool, f"-X {cfg.ifname} delete context {ctx_id}")) 15 + return int(values) 27 16 28 17 29 - def _set_flow_rule(cfg, port, chan): 30 - output = ethtool(f"-N {cfg.ifname} flow-type tcp6 dst-port {port} action {chan}").stdout 18 + def set_flow_rule(cfg): 19 + output = ethtool(f"-N {cfg.ifname} flow-type tcp6 dst-port {cfg.port} action {cfg.target}").stdout 31 20 values = re.search(r'ID (\d+)', output).group(1) 32 21 return int(values) 33 22 34 23 35 - def _set_flow_rule_rss(cfg, port, ctx_id): 36 - output = ethtool(f"-N {cfg.ifname} flow-type tcp6 dst-port {port} context {ctx_id}").stdout 24 + def set_flow_rule_rss(cfg, rss_ctx_id): 25 + output = ethtool(f"-N {cfg.ifname} flow-type tcp6 dst-port {cfg.port} context {rss_ctx_id}").stdout 37 26 values = re.search(r'ID (\d+)', output).group(1) 38 27 return int(values) 39 28 40 29 41 - def test_zcrx(cfg) -> None: 42 - cfg.require_ipver('6') 30 + def single(cfg): 31 + channels = cfg.ethnl.channels_get({'header': {'dev-index': cfg.ifindex}}) 32 + channels = channels['combined-count'] 33 + if channels < 2: 34 + raise KsftSkipEx('Test requires NETIF with at least 2 combined channels') 43 35 44 - combined_chans = _get_combined_channels(cfg) 45 - if combined_chans < 2: 46 - raise KsftSkipEx('at least 2 combined channels required') 47 - (rx_ring, hds_thresh) = _get_current_settings(cfg) 48 - port = rand_port() 36 + rings = cfg.ethnl.rings_get({'header': {'dev-index': cfg.ifindex}}) 37 + rx_rings = rings['rx'] 38 + hds_thresh = rings.get('hds-thresh', 0) 49 39 50 - ethtool(f"-G {cfg.ifname} tcp-data-split on") 51 - defer(ethtool, f"-G {cfg.ifname} tcp-data-split auto") 40 + cfg.ethnl.rings_set({'header': {'dev-index': cfg.ifindex}, 41 + 'tcp-data-split': 'enabled', 42 + 'hds-thresh': 0, 43 + 'rx': 64}) 44 + defer(cfg.ethnl.rings_set, {'header': {'dev-index': cfg.ifindex}, 45 + 'tcp-data-split': 'unknown', 46 + 'hds-thresh': hds_thresh, 47 + 'rx': rx_rings}) 52 48 53 - ethtool(f"-G {cfg.ifname} hds-thresh 0") 54 - defer(ethtool, f"-G {cfg.ifname} hds-thresh {hds_thresh}") 55 - 56 - ethtool(f"-G {cfg.ifname} rx 64") 57 - defer(ethtool, f"-G {cfg.ifname} rx {rx_ring}") 58 - 59 - ethtool(f"-X {cfg.ifname} equal {combined_chans - 1}") 49 + cfg.target = channels - 1 50 + ethtool(f"-X {cfg.ifname} equal {cfg.target}") 60 51 defer(ethtool, f"-X {cfg.ifname} default") 61 52 62 - flow_rule_id = _set_flow_rule(cfg, port, combined_chans - 1) 53 + flow_rule_id = set_flow_rule(cfg) 63 54 defer(ethtool, f"-N {cfg.ifname} delete {flow_rule_id}") 64 55 65 - rx_cmd = f"{cfg.bin_local} -s -p {port} -i {cfg.ifname} -q {combined_chans - 1}" 66 - tx_cmd = f"{cfg.bin_remote} -c -h {cfg.addr_v['6']} -p {port} -l 12840" 56 + 57 + def rss(cfg): 58 + channels = cfg.ethnl.channels_get({'header': {'dev-index': cfg.ifindex}}) 59 + channels = channels['combined-count'] 60 + if channels < 2: 61 + raise KsftSkipEx('Test requires NETIF with at least 2 combined channels') 62 + 63 + rings = cfg.ethnl.rings_get({'header': {'dev-index': cfg.ifindex}}) 64 + rx_rings = rings['rx'] 65 + hds_thresh = rings.get('hds-thresh', 0) 66 + 67 + cfg.ethnl.rings_set({'header': {'dev-index': cfg.ifindex}, 68 + 'tcp-data-split': 'enabled', 69 + 'hds-thresh': 0, 70 + 'rx': 64}) 71 + defer(cfg.ethnl.rings_set, {'header': {'dev-index': cfg.ifindex}, 72 + 'tcp-data-split': 'unknown', 73 + 'hds-thresh': hds_thresh, 74 + 'rx': rx_rings}) 75 + 76 + cfg.target = channels - 1 77 + ethtool(f"-X {cfg.ifname} equal {cfg.target}") 78 + defer(ethtool, f"-X {cfg.ifname} default") 79 + 80 + rss_ctx_id = create_rss_ctx(cfg) 81 + defer(ethtool, f"-X {cfg.ifname} delete context {rss_ctx_id}") 82 + 83 + flow_rule_id = set_flow_rule_rss(cfg, rss_ctx_id) 84 + defer(ethtool, f"-N {cfg.ifname} delete {flow_rule_id}") 85 + 86 + 87 + @ksft_variants([ 88 + KsftNamedVariant("single", single), 89 + KsftNamedVariant("rss", rss), 90 + ]) 91 + def test_zcrx(cfg, setup) -> None: 92 + cfg.require_ipver('6') 93 + 94 + setup(cfg) 95 + rx_cmd = f"{cfg.bin_local} -s -p {cfg.port} -i {cfg.ifname} -q {cfg.target}" 96 + tx_cmd = f"{cfg.bin_remote} -c -h {cfg.addr_v['6']} -p {cfg.port} -l 12840" 67 97 with bkg(rx_cmd, exit_wait=True): 68 - wait_port_listen(port, proto="tcp") 98 + wait_port_listen(cfg.port, proto="tcp") 69 99 cmd(tx_cmd, host=cfg.remote) 70 100 71 101 72 - def test_zcrx_oneshot(cfg) -> None: 102 + @ksft_variants([ 103 + KsftNamedVariant("single", single), 104 + KsftNamedVariant("rss", rss), 105 + ]) 106 + def test_zcrx_oneshot(cfg, setup) -> None: 73 107 cfg.require_ipver('6') 74 108 75 - combined_chans = _get_combined_channels(cfg) 76 - if combined_chans < 2: 77 - raise KsftSkipEx('at least 2 combined channels required') 78 - (rx_ring, hds_thresh) = _get_current_settings(cfg) 79 - port = rand_port() 80 - 81 - ethtool(f"-G {cfg.ifname} tcp-data-split on") 82 - defer(ethtool, f"-G {cfg.ifname} tcp-data-split auto") 83 - 84 - ethtool(f"-G {cfg.ifname} hds-thresh 0") 85 - defer(ethtool, f"-G {cfg.ifname} hds-thresh {hds_thresh}") 86 - 87 - ethtool(f"-G {cfg.ifname} rx 64") 88 - defer(ethtool, f"-G {cfg.ifname} rx {rx_ring}") 89 - 90 - ethtool(f"-X {cfg.ifname} equal {combined_chans - 1}") 91 - defer(ethtool, f"-X {cfg.ifname} default") 92 - 93 - flow_rule_id = _set_flow_rule(cfg, port, combined_chans - 1) 94 - defer(ethtool, f"-N {cfg.ifname} delete {flow_rule_id}") 95 - 96 - rx_cmd = f"{cfg.bin_local} -s -p {port} -i {cfg.ifname} -q {combined_chans - 1} -o 4" 97 - tx_cmd = f"{cfg.bin_remote} -c -h {cfg.addr_v['6']} -p {port} -l 4096 -z 16384" 109 + setup(cfg) 110 + rx_cmd = f"{cfg.bin_local} -s -p {cfg.port} -i {cfg.ifname} -q {cfg.target} -o 4" 111 + tx_cmd = f"{cfg.bin_remote} -c -h {cfg.addr_v['6']} -p {cfg.port} -l 4096 -z 16384" 98 112 with bkg(rx_cmd, exit_wait=True): 99 - wait_port_listen(port, proto="tcp") 100 - cmd(tx_cmd, host=cfg.remote) 101 - 102 - 103 - def test_zcrx_rss(cfg) -> None: 104 - cfg.require_ipver('6') 105 - 106 - combined_chans = _get_combined_channels(cfg) 107 - if combined_chans < 2: 108 - raise KsftSkipEx('at least 2 combined channels required') 109 - (rx_ring, hds_thresh) = _get_current_settings(cfg) 110 - port = rand_port() 111 - 112 - ethtool(f"-G {cfg.ifname} tcp-data-split on") 113 - defer(ethtool, f"-G {cfg.ifname} tcp-data-split auto") 114 - 115 - ethtool(f"-G {cfg.ifname} hds-thresh 0") 116 - defer(ethtool, f"-G {cfg.ifname} hds-thresh {hds_thresh}") 117 - 118 - ethtool(f"-G {cfg.ifname} rx 64") 119 - defer(ethtool, f"-G {cfg.ifname} rx {rx_ring}") 120 - 121 - ethtool(f"-X {cfg.ifname} equal {combined_chans - 1}") 122 - defer(ethtool, f"-X {cfg.ifname} default") 123 - 124 - (ctx_id, delete_ctx) = _create_rss_ctx(cfg, combined_chans - 1) 125 - flow_rule_id = _set_flow_rule_rss(cfg, port, ctx_id) 126 - defer(ethtool, f"-N {cfg.ifname} delete {flow_rule_id}") 127 - 128 - rx_cmd = f"{cfg.bin_local} -s -p {port} -i {cfg.ifname} -q {combined_chans - 1}" 129 - tx_cmd = f"{cfg.bin_remote} -c -h {cfg.addr_v['6']} -p {port} -l 12840" 130 - with bkg(rx_cmd, exit_wait=True): 131 - wait_port_listen(port, proto="tcp") 113 + wait_port_listen(cfg.port, proto="tcp") 132 114 cmd(tx_cmd, host=cfg.remote) 133 115 134 116 ··· 119 137 cfg.bin_local = path.abspath(path.dirname(__file__) + "/../../../drivers/net/hw/iou-zcrx") 120 138 cfg.bin_remote = cfg.remote.deploy(cfg.bin_local) 121 139 122 - ksft_run(globs=globals(), case_pfx={"test_"}, args=(cfg, )) 140 + cfg.ethnl = EthtoolFamily() 141 + cfg.port = rand_port() 142 + ksft_run(globs=globals(), cases=[test_zcrx, test_zcrx_oneshot], args=(cfg, )) 123 143 ksft_exit() 124 144 125 145