Skip to content

Commit dd9f6cf

Browse files
jsitnickiMartin KaFai Lau
authored andcommitted
selftests/bpf: Parametrize test_xdp_context_tuntap
We want to add more test cases to cover different ways to access the metadata area. Prepare for it. Pull up the skeleton management. Signed-off-by: Jakub Sitnicki <[email protected]> Signed-off-by: Martin KaFai Lau <[email protected]> Reviewed-by: Jesse Brandeburg <[email protected]> Acked-by: Eduard Zingerman <[email protected]> Link: https://patch.msgid.link/20250814-skb-metadata-thru-dynptr-v7-5-8a39e636e0fb@cloudflare.com
1 parent 6dfd5e0 commit dd9f6cf

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

tools/testing/selftests/bpf/prog_tests/xdp_context_test_run.c

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,13 @@ void test_xdp_context_veth(void)
256256
netns_free(tx_ns);
257257
}
258258

259-
void test_xdp_context_tuntap(void)
259+
static void test_tuntap(struct bpf_program *xdp_prog,
260+
struct bpf_program *tc_prog,
261+
struct bpf_map *result_map)
260262
{
261263
LIBBPF_OPTS(bpf_tc_hook, tc_hook, .attach_point = BPF_TC_INGRESS);
262264
LIBBPF_OPTS(bpf_tc_opts, tc_opts, .handle = 1, .priority = 1);
263265
struct netns_obj *ns = NULL;
264-
struct test_xdp_meta *skel = NULL;
265266
__u8 packet[sizeof(struct ethhdr) + TEST_PAYLOAD_LEN];
266267
int tap_fd = -1;
267268
int tap_ifindex;
@@ -277,10 +278,6 @@ void test_xdp_context_tuntap(void)
277278

278279
SYS(close, "ip link set dev " TAP_NAME " up");
279280

280-
skel = test_xdp_meta__open_and_load();
281-
if (!ASSERT_OK_PTR(skel, "open and load skeleton"))
282-
goto close;
283-
284281
tap_ifindex = if_nametoindex(TAP_NAME);
285282
if (!ASSERT_GE(tap_ifindex, 0, "if_nametoindex"))
286283
goto close;
@@ -290,12 +287,12 @@ void test_xdp_context_tuntap(void)
290287
if (!ASSERT_OK(ret, "bpf_tc_hook_create"))
291288
goto close;
292289

293-
tc_opts.prog_fd = bpf_program__fd(skel->progs.ing_cls);
290+
tc_opts.prog_fd = bpf_program__fd(tc_prog);
294291
ret = bpf_tc_attach(&tc_hook, &tc_opts);
295292
if (!ASSERT_OK(ret, "bpf_tc_attach"))
296293
goto close;
297294

298-
ret = bpf_xdp_attach(tap_ifindex, bpf_program__fd(skel->progs.ing_xdp),
295+
ret = bpf_xdp_attach(tap_ifindex, bpf_program__fd(xdp_prog),
299296
0, NULL);
300297
if (!ASSERT_GE(ret, 0, "bpf_xdp_attach"))
301298
goto close;
@@ -312,11 +309,25 @@ void test_xdp_context_tuntap(void)
312309
if (!ASSERT_EQ(ret, sizeof(packet), "write packet"))
313310
goto close;
314311

315-
assert_test_result(skel->maps.test_result);
312+
assert_test_result(result_map);
316313

317314
close:
318315
if (tap_fd >= 0)
319316
close(tap_fd);
320-
test_xdp_meta__destroy(skel);
321317
netns_free(ns);
322318
}
319+
320+
void test_xdp_context_tuntap(void)
321+
{
322+
struct test_xdp_meta *skel = NULL;
323+
324+
skel = test_xdp_meta__open_and_load();
325+
if (!ASSERT_OK_PTR(skel, "open and load skeleton"))
326+
return;
327+
328+
if (test__start_subtest("data_meta"))
329+
test_tuntap(skel->progs.ing_xdp, skel->progs.ing_cls,
330+
skel->maps.test_result);
331+
332+
test_xdp_meta__destroy(skel);
333+
}

0 commit comments

Comments
 (0)