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

Merge branch 'io_uring-zcrx-selftests-more-cleanups'

David Wei says:

====================
io_uring/zcrx: selftests: more cleanups

Patch 1 use rand_port() instead of hard coding port 9999. Patch 2 parses
JSON from ethtool -g instead of string.
====================

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

+33 -21
+33 -21
tools/testing/selftests/drivers/net/hw/iou-zcrx.py
··· 5 5 from os import path 6 6 from lib.py import ksft_run, ksft_exit 7 7 from lib.py import NetDrvEpEnv 8 - from lib.py import bkg, cmd, defer, ethtool, wait_port_listen 8 + from lib.py import bkg, cmd, defer, ethtool, rand_port, wait_port_listen 9 9 10 10 11 11 def _get_current_settings(cfg): 12 - output = ethtool(f"-g {cfg.ifname}", host=cfg.remote).stdout 13 - rx_ring = re.findall(r'RX:\s+(\d+)', output) 14 - hds_thresh = re.findall(r'HDS thresh:\s+(\d+)', output) 15 - return (int(rx_ring[1]), int(hds_thresh[1])) 12 + output = ethtool(f"-g {cfg.ifname}", json=True, host=cfg.remote)[0] 13 + return (output['rx'], output['hds-thresh']) 16 14 17 15 18 16 def _get_combined_channels(cfg): ··· 26 28 return (ctx_id, defer(ethtool, f"-X {cfg.ifname} delete context {ctx_id}", host=cfg.remote)) 27 29 28 30 29 - def _set_flow_rule(cfg, chan): 30 - output = ethtool(f"-N {cfg.ifname} flow-type tcp6 dst-port 9999 action {chan}", host=cfg.remote).stdout 31 + def _set_flow_rule(cfg, port, chan): 32 + output = ethtool(f"-N {cfg.ifname} flow-type tcp6 dst-port {port} action {chan}", host=cfg.remote).stdout 31 33 values = re.search(r'ID (\d+)', output).group(1) 32 34 return int(values) 33 35 34 36 35 - def _set_flow_rule_rss(cfg, chan): 36 - output = ethtool(f"-N {cfg.ifname} flow-type tcp6 dst-port 9999 action {chan}", host=cfg.remote).stdout 37 + def _set_flow_rule_rss(cfg, port, chan): 38 + output = ethtool(f"-N {cfg.ifname} flow-type tcp6 dst-port {port} action {chan}", host=cfg.remote).stdout 37 39 values = re.search(r'ID (\d+)', output).group(1) 38 40 return int(values) 39 41 ··· 45 47 if combined_chans < 2: 46 48 raise KsftSkipEx('at least 2 combined channels required') 47 49 (rx_ring, hds_thresh) = _get_current_settings(cfg) 50 + port = rand_port() 48 51 49 52 ethtool(f"-G {cfg.ifname} tcp-data-split on", host=cfg.remote) 50 53 defer(ethtool, f"-G {cfg.ifname} tcp-data-split auto", host=cfg.remote) 54 + 51 55 ethtool(f"-G {cfg.ifname} hds-thresh 0", host=cfg.remote) 52 56 defer(ethtool, f"-G {cfg.ifname} hds-thresh {hds_thresh}", host=cfg.remote) 57 + 53 58 ethtool(f"-G {cfg.ifname} rx 64", host=cfg.remote) 54 59 defer(ethtool, f"-G {cfg.ifname} rx {rx_ring}", host=cfg.remote) 60 + 55 61 ethtool(f"-X {cfg.ifname} equal {combined_chans - 1}", host=cfg.remote) 56 62 defer(ethtool, f"-X {cfg.ifname} default", host=cfg.remote) 57 - flow_rule_id = _set_flow_rule(cfg, combined_chans - 1) 63 + 64 + flow_rule_id = _set_flow_rule(cfg, port, combined_chans - 1) 58 65 defer(ethtool, f"-N {cfg.ifname} delete {flow_rule_id}", host=cfg.remote) 59 66 60 - rx_cmd = f"{cfg.bin_remote} -s -p 9999 -i {cfg.ifname} -q {combined_chans - 1}" 61 - tx_cmd = f"{cfg.bin_local} -c -h {cfg.remote_addr_v['6']} -p 9999 -l 12840" 67 + rx_cmd = f"{cfg.bin_remote} -s -p {port} -i {cfg.ifname} -q {combined_chans - 1}" 68 + tx_cmd = f"{cfg.bin_local} -c -h {cfg.remote_addr_v['6']} -p {port} -l 12840" 62 69 with bkg(rx_cmd, host=cfg.remote, exit_wait=True): 63 - wait_port_listen(9999, proto="tcp", host=cfg.remote) 70 + wait_port_listen(port, proto="tcp", host=cfg.remote) 64 71 cmd(tx_cmd) 65 72 66 73 ··· 76 73 if combined_chans < 2: 77 74 raise KsftSkipEx('at least 2 combined channels required') 78 75 (rx_ring, hds_thresh) = _get_current_settings(cfg) 76 + port = rand_port() 79 77 80 78 ethtool(f"-G {cfg.ifname} tcp-data-split on", host=cfg.remote) 81 79 defer(ethtool, f"-G {cfg.ifname} tcp-data-split auto", host=cfg.remote) 80 + 82 81 ethtool(f"-G {cfg.ifname} hds-thresh 0", host=cfg.remote) 83 82 defer(ethtool, f"-G {cfg.ifname} hds-thresh {hds_thresh}", host=cfg.remote) 83 + 84 84 ethtool(f"-G {cfg.ifname} rx 64", host=cfg.remote) 85 85 defer(ethtool, f"-G {cfg.ifname} rx {rx_ring}", host=cfg.remote) 86 + 86 87 ethtool(f"-X {cfg.ifname} equal {combined_chans - 1}", host=cfg.remote) 87 88 defer(ethtool, f"-X {cfg.ifname} default", host=cfg.remote) 88 - flow_rule_id = _set_flow_rule(cfg, combined_chans - 1) 89 + 90 + flow_rule_id = _set_flow_rule(cfg, port, combined_chans - 1) 89 91 defer(ethtool, f"-N {cfg.ifname} delete {flow_rule_id}", host=cfg.remote) 90 92 91 - rx_cmd = f"{cfg.bin_remote} -s -p 9999 -i {cfg.ifname} -q {combined_chans - 1} -o 4" 92 - tx_cmd = f"{cfg.bin_local} -c -h {cfg.remote_addr_v['6']} -p 9999 -l 4096 -z 16384" 93 + rx_cmd = f"{cfg.bin_remote} -s -p {port} -i {cfg.ifname} -q {combined_chans - 1} -o 4" 94 + tx_cmd = f"{cfg.bin_local} -c -h {cfg.remote_addr_v['6']} -p {port} -l 4096 -z 16384" 93 95 with bkg(rx_cmd, host=cfg.remote, exit_wait=True): 94 - wait_port_listen(9999, proto="tcp", host=cfg.remote) 96 + wait_port_listen(port, proto="tcp", host=cfg.remote) 95 97 cmd(tx_cmd) 96 98 97 99 ··· 107 99 if combined_chans < 2: 108 100 raise KsftSkipEx('at least 2 combined channels required') 109 101 (rx_ring, hds_thresh) = _get_current_settings(cfg) 102 + port = rand_port() 110 103 111 104 ethtool(f"-G {cfg.ifname} tcp-data-split on", host=cfg.remote) 112 105 defer(ethtool, f"-G {cfg.ifname} tcp-data-split auto", host=cfg.remote) 106 + 113 107 ethtool(f"-G {cfg.ifname} hds-thresh 0", host=cfg.remote) 114 108 defer(ethtool, f"-G {cfg.ifname} hds-thresh {hds_thresh}", host=cfg.remote) 109 + 115 110 ethtool(f"-G {cfg.ifname} rx 64", host=cfg.remote) 116 111 defer(ethtool, f"-G {cfg.ifname} rx {rx_ring}", host=cfg.remote) 112 + 117 113 ethtool(f"-X {cfg.ifname} equal {combined_chans - 1}", host=cfg.remote) 118 114 defer(ethtool, f"-X {cfg.ifname} default", host=cfg.remote) 119 115 120 116 (ctx_id, delete_ctx) = _create_rss_ctx(cfg, combined_chans) 121 - flow_rule_id = _set_flow_rule_rss(cfg, ctx_id) 117 + flow_rule_id = _set_flow_rule_rss(cfg, port, ctx_id) 122 118 defer(ethtool, f"-N {cfg.ifname} delete {flow_rule_id}", host=cfg.remote) 123 119 124 - rx_cmd = f"{cfg.bin_remote} -s -p 9999 -i {cfg.ifname} -q {combined_chans - 1}" 125 - tx_cmd = f"{cfg.bin_local} -c -h {cfg.remote_addr_v['6']} -p 9999 -l 12840" 120 + rx_cmd = f"{cfg.bin_remote} -s -p {port} -i {cfg.ifname} -q {combined_chans - 1}" 121 + tx_cmd = f"{cfg.bin_local} -c -h {cfg.remote_addr_v['6']} -p {port} -l 12840" 126 122 with bkg(rx_cmd, host=cfg.remote, exit_wait=True): 127 - wait_port_listen(9999, proto="tcp", host=cfg.remote) 123 + wait_port_listen(port, proto="tcp", host=cfg.remote) 128 124 cmd(tx_cmd) 129 125 130 126