Skip to content

Commit cd31182

Browse files
committed
Merge branch 'selftests-test-xdp_tx-for-single-buffer'
Dimitri Daskalakis says: ==================== selftests: Test XDP_TX for single-buffer Ensure single buffer XDP functions correctly by covering the following cases: 1) Zero size payload 2) Full MTU 3) Single buffer packets through a multi-buffer XDP program These changes were tested with netdevsim and fbnic. # ./ksft-net-drv/drivers/net/xdp.py TAP version 13 1..10 ok 1 xdp.test_xdp_native_pass_sb ok 2 xdp.test_xdp_native_pass_mb ok 3 xdp.test_xdp_native_drop_sb ok 4 xdp.test_xdp_native_drop_mb ok 5 xdp.test_xdp_native_tx_sb ok 6 xdp.test_xdp_native_tx_mb # Failed run: pkt_sz 2048, offset 1. Last successful run: pkt_sz 1024, offset 256. Reason: Adjustment failed ok 7 xdp.test_xdp_native_adjst_tail_grow_data ok 8 xdp.test_xdp_native_adjst_tail_shrnk_data # Failed run: pkt_sz 512, offset -256. Last successful run: pkt_sz 512, offset -128. Reason: Adjustment failed ok 9 xdp.test_xdp_native_adjst_head_grow_data # Failed run: pkt_sz (2048) > HDS threshold (1536) and offset 64 > 48 ok 10 xdp.test_xdp_native_adjst_head_shrnk_data # Totals: pass:10 fail:0 xfail:0 xpass:0 skip:0 error:0 ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents a7bd721 + bbd885b commit cd31182

File tree

1 file changed

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

1 file changed

+58
-13
lines changed

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

Lines changed: 58 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -290,34 +290,78 @@ 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+
318+
# Writing zero bytes to stdin gets ignored by socat,
319+
# but with the shut-null flag socat generates a zero sized packet
320+
# when the socket is closed.
321+
tx_cmd_suffix = ",shut-null" if payload_len == 0 else ""
322+
tx_udp = f"echo -n {test_string} | socat -t 2 " + \
323+
f"-u STDIN UDP:{cfg.baddr}:{port}{tx_cmd_suffix}"
324+
325+
with bkg(rx_udp, host=cfg.remote, exit_wait=True) as rnc:
326+
wait_port_listen(port, proto="udp", host=cfg.remote)
327+
cmd(tx_udp, host=cfg.remote, shell=True)
328+
329+
ksft_eq(rnc.stdout.strip(), test_string, "UDP packet exchange failed")
330+
331+
expected_pkts += 1
332+
stats = _get_stats(prog_info["maps"]["map_xdp_stats"])
333+
ksft_eq(stats[XDPStats.RX.value], expected_pkts, "RX stats mismatch")
334+
ksft_eq(stats[XDPStats.TX.value], expected_pkts, "TX stats mismatch")
335+
336+
337+
def test_xdp_native_tx_sb(cfg):
338+
"""
339+
Tests the XDP_TX action for a single-buff case.
340+
341+
Args:
342+
cfg: Configuration object containing network settings.
343+
"""
344+
bpf_info = BPFProgInfo("xdp_prog", "xdp_native.bpf.o", "xdp", 1500)
345+
346+
# Ensure there's enough room for an ETH / IP / UDP header
347+
pkt_hdr_len = 42 if cfg.addr_ipver == "4" else 62
312348

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)
349+
_test_xdp_native_tx(cfg, bpf_info, [0, 1500 // 2, 1500 - pkt_hdr_len])
316350

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

319-
ksft_eq(rnc.stdout.strip(), test_string, "UDP packet exchange failed")
320-
ksft_eq(stats[XDPStats.TX.value], 1, "TX stats mismatch")
352+
def test_xdp_native_tx_mb(cfg):
353+
"""
354+
Tests the XDP_TX action for a multi-buff case.
355+
356+
Args:
357+
cfg: Configuration object containing network settings.
358+
"""
359+
bpf_info = BPFProgInfo("xdp_prog_frags", "xdp_native.bpf.o",
360+
"xdp.frags", 9000)
361+
# The first packet ensures we exercise the fragmented code path.
362+
# And the subsequent 0-sized packet ensures the driver
363+
# reinitializes xdp_buff correctly.
364+
_test_xdp_native_tx(cfg, bpf_info, [8000, 0])
321365

322366

323367
def _validate_res(res, offset_lst, pkt_sz_lst):
@@ -644,6 +688,7 @@ def main():
644688
test_xdp_native_pass_mb,
645689
test_xdp_native_drop_sb,
646690
test_xdp_native_drop_mb,
691+
test_xdp_native_tx_sb,
647692
test_xdp_native_tx_mb,
648693
test_xdp_native_adjst_tail_grow_data,
649694
test_xdp_native_adjst_tail_shrnk_data,

0 commit comments

Comments
 (0)