selftests/bpf: add coverage for xdp_features in test_progs
Subsystems (6)
v3 cover selftests/bpf: add coverage for xdp_features in test_progs
Hello,
this small series aims to increase coverage of xdp features in test_progs. The initial versions proposed to rework test_xdp_features.sh to make it fit in test_progs, but some discussions in v1 and v2 showed that the script is still needed as a standalone tool. So this new revision lets test_xdp_features.sh as-is, and rather adds missing coverage in existing test (cpu map). The new revision is now also a follow-up to the update performed by Florian Kauer in [1] for devmap programs testing.
---
Changes in v3:
- Drop xdp_features rework commit
- update xdp_cpumap_attach to extend its coverage
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- fix endianness management in userspace packet parsing (call htonl on constant rather than packet part)
The new test has been run in a local x86 environment and in CI:
#560/1 xdp_cpumap_attach/CPUMAP with programs in entries:OK #560/2 xdp_cpumap_attach/CPUMAP with frags programs in entries:OK #560/3 xdp_cpumap_attach/CPUMAP attach with programs in entries on veth:OK #560 xdp_cpumap_attach:OK
Summary: 1/3 PASSED, 0 SKIPPED, 0 FAILED
---
Alexis Lothoré (eBPF Foundation) (3):
selftests/bpf: fix bpf_map_redirect call for cpu map test selftests/bpf: make xdp_cpumap_attach keep redirect prog attached selftests/bpf: check program redirect in xdp_cpumap_attach
.../selftests/bpf/prog_tests/xdp_cpumap_attach.c | 130 +++++++++++++++++++-- .../bpf/progs/test_xdp_with_cpumap_helpers.c | 7 +- 2 files changed, 129 insertions(+), 8 deletions(-)
---
base-commit: 058d7c3d1691e2e4a4963716ec6c047dff778637
change-id: 20240730-convert_xdp_tests-ccd66bfe33db
Best regards,
Signature · 3 lines
Alexis Lothoré, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
PATCH v3 1/3 selftests/bpf: fix bpf_map_redirect call for cpu map test
xdp_redir_prog currently redirects packets based on the entry at index 1 in cpu_map, but the corresponding test only manipulates the entry at index 0. This does not really affect the test in its current form since the program is detached before having the opportunity to execute, but it needs to be fixed before being able improve the corresponding test (ie, not only test attach/detach but also the redirect feature)
Fix this XDP program by making it redirect packets based on entry 0 in cpu_map instead of entry 1.
---
Changes in v3:
- new patch
--- tools/testing/selftests/bpf/progs/test_xdp_with_cpumap_helpers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/progs/test_xdp_with_cpumap_helpers.c +1 -1
@@ -15,7 +15,7 @@ struct { SEC("xdp")int xdp_redir_prog (struct xdp_md *ctx) { -return bpf_redirect_map (&cpu_map,1 ,0 ); +return bpf_redirect_map (&cpu_map,0 ,0 ); }SEC ("xdp" )
Signature · 1 line
2.46.2
PATCH v3 2/3 selftests/bpf: make xdp_cpumap_attach keep redirect prog attached
In reply to Alexis Lothoré (eBPF Foundation)Current test only checks attach/detach on cpu map type program, and so does not check that it can be properly executed, neither that it redirects correctly.
Update the existing test to extend its coverage:
- keep the redirected program loaded
- try to execute it through bpf_prog_test_run_opts with some dummy context
While at it, bring the following minor improvements:
- isolate test interface in its own namespace
- replicate the test on a veth pair
---
This change is based on the similar update brought to xdp_devmap_attach ([1]) and then realigns xdp_cpumap_attach with it
Changes in v3:
- new patch
--- .../selftests/bpf/prog_tests/xdp_cpumap_attach.c | 124 +++++++++++++++++++-- 1 file changed, 117 insertions(+), 7 deletions(-)
tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c +117 -7
@@ -2,35 +2,41 @@#include <uapi/linux/bpf.h> #include <linux/if_link.h> #include <test_progs.h> +#include <network_helpers.h> #include "test_xdp_with_cpumap_frags_helpers.skel.h" #include "test_xdp_with_cpumap_helpers.skel.h" #define IFINDEX_LO 1 +#define TEST_NS "cpu_attach_ns"static void test_xdp_with_cpumap_helpers (void ) { -struct test_xdp_with_cpumap_helpers *skel; +struct test_xdp_with_cpumap_helpers *skel =NULL ;struct bpf_prog_info info = {};__u32 len =sizeof (info);struct bpf_cpumap_val val = { .qsize =192 , }; -int err, prog_fd, map_fd; +int err, prog_fd, prog_redir_fd, map_fd; +struct nstoken *nstoken =NULL ;__u32 idx =0 ; +SYS (out_close,"ip netns add %s" ,TEST_NS ); + nstoken =open_netns (TEST_NS ); +if (!ASSERT_OK_PTR (nstoken,"open_netns" )) + goto out_close; +SYS (out_close,"ip link set dev lo up" ); + skel =test_xdp_with_cpumap_helpers__open_and_load ();if (!ASSERT_OK_PTR (skel,"test_xdp_with_cpumap_helpers__open_and_load" ))return ; - prog_fd =bpf_program__fd (skel->progs.xdp_redir_prog); - err =bpf_xdp_attach (IFINDEX_LO , prog_fd,XDP_FLAGS_SKB_MODE ,NULL ); + prog_redir_fd =bpf_program__fd (skel->progs.xdp_redir_prog); + err =bpf_xdp_attach (IFINDEX_LO , prog_redir_fd,XDP_FLAGS_SKB_MODE ,NULL );if (!ASSERT_OK (err,"Generic attach of program with 8-byte CPUMAP" )) goto out_close; - err =bpf_xdp_detach (IFINDEX_LO ,XDP_FLAGS_SKB_MODE ,NULL ); -ASSERT_OK (err,"XDP program detach" ); - prog_fd =bpf_program__fd (skel->progs.xdp_dummy_cm); map_fd =bpf_map__fd (skel->maps.cpu_map); err =bpf_prog_get_info_by_fd (prog_fd, &info, &len);
@@ -45,6 +51,23 @@ static void test_xdp_with_cpumap_helpers(void)ASSERT_OK (err,"Read cpumap entry" );ASSERT_EQ (info.id, val.bpf_prog.id,"Match program id to cpumap entry prog_id" ); +/* send a packet to trigger any potential bugs in there */ +char data[10 ] = {}; +DECLARE_LIBBPF_OPTS (bpf_test_run_opts, opts, + .data_in = &data, + .data_size_in = 10, + .flags = BPF_F_TEST_XDP_LIVE_FRAMES, + .repeat = 1, + ); + err =bpf_prog_test_run_opts (prog_redir_fd, &opts); +ASSERT_OK (err,"XDP test run" ); + +/* wait for the packets to be flushed */ +kern_sync_rcu (); + + err =bpf_xdp_detach (IFINDEX_LO ,XDP_FLAGS_SKB_MODE ,NULL ); +ASSERT_OK (err,"XDP program detach" ); +/* can not attach BPF_XDP_CPUMAP program to a device */ err =bpf_xdp_attach (IFINDEX_LO , prog_fd,XDP_FLAGS_SKB_MODE ,NULL );if (!ASSERT_NEQ (err,0 ,"Attach of BPF_XDP_CPUMAP program" ))
@@ -65,6 +88,8 @@ static void test_xdp_with_cpumap_helpers(void)ASSERT_NEQ (err,0 ,"Add BPF_XDP program with frags to cpumap entry" ); out_close: +close_netns (nstoken); +SYS_NOFAIL ("ip netns del %s" ,TEST_NS );test_xdp_with_cpumap_helpers__destroy (skel); }
@@ -111,6 +136,88 @@ static void test_xdp_with_cpumap_frags_helpers(void)test_xdp_with_cpumap_frags_helpers__destroy (skel); } +static void test_xdp_with_cpumap_helpers_veth (void ) +{ +int err, cm_fd, cm_fd_redir, map_fd, ifindex_dst, ifindex_src; +struct test_xdp_with_cpumap_helpers *skel =NULL ; +struct bpf_prog_info info = {}; +struct bpf_cpumap_val val = { + .qsize =192 + }; +struct nstoken *nstoken =NULL ; +__u32 len =sizeof (info); +__u32 idx =0 ; + +SYS (out_close,"ip netns add %s" ,TEST_NS ); + nstoken =open_netns (TEST_NS ); +if (!ASSERT_OK_PTR (nstoken,"open_netns" )) + goto out_close; + +SYS (out_close,"ip link add veth_src type veth peer name veth_dst" ); +SYS (out_close,"ip link set dev veth_src up" ); +SYS (out_close,"ip link set dev veth_dst up" ); + + ifindex_src =if_nametoindex ("veth_src" ); + ifindex_dst =if_nametoindex ("veth_dst" ); +if (!ASSERT_NEQ (ifindex_src,0 ,"val.ifindex" ) || + !ASSERT_NEQ (ifindex_dst,0 ,"ifindex_dst" )) + goto out_close; + + skel =test_xdp_with_cpumap_helpers__open_and_load (); +if (!ASSERT_OK_PTR (skel,"test_xdp_with_cpumap_helpers__open_and_load" )) + goto out_close; + + cm_fd_redir =bpf_program__fd (skel->progs.xdp_redir_prog); + err =bpf_xdp_attach (ifindex_src, cm_fd_redir,XDP_FLAGS_DRV_MODE ,NULL ); +if (!ASSERT_OK (err,"Attach of program with 8-byte cpumap" )) + goto out_close; + + cm_fd =bpf_program__fd (skel->progs.xdp_dummy_cm); + map_fd =bpf_map__fd (skel->maps.cpu_map); + err =bpf_prog_get_info_by_fd (cm_fd, &info, &len); +if (!ASSERT_OK (err,"bpf_prog_get_info_by_fd" )) + goto out_close; + + val.bpf_prog.fd = cm_fd; + err =bpf_map_update_elem (map_fd, &idx, &val,0 ); +ASSERT_OK (err,"Add program to cpumap entry" ); + + err =bpf_map_lookup_elem (map_fd, &idx, &val); +ASSERT_OK (err,"Read cpumap entry" ); +ASSERT_EQ (info.id, val.bpf_prog.id,"Match program id to cpumap entry prog_id" ); + +/* attach dummy to other side to enable reception */ + cm_fd =bpf_program__fd (skel->progs.xdp_dummy_prog); + err =bpf_xdp_attach (ifindex_dst, cm_fd,XDP_FLAGS_DRV_MODE ,NULL ); +if (!ASSERT_OK (err,"Attach of dummy XDP" )) + goto out_close; + +/* send a packet to trigger any potential bugs in there */ +char data[10 ] = {}; +DECLARE_LIBBPF_OPTS (bpf_test_run_opts, opts, + .data_in = &data, + .data_size_in = 10, + .flags = BPF_F_TEST_XDP_LIVE_FRAMES, + .repeat = 1, + ); + err =bpf_prog_test_run_opts (cm_fd_redir, &opts); +ASSERT_OK (err,"XDP test run" ); + +/* wait for the packets to be flushed */ +kern_sync_rcu (); + + err =bpf_xdp_detach (ifindex_src,XDP_FLAGS_DRV_MODE ,NULL ); +ASSERT_OK (err,"XDP program detach" ); + + err =bpf_xdp_detach (ifindex_dst,XDP_FLAGS_DRV_MODE ,NULL ); +ASSERT_OK (err,"XDP program detach" ); + +out_close: +close_netns (nstoken); +SYS_NOFAIL ("ip netns del %s" ,TEST_NS ); +test_xdp_with_cpumap_helpers__destroy (skel); +} +void serial_test_xdp_cpumap_attach (void ) {if (test__start_subtest ("CPUMAP with programs in entries" ))
@@ -118,4 +225,7 @@ void serial_test_xdp_cpumap_attach(void)if (test__start_subtest ("CPUMAP with frags programs in entries" ))test_xdp_with_cpumap_frags_helpers (); + +if (test__start_subtest ("CPUMAP attach with programs in entries on veth" )) +test_xdp_with_cpumap_helpers_veth (); }
Signature · 1 line
2.46.2
Martin KaFai Lau
reviewerRe: [PATCH bpf-next v3 2/3] selftests/bpf: make xdp_cpumap_attach keep redirect prog attached
Quoted 51 lines · Alexis Lothoré (eBPF Foundation)
Current test only checks attach/detach on cpu map type program, and so does not check that it can be properly executed, neither that it redirects correctly.
Update the existing test to extend its coverage:
- keep the redirected program loaded
- try to execute it throughbpf_prog_test_run_optswith some dummy contextWhile at it, bring the following minor improvements:
- isolate test interface in its own namespace
- replicate the test on a veth pairSigned-off-by Alexis Lothoré (eBPF Foundation) <[email protected]>---
This change is based on the similar update brought toxdp_devmap_attach([1]) and then realignsxdp_cpumap_attachwith itChanges in v3:
- new patch--- .../selftests/bpf/prog_tests/xdp_cpumap_attach.c | 124 +++++++++++++++++++-- 1 file changed, 117 insertions(+), 7 deletions(-)tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c +3
-1@@ -2,35 +2,41 @@#include <uapi/linux/bpf.h> #include <linux/if_link.h> #include <test_progs.h> +#include <network_helpers.h> #include "test_xdp_with_cpumap_frags_helpers.skel.h" #include "test_xdp_with_cpumap_helpers.skel.h" #define IFINDEX_LO 1 +#define TEST_NS "cpu_attach_ns"static void test_xdp_with_cpumap_helpers (void ) { -struct test_xdp_with_cpumap_helpers *skel; +struct test_xdp_with_cpumap_helpers *skel =NULL ;struct bpf_prog_info info = {};__u32 len =sizeof (info);struct bpf_cpumap_val val = { .qsize =192 , };
tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c line 29
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c +7
-1-int err, prog_fd, map_fd; +int err, prog_fd, prog_redir_fd, map_fd; +struct nstoken *nstoken =NULL ;__u32 idx =0 ; +SYS (out_close,"ip netns add %s" ,TEST_NS ); + nstoken =open_netns (TEST_NS ); +if (!ASSERT_OK_PTR (nstoken,"open_netns" )) + goto out_close; +SYS (out_close,"ip link set dev lo up" );
There is easier helper netns_{new,free} to do all these:
netns_obj = netns_new(TEST_NS, true);
Only fyi for your future work.
Quoted 52 lines
tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c +22
-5+ skel =test_xdp_with_cpumap_helpers__open_and_load ();if (!ASSERT_OK_PTR (skel,"test_xdp_with_cpumap_helpers__open_and_load" ))return ; - prog_fd =bpf_program__fd (skel->progs.xdp_redir_prog); - err =bpf_xdp_attach (IFINDEX_LO , prog_fd,XDP_FLAGS_SKB_MODE ,NULL ); + prog_redir_fd =bpf_program__fd (skel->progs.xdp_redir_prog); + err =bpf_xdp_attach (IFINDEX_LO , prog_redir_fd,XDP_FLAGS_SKB_MODE ,NULL );if (!ASSERT_OK (err,"Generic attach of program with 8-byte CPUMAP" )) goto out_close; - err =bpf_xdp_detach (IFINDEX_LO ,XDP_FLAGS_SKB_MODE ,NULL ); -ASSERT_OK (err,"XDP program detach" ); - prog_fd =bpf_program__fd (skel->progs.xdp_dummy_cm); map_fd =bpf_map__fd (skel->maps.cpu_map); err =bpf_prog_get_info_by_fd (prog_fd, &info, &len);@@ -45,6 +51,23 @@ static void test_xdp_with_cpumap_helpers(void)ASSERT_OK (err,"Read cpumap entry" );ASSERT_EQ (info.id, val.bpf_prog.id,"Match program id to cpumap entry prog_id" ); +/* send a packet to trigger any potential bugs in there */ +char data[10 ] = {}; +DECLARE_LIBBPF_OPTS (bpf_test_run_opts, opts, + .data_in = &data, + .data_size_in = 10, + .flags = BPF_F_TEST_XDP_LIVE_FRAMES, + .repeat = 1, + ); + err =bpf_prog_test_run_opts (prog_redir_fd, &opts); +ASSERT_OK (err,"XDP test run" ); + +/* wait for the packets to be flushed */ +kern_sync_rcu (); + + err =bpf_xdp_detach (IFINDEX_LO ,XDP_FLAGS_SKB_MODE ,NULL ); +ASSERT_OK (err,"XDP program detach" ); +/* can not attach BPF_XDP_CPUMAP program to a device */ err =bpf_xdp_attach (IFINDEX_LO , prog_fd,XDP_FLAGS_SKB_MODE ,NULL );if (!ASSERT_NEQ (err,0 ,"Attach of BPF_XDP_CPUMAP program" ))@@ -65,6 +88,8 @@ static void test_xdp_with_cpumap_helpers(void)ASSERT_NEQ (err,0 ,"Add BPF_XDP program with frags to cpumap entry" ); out_close: +close_netns (nstoken); +SYS_NOFAIL ("ip netns del %s" ,TEST_NS );test_xdp_with_cpumap_helpers__destroy (skel); }
tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c static void test_xdp_with_cpumap_frags_helpers(void) · line 139
Quoted 4 lines
tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c +1
-0@@ -111,6 +136,88 @@ static void test_xdp_with_cpumap_frags_helpers(void)test_xdp_with_cpumap_frags_helpers__destroy (skel); } +static void test_xdp_with_cpumap_helpers_veth (void )
Unlike the devmap redirect, cpumap redirects pkt to another cpu instead of another veth dev. veth test is not very useful here for cpumap, so I take the veth test out.
Quoted 72 lines
tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c +72
-0+{ +int err, cm_fd, cm_fd_redir, map_fd, ifindex_dst, ifindex_src; +struct test_xdp_with_cpumap_helpers *skel =NULL ; +struct bpf_prog_info info = {}; +struct bpf_cpumap_val val = { + .qsize =192 + }; +struct nstoken *nstoken =NULL ; +__u32 len =sizeof (info); +__u32 idx =0 ; + +SYS (out_close,"ip netns add %s" ,TEST_NS ); + nstoken =open_netns (TEST_NS ); +if (!ASSERT_OK_PTR (nstoken,"open_netns" )) + goto out_close; + +SYS (out_close,"ip link add veth_src type veth peer name veth_dst" ); +SYS (out_close,"ip link set dev veth_src up" ); +SYS (out_close,"ip link set dev veth_dst up" ); + + ifindex_src =if_nametoindex ("veth_src" ); + ifindex_dst =if_nametoindex ("veth_dst" ); +if (!ASSERT_NEQ (ifindex_src,0 ,"val.ifindex" ) || + !ASSERT_NEQ (ifindex_dst,0 ,"ifindex_dst" )) + goto out_close; + + skel =test_xdp_with_cpumap_helpers__open_and_load (); +if (!ASSERT_OK_PTR (skel,"test_xdp_with_cpumap_helpers__open_and_load" )) + goto out_close; + + cm_fd_redir =bpf_program__fd (skel->progs.xdp_redir_prog); + err =bpf_xdp_attach (ifindex_src, cm_fd_redir,XDP_FLAGS_DRV_MODE ,NULL ); +if (!ASSERT_OK (err,"Attach of program with 8-byte cpumap" )) + goto out_close; + + cm_fd =bpf_program__fd (skel->progs.xdp_dummy_cm); + map_fd =bpf_map__fd (skel->maps.cpu_map); + err =bpf_prog_get_info_by_fd (cm_fd, &info, &len); +if (!ASSERT_OK (err,"bpf_prog_get_info_by_fd" )) + goto out_close; + + val.bpf_prog.fd = cm_fd; + err =bpf_map_update_elem (map_fd, &idx, &val,0 ); +ASSERT_OK (err,"Add program to cpumap entry" ); + + err =bpf_map_lookup_elem (map_fd, &idx, &val); +ASSERT_OK (err,"Read cpumap entry" ); +ASSERT_EQ (info.id, val.bpf_prog.id,"Match program id to cpumap entry prog_id" ); + +/* attach dummy to other side to enable reception */ + cm_fd =bpf_program__fd (skel->progs.xdp_dummy_prog); + err =bpf_xdp_attach (ifindex_dst, cm_fd,XDP_FLAGS_DRV_MODE ,NULL ); +if (!ASSERT_OK (err,"Attach of dummy XDP" )) + goto out_close; + +/* send a packet to trigger any potential bugs in there */ +char data[10 ] = {}; +DECLARE_LIBBPF_OPTS (bpf_test_run_opts, opts, + .data_in = &data, + .data_size_in = 10, + .flags = BPF_F_TEST_XDP_LIVE_FRAMES, + .repeat = 1, + ); + err =bpf_prog_test_run_opts (cm_fd_redir, &opts); +ASSERT_OK (err,"XDP test run" ); + +/* wait for the packets to be flushed */ +kern_sync_rcu (); + + err =bpf_xdp_detach (ifindex_src,XDP_FLAGS_DRV_MODE ,NULL ); +ASSERT_OK (err,"XDP program detach" ); +
tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c static void test_xdp_with_cpumap_frags_helpers(void) · line 221
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c +9
-0+ err =bpf_xdp_detach (ifindex_dst,XDP_FLAGS_DRV_MODE ,NULL ); +ASSERT_OK (err,"XDP program detach" ); + +out_close: +close_netns (nstoken); +SYS_NOFAIL ("ip netns del %s" ,TEST_NS ); +test_xdp_with_cpumap_helpers__destroy (skel); +} +void serial_test_xdp_cpumap_attach (void )
Thanks for improving the existing test by running in its netns, I also removed the "serial_". Applied. Thanks.
Quoted 11 lines
tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c +3
-0{if (test__start_subtest ("CPUMAP with programs in entries" ))@@ -118,4 +225,7 @@ void serial_test_xdp_cpumap_attach(void)if (test__start_subtest ("CPUMAP with frags programs in entries" ))test_xdp_with_cpumap_frags_helpers (); + +if (test__start_subtest ("CPUMAP attach with programs in entries on veth" )) +test_xdp_with_cpumap_helpers_veth (); }
Re: [PATCH bpf-next v3 2/3] selftests/bpf: make xdp_cpumap_attach keep redirect prog attached
Hello Martin,
Quoted 11 lines · Martin KaFai Lau
Quoted 9 lines · Alexis Lothoré (eBPF Foundation)
- int err,
prog_fd,map_fd;
+ int err,prog_fd,prog_redir_fd,map_fd; + struct nstoken *nstoken = NULL;
__u32idx = 0;
+SYS(out_close, "ip netns add %s", TEST_NS); + nstoken =open_netns(TEST_NS);
+ if (!ASSERT_OK_PTR(nstoken, "open_netns")) + gotoout_close;
+SYS(out_close, "ip link set dev lo up");
Quoted 4 lines
There is easier helper netns_{new,free} to do all these:
netns_obj =netns_new(TEST_NS, true);Only fyi for your future work.
ACK, thanks !
Signature · 3 lines
Alexis Lothoré, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
PATCH v3 3/3 selftests/bpf: check program redirect in xdp_cpumap_attach
In reply to Alexis Lothoré (eBPF Foundation)xdp_cpumap_attach, in its current form, only checks that an xdp cpumap program can be executed, but not that it performs correctly the cpu redirect as configured by userspace (bpf_prog_test_run_opts will return success even if the redirect program returns an error)
Add a check to ensure that the program performs the configured redirect as well. The check is based on a global variable incremented by a chained program executed only if the redirect program properly executes.
---
Changes in v3:
- new patch
--- tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c | 10 ++++++++-- .../testing/selftests/bpf/progs/test_xdp_with_cpumap_helpers.c | 5 +++++ 2 files changed, 13 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c +8 -2
@@ -62,8 +62,11 @@ static void test_xdp_with_cpumap_helpers(void) err =bpf_prog_test_run_opts (prog_redir_fd, &opts);ASSERT_OK (err,"XDP test run" ); -/* wait for the packets to be flushed */ +/* wait for the packets to be flushed, then check that redirect has been +* performed +*/ kern_sync_rcu (); +ASSERT_NEQ (skel->bss->redirect_count,0 ,"redirected packets" ); err =bpf_xdp_detach (IFINDEX_LO ,XDP_FLAGS_SKB_MODE ,NULL );ASSERT_OK (err,"XDP program detach" );
@@ -203,8 +206,11 @@ static void test_xdp_with_cpumap_helpers_veth(void) err =bpf_prog_test_run_opts (cm_fd_redir, &opts);ASSERT_OK (err,"XDP test run" ); -/* wait for the packets to be flushed */ +/* wait for the packets to be flushed, then check that redirect has been +* performed +*/ kern_sync_rcu (); +ASSERT_NEQ (skel->bss->redirect_count,0 ,"redirected packets" ); err =bpf_xdp_detach (ifindex_src,XDP_FLAGS_DRV_MODE ,NULL );ASSERT_OK (err,"XDP program detach" );
tools/testing/selftests/bpf/progs/test_xdp_with_cpumap_helpers.c +5 -0
@@ -12,6 +12,8 @@ struct {__uint (max_entries,4 ); } cpu_map SEC(".maps"); +__u32 redirect_count =0 ; + SEC("xdp")int xdp_redir_prog (struct xdp_md *ctx) {
@@ -27,6 +29,9 @@ int xdp_dummy_prog(struct xdp_md *ctx) SEC("xdp/cpumap")int xdp_dummy_cm (struct xdp_md *ctx) { +if (bpf_get_smp_processor_id () ==0 ) + redirect_count++; +if (ctx->ingress_ifindex ==IFINDEX_LO )return XDP_DROP ;
Signature · 1 line
2.46.2
This series was applied to bpf/bpf-next.git (net) by Martin KaFai Lau <[email protected]>:
Hello:
This series was applied to bpf/bpf-next.git (net)
by Martin KaFai Lau <[email protected]>:
Quoted 11 lines · On Wed, 09 Oct 2024 12:12:06 +0200 you wrote:
Hello,
this small series aims to increase coverage of xdp features intest_progs. The initial versions proposed to reworktest_xdp_features.shto make it fit intest_progs, but some discussions in v1 and v2 showed that the script is still needed as a standalone tool. So this new revision letstest_xdp_features.shas-is, and rather adds missing coverage in existing test (cpu map). The new revision is now also a follow-up to the update performed by Florian Kauer in [1] for devmap programs testing.[...]
Here is the summary with links:
- [bpf-next,v3,1/3] selftests/bpf: fix bpf_map_redirect call for cpu map test
https://git.kernel.org/bpf/bpf-next/c/ac8d16b2d377 - [bpf-next,v3,2/3] selftests/bpf: make xdp_cpumap_attach keep redirect prog attached https://git.kernel.org/bpf/bpf-next/c/d5fbcf46ee82 - [bpf-next,v3,3/3] selftests/bpf: check program redirect in xdp_cpumap_attach https://git.kernel.org/bpf/bpf-next/c/d124d984c8a2
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html