Skip to content

Commit 91aacd8

Browse files
Dimitri Daskalakiskuba-moo
authored andcommitted
selftests: drv-net: xdp: Extract common XDP_TX setup/validation.
In preparation of single-buffer XDP_TX tests, refactor common test code into the _test_xdp_native_tx method. Add support for multiple payload sizes, and additional validation for RX packet count. Pass the -n flag to echo to avoid adding an extra byte into the TX packet. Signed-off-by: Dimitri Daskalakis <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent a7bd721 commit 91aacd8

File tree

1 file changed

+34
-13
lines changed
  • tools/testing/selftests/drivers/net

1 file changed

+34
-13
lines changed

tools/testing/selftests/drivers/net/xdp.py

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -290,34 +290,55 @@ def test_xdp_native_drop_mb(cfg):
290290
_test_drop(cfg, bpf_info, 8000)
291291

292292

293-
def test_xdp_native_tx_mb(cfg):
293+
def _test_xdp_native_tx(cfg, bpf_info, payload_lens):
294294
"""
295-
Tests the XDP_TX action for a multi-buff case.
295+
Tests the XDP_TX action.
296296
297297
Args:
298298
cfg: Configuration object containing network settings.
299+
bpf_info: BPFProgInfo object containing the BPF program metadata.
300+
payload_lens: Array of packet lengths to send.
299301
"""
300302
cfg.require_cmd("socat", remote=True)
301-
302-
bpf_info = BPFProgInfo("xdp_prog_frags", "xdp_native.bpf.o", "xdp.frags", 9000)
303303
prog_info = _load_xdp_prog(cfg, bpf_info)
304304
port = rand_port()
305305

306306
_set_xdp_map("map_xdp_setup", TestConfig.MODE.value, XDPAction.TX.value)
307307
_set_xdp_map("map_xdp_setup", TestConfig.PORT.value, port)
308308

309-
test_string = ''.join(random.choice(string.ascii_lowercase) for _ in range(8000))
310-
rx_udp = f"socat -{cfg.addr_ipver} -T 2 -u UDP-RECV:{port},reuseport STDOUT"
311-
tx_udp = f"echo {test_string} | socat -t 2 -u STDIN UDP:{cfg.baddr}:{port}"
309+
expected_pkts = 0
310+
for payload_len in payload_lens:
311+
test_string = "".join(
312+
random.choice(string.ascii_lowercase) for _ in range(payload_len)
313+
)
314+
315+
rx_udp = f"socat -{cfg.addr_ipver} -T 2 " + \
316+
f"-u UDP-RECV:{port},reuseport STDOUT"
317+
tx_udp = f"echo -n {test_string} | socat -t 2 " + \
318+
f"-u STDIN UDP:{cfg.baddr}:{port}"
319+
320+
with bkg(rx_udp, host=cfg.remote, exit_wait=True) as rnc:
321+
wait_port_listen(port, proto="udp", host=cfg.remote)
322+
cmd(tx_udp, host=cfg.remote, shell=True)
323+
324+
ksft_eq(rnc.stdout.strip(), test_string, "UDP packet exchange failed")
312325

313-
with bkg(rx_udp, host=cfg.remote, exit_wait=True) as rnc:
314-
wait_port_listen(port, proto="udp", host=cfg.remote)
315-
cmd(tx_udp, host=cfg.remote, shell=True)
326+
expected_pkts += 1
327+
stats = _get_stats(prog_info["maps"]["map_xdp_stats"])
328+
ksft_eq(stats[XDPStats.RX.value], expected_pkts, "RX stats mismatch")
329+
ksft_eq(stats[XDPStats.TX.value], expected_pkts, "TX stats mismatch")
316330

317-
stats = _get_stats(prog_info['maps']['map_xdp_stats'])
318331

319-
ksft_eq(rnc.stdout.strip(), test_string, "UDP packet exchange failed")
320-
ksft_eq(stats[XDPStats.TX.value], 1, "TX stats mismatch")
332+
def test_xdp_native_tx_mb(cfg):
333+
"""
334+
Tests the XDP_TX action for a multi-buff case.
335+
336+
Args:
337+
cfg: Configuration object containing network settings.
338+
"""
339+
bpf_info = BPFProgInfo("xdp_prog_frags", "xdp_native.bpf.o",
340+
"xdp.frags", 9000)
341+
_test_xdp_native_tx(cfg, bpf_info, [8000])
321342

322343

323344
def _validate_res(res, offset_lst, pkt_sz_lst):

0 commit comments

Comments
 (0)