All of lore.kernel.org
 help / color / mirror / Atom feed
From: Geliang Tang <geliang.tang@suse.com>
To: mptcp@lists.linux.dev
Cc: Geliang Tang <geliang.tang@suse.com>
Subject: [PATCH mptcp-next v2] Squash to "selftests/bpf: Add bpf_first test"
Date: Wed, 17 May 2023 16:40:23 +0800	[thread overview]
Message-ID: <605ac80d58b4d089b74b6eedf003a43862c55b61.1684312597.git.geliang.tang@suse.com> (raw)
In-Reply-To: <a7aff063bf87d2d86207cb8fe7394251aaffd93c.1684312574.git.geliang.tang@suse.com>

Run mptcp sched test in a dedicated netns.

Signed-off-by: Geliang Tang <geliang.tang@suse.com>
---
 .../testing/selftests/bpf/prog_tests/mptcp.c  | 50 ++++++++-----------
 1 file changed, 22 insertions(+), 28 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c
index 77a6997fc82f..bea9c799a531 100644
--- a/tools/testing/selftests/bpf/prog_tests/mptcp.c
+++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c
@@ -253,40 +253,34 @@ static void send_data(int lfd, int fd)
 #define ADDR_1	"10.0.1.1"
 #define ADDR_2	"10.0.1.2"
 
-static void sched_init(char *flags, char *sched)
+static void sched_init(char *ns, char *flags, char *sched)
 {
-	char cmd[64];
-
-	system("ip link add veth1 type veth peer name veth2");
-	snprintf(cmd, sizeof(cmd), "ip addr add %s/24 dev veth1", ADDR_1);
-	system(cmd);
-	system("ip link set veth1 up");
-	snprintf(cmd, sizeof(cmd), "ip addr add %s/24 dev veth2", ADDR_2);
-	system(cmd);
-	system("ip link set veth2 up");
-
-	snprintf(cmd, sizeof(cmd), "ip mptcp endpoint add %s %s", ADDR_2, flags);
-	system(cmd);
-	snprintf(cmd, sizeof(cmd), "sysctl -qw net.mptcp.scheduler=%s", sched);
-	system(cmd);
+	SYS_NOFAIL("ip -net %s link add veth1 type veth peer name veth2", ns);
+	SYS_NOFAIL("ip -net %s addr add %s/24 dev veth1", ns, ADDR_1);
+	SYS_NOFAIL("ip -net %s link set dev veth1 up", ns);
+	SYS_NOFAIL("ip -net %s addr add %s/24 dev veth2", ns, ADDR_2);
+	SYS_NOFAIL("ip -net %s link set dev veth2 up", ns);
+	SYS_NOFAIL("ip -net %s mptcp endpoint add %s %s", ns, ADDR_2, flags);
+	SYS_NOFAIL("ip netns exec %s sysctl -qw net.mptcp.scheduler=%s", ns, sched);
 }
 
-static void sched_cleanup(void)
+static void sched_cleanup(char *ns)
 {
-	system("sysctl -qw net.mptcp.scheduler=default");
-	system("ip mptcp endpoint flush");
-	system("ip link del veth1");
+	SYS_NOFAIL("ip netns exec %s sysctl -qw net.mptcp.scheduler=default", ns);
+	SYS_NOFAIL("ip -net %s mptcp endpoint flush", ns);
+	SYS_NOFAIL("ip -net %s link del veth1", ns);
 }
 
-static int has_bytes_sent(char *addr)
+static int has_bytes_sent(char *ns, char *addr)
 {
-	char cmd[64];
+	char cmd[128];
 
-	snprintf(cmd, sizeof(cmd), "ss -it dst %s | grep -q 'bytes_sent:'", addr);
+	snprintf(cmd, sizeof(cmd), "ip netns exec %s ss -it dst %s | grep -q bytes_sent:",
+		 ns, addr);
 	return system(cmd);
 }
 
-static void test_first(void)
+static void test_first(char *ns)
 {
 	struct mptcp_bpf_first *first_skel;
 	int server_fd, client_fd;
@@ -302,17 +296,17 @@ static void test_first(void)
 		return;
 	}
 
-	sched_init("subflow", "bpf_first");
+	sched_init(ns, "subflow", "bpf_first");
 	server_fd = start_mptcp_server(AF_INET, ADDR_1, 0, 0);
 	client_fd = connect_to_fd(server_fd, 0);
 
 	send_data(server_fd, client_fd);
-	ASSERT_OK(has_bytes_sent(ADDR_1), "has_bytes_sent addr_1");
-	ASSERT_GT(has_bytes_sent(ADDR_2), 0, "has_bytes_sent addr_2");
+	ASSERT_OK(has_bytes_sent(ns, ADDR_1), "has_bytes_sent addr_1");
+	ASSERT_GT(has_bytes_sent(ns, ADDR_2), 0, "has_bytes_sent addr_2");
 
 	close(client_fd);
 	close(server_fd);
-	sched_cleanup();
+	sched_cleanup(ns);
 	bpf_link__destroy(link);
 	mptcp_bpf_first__destroy(first_skel);
 }
@@ -334,7 +328,7 @@ void test_mptcp(void)
 	if (test__start_subtest("base"))
 		test_base();
 	if (test__start_subtest("first"))
-		test_first();
+		test_first(NS_TEST);
 
 	if (nstoken)
 		close_netns(nstoken);
-- 
2.35.3


  reply	other threads:[~2023-05-17  8:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-17  8:40 [PATCH mptcp-next v2] selftests/bpf: use random netns name for mptcp Geliang Tang
2023-05-17  8:40 ` Geliang Tang [this message]
2023-05-17  8:55   ` [PATCH mptcp-next v2] Squash to "selftests/bpf: Add bpf_first test" Matthieu Baerts
2023-05-17  8:40 ` [PATCH mptcp-next v2] Squash to "selftests/bpf: Add bpf_bkup test" Geliang Tang
2023-05-17  8:40 ` [PATCH mptcp-next v2] Squash to "selftests/bpf: Add bpf_rr test" Geliang Tang
2023-05-17  8:40 ` [PATCH mptcp-next v2] Squash to "selftests/bpf: Add bpf_red test" Geliang Tang
2023-05-17  8:48   ` Geliang Tang
  -- strict thread matches above, loose matches on Subject: below --
2022-05-19  8:25 [PATCH mptcp-next v2 0/7] for bpf-next Geliang Tang
2022-05-19  8:25 ` [PATCH mptcp-next v2] Squash to "selftests/bpf: add bpf_first test" Geliang Tang

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=605ac80d58b4d089b74b6eedf003a43862c55b61.1684312597.git.geliang.tang@suse.com \
    --to=geliang.tang@suse.com \
    --cc=mptcp@lists.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.