selftests: bpf: Migrate test_xdp_redirect.sh to test_progs
Subsystems (6)
v2 cover selftests: bpf: Migrate test_xdp_redirect.sh to test_progs
Hi all,
This patch series continues the work to migrate the *.sh tests into prog_tests.
test_xdp_redirect.sh tests the XDP redirections done through bpf_redirect().
These XDP redirections are already tested by prog_tests/xdp_do_redirect.c but IMO it doesn't cover the exact same code path because xdp_do_redirect.c uses bpf_prog_test_run_opts() to trigger redirections of 'fake packets' while test_xdp_redirect.sh redirects packets coming from the network. Also, the test_xdp_redirect.sh script tests the redirections with both SKB and DRV modes while xdp_do_redirect.c only tests the DRV mode.
The patch series adds two new test cases in prog_tests/xdp_do_redirect.c to replace the test_xdp_redirect.sh script.
---
Changes in v2:
- Use directly skel->progs instead of 'bpf_object__find_program_by_name()'
- Use 'ip -n NSX' in SYS calls instead of opening NSX with open_netns()
- Use #define for static indexes of veth1 and veth2
- Delete the useless second ping
- Set nstoken to NULL after close_netns()
- Merge the two added tests into one with 3 subtests (one for each flag:
0, DRV, SKB)
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Bastien Curutchet (eBPF Foundation) (3):
selftests/bpf: test_xdp_redirect: Rename BPF sections selftests/bpf: Migrate test_xdp_redirect.sh to xdp_do_redirect.c selftests/bpf: Migrate test_xdp_redirect.c to test_xdp_do_redirect.c
tools/testing/selftests/bpf/Makefile | 1 - .../selftests/bpf/prog_tests/xdp_do_redirect.c | 164 +++++++++++++++++++++ .../selftests/bpf/progs/test_xdp_do_redirect.c | 12 ++ .../selftests/bpf/progs/test_xdp_redirect.c | 26 ---- tools/testing/selftests/bpf/test_xdp_redirect.sh | 79 ---------- 5 files changed, 176 insertions(+), 106 deletions(-)
---
base-commit: b27feb5365c6a1bf7e71ba5c795717ee0eec298d
change-id: 20241219-xdp_redirect-2b8ec79dc24e
Best regards,
Signature · 1 line
Bastien Curutchet (eBPF Foundation) <[email protected]>
PATCH v2 1/3 selftests/bpf: test_xdp_redirect: Rename BPF sections
SEC("redirect_to_111") and SEC("redirect_to_222") can't be loaded by the __load() helper.
Rename both sections SEC("xdp") so it can be interpreted by the __load() helper in upcoming patch.
Update the test_xdp_redirect.sh to use the program name instead of the section name to load the BPF program.
--- tools/testing/selftests/bpf/progs/test_xdp_redirect.c | 4 ++-- tools/testing/selftests/bpf/test_xdp_redirect.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
tools/testing/selftests/bpf/progs/test_xdp_redirect.c +2 -2
@@ -12,12 +12,12 @@#include <linux/bpf.h> #include <bpf/bpf_helpers.h> -SEC("redirect_to_111") +SEC("xdp")int xdp_redirect_to_111 (struct xdp_md *xdp) {return bpf_redirect (111 ,0 ); } -SEC("redirect_to_222") +SEC("xdp")int xdp_redirect_to_222 (struct xdp_md *xdp) {return bpf_redirect (222 ,0 );
tools/testing/selftests/bpf/test_xdp_redirect.sh +2 -2
@@ -56,8 +56,8 @@ test_xdp_redirect() ip -n ${NS1} link set veth11 $xdpmode obj xdp_dummy.bpf.o sec xdp &> /dev/null ip -n ${NS2} link set veth22 $xdpmode obj xdp_dummy.bpf.o sec xdp &> /dev/null - ip link set dev veth1 $xdpmode obj test_xdp_redirect.bpf.o sec redirect_to_222 &> /dev/null - ip link set dev veth2 $xdpmode obj test_xdp_redirect.bpf.o sec redirect_to_111 &> /dev/null + ip link set dev veth1 $xdpmode obj test_xdp_redirect.bpf.o program xdp_redirect_to_222 &> /dev/null + ip link set dev veth2 $xdpmode obj test_xdp_redirect.bpf.o program xdp_redirect_to_111 &> /dev/null if ip netns exec ${NS1} ping -c 1 10.1.1.22 &> /dev/null && ip netns exec ${NS2} ping -c 1 10.1.1.11 &> /dev/null; then
Signature · 1 line
2.47.1
PATCH v2 2/3 selftests/bpf: Migrate test_xdp_redirect.sh to xdp_do_redirect.c
In reply to Bastien Curutchet (eBPF Foundation)test_xdp_redirect.sh can't be used by the BPF CI.
Migrate test_xdp_redirect.sh into a new test case in xdp_do_redirect.c. It uses the same network topology and the same BPF programs located in progs/test_xdp_redirect.c and progs/xdp_dummy.c.
Remove test_xdp_redirect.sh and its Makefile entry.
--- tools/testing/selftests/bpf/Makefile | 1 - .../selftests/bpf/prog_tests/xdp_do_redirect.c | 165 +++++++++++++++++++++ tools/testing/selftests/bpf/test_xdp_redirect.sh | 79 ---------- 3 files changed, 165 insertions(+), 80 deletions(-)
tools/testing/selftests/bpf/Makefile +0 -1
@@ -100,7 +100,6 @@ TEST_FILES = xsk_prereqs.sh $(wildcard progs/btf_dump_test_case_*.c) # Order correspond to 'make run_tests' order TEST_PROGS := test_kmod.sh \ - test_xdp_redirect.sh \ test_xdp_redirect_multi.sh \ test_xdp_meta.sh \ test_tunnel.sh \
tools/testing/selftests/bpf/prog_tests/xdp_do_redirect.c +165 -0
174 lines not on this page · raw message
tools/testing/selftests/bpf/test_xdp_redirect.sh deleted +0 -79
79 lines not on this page · raw message
Signature · 1 line
2.47.1
Re: [PATCH bpf-next v2 2/3] selftests/bpf: Migrate test_xdp_redirect.sh to xdp_do_redirect.c
Quoted 47 lines · Bastien Curutchet (eBPF Foundation)
tools/testing/selftests/bpf/prog_tests/xdp_do_redirect.c +47
-0+static void ping_test (struct test_data *data) +{ +struct test_xdp_redirect *skel =NULL ; +struct xdp_dummy *skel_dummy =NULL ; +struct nstoken *nstoken =NULL ; +int i, ret; + + skel_dummy =xdp_dummy__open_and_load (); +if (!ASSERT_OK_PTR (skel_dummy,"open and load xdp_dummy skeleton" )) + goto close; + +for (i =1 ; i <NS_NB ; i++) { +char ns_name[4 ] = {}; + +snprintf (ns_name,4 ,"NS%d" , i); + nstoken =open_netns (ns_name); +if (!ASSERT_OK_PTR (nstoken,"open ns" )) + goto close; + + ret =bpf_xdp_attach (if_nametoindex ("veth0" ), +bpf_program__fd (skel_dummy->progs.xdp_dummy_prog), + data->xdp_flags,NULL ); +if (!ASSERT_GE (ret,0 ,"bpf_xdp_attach dummy_prog" )) + goto close; + +close_netns (nstoken); + nstoken =NULL ; + } + + skel =test_xdp_redirect__open_and_load (); +if (!ASSERT_OK_PTR (skel,"open and load skeleton" )) + goto close; + + nstoken =open_netns (NS0 ); +if (!ASSERT_OK_PTR (nstoken,"open NS0" )) + goto close; + + ret =bpf_xdp_attach (VETH2_INDEX , +bpf_program__fd (skel->progs.xdp_redirect_to_111), + data->xdp_flags,NULL ); +if (!ASSERT_GE (ret,0 ,"bpf_xdp_attach" )) + goto close; + + ret =bpf_xdp_attach (VETH1_INDEX , +bpf_program__fd (skel->progs.xdp_redirect_to_222), + data->xdp_flags,NULL ); +if (!ASSERT_GE (ret,0 ,"bpf_xdp_attach" ))
tools/testing/selftests/bpf/prog_tests/xdp_do_redirect.c void test_xdp_do_redirect(void) · line 381
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/xdp_do_redirect.c +10
-0+ goto close; + +close_netns (nstoken); + nstoken =NULL ; + + nstoken =open_netns (NS1 ); +if (!ASSERT_OK_PTR (nstoken,"open NS1" )) + goto close; + +SYS (close,"ping -c 1 %s.2" ,IPV4_NETWORK );
I added "> /dev/null" to remove noise for common case.
Applied. Thanks.
PATCH v2 3/3 selftests/bpf: Migrate test_xdp_redirect.c to test_xdp_do_redirect.c
In reply to Bastien Curutchet (eBPF Foundation)prog_tests/xdp_do_redirect.c is the only user of the BPF programs located in progs/test_xdp_do_redirect.c and progs/test_xdp_redirect.c. There is no need to keep both files with such close names.
Move test_xdp_redirect.c contents to test_xdp_do_redirect.c and remove progs/test_xdp_redirect.c
--- .../selftests/bpf/prog_tests/xdp_do_redirect.c | 7 +++--- .../selftests/bpf/progs/test_xdp_do_redirect.c | 12 ++++++++++ .../selftests/bpf/progs/test_xdp_redirect.c | 26 ---------------------- 3 files changed, 15 insertions(+), 30 deletions(-)
tools/testing/selftests/bpf/prog_tests/xdp_do_redirect.c +3 -4
@@ -11,7 +11,6 @@#include <bpf/bpf_endian.h> #include <uapi/linux/netdev.h> #include "test_xdp_do_redirect.skel.h" -#include "test_xdp_redirect.skel.h" #include "xdp_dummy.skel.h" struct udp_packet {
@@ -324,7 +323,7 @@ static int ping_setup(struct test_data *data)static void ping_test (struct test_data *data) { -struct test_xdp_redirect *skel =NULL ; +struct test_xdp_do_redirect *skel =NULL ;struct xdp_dummy *skel_dummy =NULL ;struct nstoken *nstoken =NULL ;int i, ret;
@@ -351,7 +350,7 @@ static void ping_test(struct test_data *data) nstoken =NULL ; } - skel =test_xdp_redirect__open_and_load (); + skel =test_xdp_do_redirect__open_and_load ();if (!ASSERT_OK_PTR (skel,"open and load skeleton" )) goto close;
@@ -383,7 +382,7 @@ static void ping_test(struct test_data *data) close:close_netns (nstoken);xdp_dummy__destroy (skel_dummy); -test_xdp_redirect__destroy (skel); +test_xdp_do_redirect__destroy (skel); }
tools/testing/selftests/bpf/progs/test_xdp_do_redirect.c +12 -0
@@ -98,6 +98,18 @@ int xdp_count_pkts(struct xdp_md *xdp)return XDP_DROP ; } +SEC("xdp") +int xdp_redirect_to_111 (struct xdp_md *xdp) +{ +return bpf_redirect (111 ,0 ); +} + +SEC("xdp") +int xdp_redirect_to_222 (struct xdp_md *xdp) +{ +return bpf_redirect (222 ,0 ); +} + SEC("tc")int tc_count_pkts (struct __sk_buff *skb) {
tools/testing/selftests/bpf/progs/test_xdp_redirect.c deleted +0 -26
@@ -1,26 +0,0 @@ -/* Copyright (c) 2017 VMware -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of version 2 of the GNU General Public -* License as published by the Free Software Foundation. -* -* This program is distributed in the hope that it will be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -* General Public License for more details. -*/ -#include <linux/bpf.h> -#include <bpf/bpf_helpers.h> - -SEC("xdp") -int xdp_redirect_to_111 (struct xdp_md *xdp) -{ -return bpf_redirect (111 ,0 ); -} -SEC("xdp") -int xdp_redirect_to_222 (struct xdp_md *xdp) -{ -return bpf_redirect (222 ,0 ); -} - -char _license[] SEC("license") = "GPL";
Signature · 1 line
2.47.1
This series was applied to bpf/bpf-next.git (master) by Martin KaFai Lau <[email protected]>:
Hello:
This series was applied to bpf/bpf-next.git (master) by Martin KaFai Lau <[email protected]>:
Quoted 9 lines · On Fri, 10 Jan 2025 10:21:08 +0100 you wrote:
Hi all,
This patch series continues the work to migrate the *.sh tests into
prog_tests.
test_xdp_redirect.shtests the XDP redirections done throughbpf_redirect().[...]
Here is the summary with links:
- [bpf-next,v2,1/3] selftests/bpf: test_xdp_redirect: Rename BPF sections
https://git.kernel.org/bpf/bpf-next/c/2c6c5c7c1ad1 - [bpf-next,v2,2/3] selftests/bpf: Migrate test_xdp_redirect.sh to xdp_do_redirect.c (no matching commit) - [bpf-next,v2,3/3] selftests/bpf: Migrate test_xdp_redirect.c to test_xdp_do_redirect.c https://git.kernel.org/bpf/bpf-next/c/3e99fa9fab19
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html