From: "Bastien Curutchet (eBPF Foundation)" <bastien.curutchet@bootlin.com>
To: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@fomichev.me>,
Hao Luo <haoluo@google.com>, Jiri Olsa <jolsa@kernel.org>,
Mykola Lysenko <mykolal@fb.com>, Shuah Khan <shuah@kernel.org>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
Alexis Lothore <alexis.lothore@bootlin.com>,
bpf@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org,
"Bastien Curutchet (eBPF Foundation)"
<bastien.curutchet@bootlin.com>
Subject: [PATCH bpf-next v2 02/10] selftests/bpf: test_tunnel: Add ping helpers
Date: Mon, 03 Mar 2025 09:22:50 +0100 [thread overview]
Message-ID: <20250303-tunnels-v2-2-8329f38f0678@bootlin.com> (raw)
In-Reply-To: <20250303-tunnels-v2-0-8329f38f0678@bootlin.com>
All tests use more or less the same ping commands as final validation.
Also test_ping()'s return value is checked with ASSERT_OK() while this
check is already done by the SYS() macro inside test_ping().
Create helpers around test_ping() and use them in the tests to avoid code
duplication.
Remove the unnecessary ASSERT_OK() from the tests.
Acked-by: Stanislav Fomichev <sdf@fomichev.me>
Signed-off-by: Bastien Curutchet (eBPF Foundation) <bastien.curutchet@bootlin.com>
---
.../testing/selftests/bpf/prog_tests/test_tunnel.c | 53 ++++++++++------------
1 file changed, 24 insertions(+), 29 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/test_tunnel.c b/tools/testing/selftests/bpf/prog_tests/test_tunnel.c
index cc03a4440182cfff94f8421c3f5362aaf470086d..09e674c147bb31e239476b66eb5f57fc2b447cd9 100644
--- a/tools/testing/selftests/bpf/prog_tests/test_tunnel.c
+++ b/tools/testing/selftests/bpf/prog_tests/test_tunnel.c
@@ -364,6 +364,25 @@ static int test_ping(int family, const char *addr)
return -1;
}
+static void ping_dev0(void)
+{
+ /* ping from root namespace test */
+ test_ping(AF_INET, IP4_ADDR_TUNL_DEV0);
+}
+
+static void ping_dev1(void)
+{
+ struct nstoken *nstoken;
+
+ /* ping from at_ns0 namespace test */
+ nstoken = open_netns("at_ns0");
+ if (!ASSERT_OK_PTR(nstoken, "setns"))
+ return;
+
+ test_ping(AF_INET, IP4_ADDR_TUNL_DEV1);
+ close_netns(nstoken);
+}
+
static int attach_tc_prog(int ifindex, int igr_fd, int egr_fd)
{
DECLARE_LIBBPF_OPTS(bpf_tc_hook, hook, .ifindex = ifindex,
@@ -492,9 +511,7 @@ static void test_vxlan_tunnel(void)
goto done;
/* ping test */
- err = test_ping(AF_INET, IP4_ADDR_TUNL_DEV0);
- if (!ASSERT_OK(err, "test_ping"))
- goto done;
+ ping_dev0();
done:
/* delete vxlan tunnel */
@@ -549,9 +566,7 @@ static void test_ip6vxlan_tunnel(void)
goto done;
/* ping test */
- err = test_ping(AF_INET, IP4_ADDR_TUNL_DEV0);
- if (!ASSERT_OK(err, "test_ping"))
- goto done;
+ ping_dev0();
done:
/* delete ipv6 vxlan tunnel */
@@ -565,7 +580,6 @@ static void test_ip6vxlan_tunnel(void)
static void test_ipip_tunnel(enum ipip_encap encap)
{
struct test_tunnel_kern *skel = NULL;
- struct nstoken *nstoken;
int set_src_prog_fd, get_src_prog_fd;
int err;
@@ -602,19 +616,8 @@ static void test_ipip_tunnel(enum ipip_encap encap)
if (generic_attach(IPIP_TUNL_DEV1, get_src_prog_fd, set_src_prog_fd))
goto done;
- /* ping from root namespace test */
- err = test_ping(AF_INET, IP4_ADDR_TUNL_DEV0);
- if (!ASSERT_OK(err, "test_ping"))
- goto done;
-
- /* ping from at_ns0 namespace test */
- nstoken = open_netns("at_ns0");
- if (!ASSERT_OK_PTR(nstoken, "setns"))
- goto done;
- err = test_ping(AF_INET, IP4_ADDR_TUNL_DEV1);
- if (!ASSERT_OK(err, "test_ping"))
- goto done;
- close_netns(nstoken);
+ ping_dev0();
+ ping_dev1();
done:
/* delete ipip tunnel */
@@ -627,7 +630,6 @@ static void test_xfrm_tunnel(void)
{
LIBBPF_OPTS(bpf_xdp_attach_opts, opts);
struct test_tunnel_kern *skel = NULL;
- struct nstoken *nstoken;
int xdp_prog_fd;
int tc_prog_fd;
int ifindex;
@@ -658,14 +660,7 @@ static void test_xfrm_tunnel(void)
if (!ASSERT_OK(err, "bpf_xdp_attach"))
goto done;
- /* ping from at_ns0 namespace test */
- nstoken = open_netns("at_ns0");
- if (!ASSERT_OK_PTR(nstoken, "setns"))
- goto done;
- err = test_ping(AF_INET, IP4_ADDR_TUNL_DEV1);
- close_netns(nstoken);
- if (!ASSERT_OK(err, "test_ping"))
- goto done;
+ ping_dev1();
if (!ASSERT_EQ(skel->bss->xfrm_reqid, 1, "req_id"))
goto done;
--
2.48.1
next prev parent reply other threads:[~2025-03-03 8:22 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-03 8:22 [PATCH bpf-next v2 00/10] selftests/bpf: Migrate test_tunnel.sh to test_progs Bastien Curutchet (eBPF Foundation)
2025-03-03 8:22 ` [PATCH bpf-next v2 01/10] selftests/bpf: test_tunnel: Add generic_attach* helpers Bastien Curutchet (eBPF Foundation)
2025-03-03 15:47 ` Stanislav Fomichev
2025-03-03 8:22 ` Bastien Curutchet (eBPF Foundation) [this message]
2025-03-03 8:22 ` [PATCH bpf-next v2 03/10] selftests/bpf: test_tunnel: Move gre tunnel test to test_progs Bastien Curutchet (eBPF Foundation)
2025-03-03 8:22 ` [PATCH bpf-next v2 04/10] selftests/bpf: test_tunnel: Move ip6gre " Bastien Curutchet (eBPF Foundation)
2025-03-03 15:47 ` Stanislav Fomichev
2025-03-03 8:22 ` [PATCH bpf-next v2 05/10] selftests/bpf: test_tunnel: Move erspan tunnel tests " Bastien Curutchet (eBPF Foundation)
2025-03-03 8:22 ` [PATCH bpf-next v2 06/10] selftests/bpf: test_tunnel: Move ip6erspan tunnel test " Bastien Curutchet (eBPF Foundation)
2025-03-03 8:22 ` [PATCH bpf-next v2 07/10] selftests/bpf: test_tunnel: Move geneve " Bastien Curutchet (eBPF Foundation)
2025-03-03 8:22 ` [PATCH bpf-next v2 08/10] selftests/bpf: test_tunnel: Move ip6geneve " Bastien Curutchet (eBPF Foundation)
2025-03-03 8:22 ` [PATCH bpf-next v2 09/10] selftests/bpf: test_tunnel: Move ip6tnl tunnel tests " Bastien Curutchet (eBPF Foundation)
2025-03-03 8:22 ` [PATCH bpf-next v2 10/10] selftests/bpf: test_tunnel: Remove test_tunnel.sh Bastien Curutchet (eBPF Foundation)
2025-03-03 22:30 ` [PATCH bpf-next v2 00/10] selftests/bpf: Migrate test_tunnel.sh to test_progs patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250303-tunnels-v2-2-8329f38f0678@bootlin.com \
--to=bastien.curutchet@bootlin.com \
--cc=alexis.lothore@bootlin.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=mykolal@fb.com \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=thomas.petazzoni@bootlin.com \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox