[PATCH net-next v2 4/7] selftests: drv-net: probe for AF_XDP sockets more explicitly

Jakub Kicinski
2025-02-19T23:50:08Z

Separate the support check from socket binding for easier refactoring.
Use: ./helper - - just to probe if we can open the socket.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
v2: new
---
tools/testing/selftests/drivers/net/xdp_helper.c | 7 +++++++
tools/testing/selftests/drivers/net/queues.py | 12 +++++++-----
2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/tools/testing/selftests/drivers/net/xdp_helper.c b/tools/testing/selftests/drivers/net/xdp_helper.c
index 80f86c2fe1a5..2bad3b4d616c 100644
--- a/tools/testing/selftests/drivers/net/xdp_helper.c
+++ b/tools/testing/selftests/drivers/net/xdp_helper.c
@@ -50,6 +50,13 @@ int main(int argc, char **argv)
return 1;
}

+ /* "Probing mode", just checking if AF_XDP sockets are supported */
+ if (!strcmp(argv[1], "-") && !strcmp(argv[2], "-")) {
+ printf("AF_XDP support detected\n");
+ close(sock_fd);
+ return 0;
+ }
+
ifindex = atoi(argv[1]);
queue = atoi(argv[2]);

diff --git a/tools/testing/selftests/drivers/net/queues.py b/tools/testing/selftests/drivers/net/queues.py
index b6896a57a5fd..0c959b2eb618 100755
--- a/tools/testing/selftests/drivers/net/queues.py
+++ b/tools/testing/selftests/drivers/net/queues.py
@@ -25,6 +25,13 @@ import subprocess
return None

def check_xdp(cfg, nl, xdp_queue_id=0) -> None:
+ # Probe for support
+ xdp = cmd(cfg.rpath("xdp_helper") + ' - -', fail=False)
+ if xdp.ret == 255:
+ raise KsftSkipEx('AF_XDP unsupported')
+ elif xdp.ret > 0:
+ raise KsftFailEx('unable to create AF_XDP socket')
+
xdp = subprocess.Popen([cfg.rpath("xdp_helper"), f"{cfg.ifindex}", f"{xdp_queue_id}"],
stdin=subprocess.PIPE, stdout=subprocess.PIPE, bufsize=1,
text=True)
@@ -33,11 +40,6 @@ import subprocess
stdout, stderr = xdp.communicate(timeout=10)
rx = tx = False

- if xdp.returncode == 255:
- raise KsftSkipEx('AF_XDP unsupported')
- elif xdp.returncode > 0:
- raise KsftFailEx('unable to create AF_XDP socket')
-
queues = nl.queue_get({'ifindex': cfg.ifindex}, dump=True)
if not queues:
raise KsftSkipEx("Netlink reports no queues")
--
2.48.1