Skip to contentSkip to conversation

refactor mptcp bpf tests

PATCH Superseded Geliang Tang 3 participants 13 messages Apr 2, 2024 – Apr 3, 2024

Subsystems (4)

v5 of 9 Superseded Latest is v9 →

lore
Share & tools
lore

Geliang Tang

author reviewer
#0 lore raw

v5 cover refactor mptcp bpf tests

From: Geliang Tang <[email protected]>

v5:
- drop patch 5 in v4:
Squash to "selftests/bpf: Add bpf scheduler test" 4 cleanup

v4:
- add set_nonblock to make BPF tests stable.
- split 'Squash to "selftests/bpf: Add bpf scheduler test"' into 4 patches.

v3:
- part 1, bpf schedulers.

v2:
- add two more helpers, send_single_byte and send_recv_data.

Refactor mptcp bpf tests using newly added macros MPTCP_BASE_TEST, RUN_MPTCP_TEST and MPTCP_SCHED_TEST macro.

Geliang Tang (10):
Squash to "selftests/bpf: Add bpf scheduler test" 1 nonblock selftests/bpf: Add RUN_MPTCP_TEST macro
Squash to "selftests/bpf: Add bpf scheduler test" 2 verify Squash to "selftests/bpf: Add bpf scheduler test" 3 time selftests/bpf: Add MPTCP_SCHED_TEST macro
Squash to "selftests/bpf: Add bpf_first scheduler & test" Squash to "selftests/bpf: Add bpf_bkup scheduler & test" Squash to "selftests/bpf: Add bpf_rr scheduler & test" Squash to "selftests/bpf: Add bpf_red scheduler & test" Squash to "selftests/bpf: Add bpf_burst scheduler & test"

 .../testing/selftests/bpf/prog_tests/mptcp.c  | 276 ++++++------------
 .../selftests/bpf/progs/mptcp_bpf_bkup.c      |   1 +
 .../selftests/bpf/progs/mptcp_bpf_burst.c     |   1 +
 .../selftests/bpf/progs/mptcp_bpf_first.c     |   1 +
 .../selftests/bpf/progs/mptcp_bpf_red.c       |   1 +
 .../selftests/bpf/progs/mptcp_bpf_rr.c        |   1 +
 6 files changed, 89 insertions(+), 192 deletions(-)
Signature · 1 line
2.40.1
author reviewer
#1 lore raw

PATCH v5 1/10 Squash to "selftests/bpf: Add bpf scheduler test" 1 nonblock

From: Geliang Tang <[email protected]>

BPF tests fail sometimes with "bytes != total_bytes" errors:

# test_default:PASS:sched_init:default 0 nsec
# send_data:PASS:pthread_create 0 nsec
# send_data:FAIL:recv 936000 != 10485760 nr_recv:-1 errno:11 # default: 3041 ms
# server:FAIL:send 7579500 != 10485760 nr_sent:-1 errno:11 # send_data:FAIL:pthread_join thread_ret:-11 \
test_default:PASS:has_bytes_sent addr_1 0 nsec
# test_default:PASS:has_bytes_sent addr_2 0 nsec
# close_netns:PASS:setns 0 nsec

Here errno 11 is EAGAIN. This patch sets server socket to nonblock to fix this. It makes BPF tests stable.

---
 tools/testing/selftests/bpf/prog_tests/mptcp.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
tools/testing/selftests/bpf/prog_tests/mptcp.c +12 -0
index 6e28215d7404..d3d51aee440d 100644
@@ -88,6 +88,16 @@ static void cleanup_netns(struct nstoken *nstoken)
 	SYS_NOFAIL("ip netns del %s", NS_TEST);
 }
 
+static int set_nonblock(int fd)
+{
+	int flags = fcntl(fd, F_GETFL);
+
+	if (flags == -1)
+		return -1;
+
+	return fcntl(fd, flags | O_NONBLOCK);
+}
+
 static int verify_tsk(int map_fd, int client_fd)
 {
 	int err, cfd = client_fd;
@@ -466,6 +476,7 @@ static void test_default(void)
 	server_fd = start_mptcp_server(AF_INET, ADDR_1, PORT_1, 0);
 	client_fd = connect_to_fd(server_fd, 0);
 
+	set_nonblock(server_fd);
 	send_data(server_fd, client_fd, "default");
 	ASSERT_OK(has_bytes_sent(ADDR_1), "has_bytes_sent addr_1");
 	ASSERT_OK(has_bytes_sent(ADDR_2), "has_bytes_sent addr_2");
@@ -639,6 +650,7 @@ static void test_burst(void)
 	server_fd = start_mptcp_server(AF_INET, ADDR_1, PORT_1, 0);
 	client_fd = connect_to_fd(server_fd, 0);
 
+	set_nonblock(server_fd);
 	send_data(server_fd, client_fd, "bpf_burst");
 	ASSERT_OK(has_bytes_sent(ADDR_1), "has_bytes_sent addr 1");
 	ASSERT_OK(has_bytes_sent(ADDR_2), "has_bytes_sent addr 2");
Signature · 1 line
2.40.1
#2 lore raw

Re: [PATCH mptcp-next v5 01/10] Squash to "selftests/bpf: Add bpf scheduler test" 1 nonblock

Quoted 31 lines · Geliang Tang

From: Geliang Tang <[email protected]>

BPF tests fail sometimes with "bytes != total_bytes" errors:

 # test_default:PASS:sched_init:default 0 nsec
 # send_data:PASS:pthread_create 0 nsec
 # send_data:FAIL:recv 936000 != 10485760 nr_recv:-1 errno:11 # default: 3041 ms
 # server:FAIL:send 7579500 != 10485760 nr_sent:-1 errno:11 # send_data:FAIL:pthread_join thread_ret:-11 \
test_default:PASS:has_bytes_sent addr_1 0 nsec
 # test_default:PASS:has_bytes_sent addr_2 0 nsec
 # close_netns:PASS:setns 0 nsec

Here errno 11 is EAGAIN. This patch sets server socket to nonblock to fix this. It makes BPF tests stable.

---
 tools/testing/selftests/bpf/prog_tests/mptcp.c | 12 ++++++++++++

 1 file changed, 12 insertions(+)
tools/testing/selftests/bpf/prog_tests/mptcp.c +0 -0
index 6e28215d7404..d3d51aee440d 100644
@@ -88,6 +88,16 @@ static void cleanup_netns(struct nstoken *nstoken)
  	SYS_NOFAIL("ip netns del %s", NS_TEST);
  }

tools/testing/selftests/bpf/prog_tests/mptcp.c static void cleanup_netns(struct nstoken *nstoken) · line 98

Quoted 8 lines
tools/testing/selftests/bpf/prog_tests/mptcp.c +8 -0
+static int set_nonblock(int fd)
+{
+	int flags = fcntl(fd, F_GETFL);
+
+	if (flags == -1)
+		return -1;
+
+	return fcntl(fd, flags | O_NONBLOCK);

This fix is incorrect. fcntl shouldn't be used like this. I'll think about how to modify it again. BTW, Other patches in this series are still valid. But needs to be rebased.

Thanks,
-Geliang

Quoted 21 lines
tools/testing/selftests/bpf/prog_tests/mptcp.c +2 -0
+}
+

 static int verify_tsk(int map_fd, int client_fd)
 {
  int err, cfd = client_fd;

tools/testing/selftests/bpf/prog_tests/mptcp.c +0 -0
@@ -466,6 +476,7 @@ static void test_default(void)
  	server_fd = start_mptcp_server(AF_INET, ADDR_1, PORT_1, 0);
  	client_fd = connect_to_fd(server_fd, 0);

tools/testing/selftests/bpf/prog_tests/mptcp.c +1 -0
+	set_nonblock(server_fd);

  send_data(server_fd, client_fd, "default"); ASSERT_OK(has_bytes_sent(ADDR_1), "has_bytes_sent addr_1"); ASSERT_OK(has_bytes_sent(ADDR_2), "has_bytes_sent addr_2");

tools/testing/selftests/bpf/prog_tests/mptcp.c +0 -0
@@ -639,6 +650,7 @@ static void test_burst(void)
  	server_fd = start_mptcp_server(AF_INET, ADDR_1, PORT_1, 0);
  	client_fd = connect_to_fd(server_fd, 0);

tools/testing/selftests/bpf/prog_tests/mptcp.c +1 -0
+	set_nonblock(server_fd);

  send_data(server_fd, client_fd, "bpf_burst"); ASSERT_OK(has_bytes_sent(ADDR_1), "has_bytes_sent addr 1"); ASSERT_OK(has_bytes_sent(ADDR_2), "has_bytes_sent addr 2");

author reviewer
#3 lore raw

PATCH v5 2/10 selftests/bpf: Add RUN_MPTCP_TEST macro

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

Each MPTCP subtest tests test__start_subtest(suffix), then invokes test_suffix(). It makes sense to add a new macro RUN_MPTCP_TEST to simpolify the code.

---
 tools/testing/selftests/bpf/prog_tests/mptcp.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
tools/testing/selftests/bpf/prog_tests/mptcp.c +8 -4
index d3d51aee440d..faa0dc37b78e 100644
@@ -663,12 +663,16 @@ static void test_burst(void)
 	mptcp_bpf_burst__destroy(burst_skel);
 }
 
+#define RUN_MPTCP_TEST(suffix)					\
+do {								\
+	if (test__start_subtest(#suffix))			\
+		test_##suffix();				\
+} while (0)
+
 void test_mptcp(void)
 {
-	if (test__start_subtest("base"))
-		test_base();
-	if (test__start_subtest("mptcpify"))
-		test_mptcpify();
+	RUN_MPTCP_TEST(base);
+	RUN_MPTCP_TEST(mptcpify);
 	if (test__start_subtest("default"))
 		test_default();
 	if (test__start_subtest("first"))
Signature · 1 line
2.40.1
author reviewer
#4 lore raw

PATCH v5 3/10 Squash to "selftests/bpf: Add bpf scheduler test" 2 verify

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

Add send_data_and_verify helper.

---
 .../testing/selftests/bpf/prog_tests/mptcp.c  | 44 ++++++++++++++-----
 1 file changed, 33 insertions(+), 11 deletions(-)
tools/testing/selftests/bpf/prog_tests/mptcp.c +33 -11
index faa0dc37b78e..24cd0edc03fc 100644
@@ -465,24 +465,47 @@ static int has_bytes_sent(char *addr)
 	return system(cmd);
 }
 
-static void test_default(void)
+static void send_data_and_verify(char *msg, int addr1, int addr2)
 {
 	int server_fd, client_fd;
-	struct nstoken *nstoken;
 
-	nstoken = sched_init("subflow", "default");
-	if (!ASSERT_OK_PTR(nstoken, "sched_init:default"))
-		goto fail;
 	server_fd = start_mptcp_server(AF_INET, ADDR_1, PORT_1, 0);
+	if (!ASSERT_NEQ(server_fd, -1, "start_mptcp_server"))
+		return;
+
 	client_fd = connect_to_fd(server_fd, 0);
+	if (!ASSERT_NEQ(client_fd, -1, "connect_to_fd"))
+		goto close_server;
 
-	set_nonblock(server_fd);
-	send_data(server_fd, client_fd, "default");
-	ASSERT_OK(has_bytes_sent(ADDR_1), "has_bytes_sent addr_1");
-	ASSERT_OK(has_bytes_sent(ADDR_2), "has_bytes_sent addr_2");
+	if (set_nonblock(server_fd))
+		goto close_server;
+
+	send_data(server_fd, client_fd, msg);
+
+	if (addr1)
+		ASSERT_OK(has_bytes_sent(ADDR_1), "Should have bytes_sent on addr1");
+	else
+		ASSERT_GT(has_bytes_sent(ADDR_1), 0, "Shouldn't have bytes_sent on addr1");
+	if (addr2)
+		ASSERT_OK(has_bytes_sent(ADDR_2), "Should have bytes_sent on addr2");
+	else
+		ASSERT_GT(has_bytes_sent(ADDR_2), 0, "Shouldn't have bytes_sent on addr2");
 
 	close(client_fd);
+close_server:
 	close(server_fd);
+}
+
+static void test_default(void)
+{
+	struct nstoken *nstoken;
+
+	nstoken = sched_init("subflow", "default");
+	if (!ASSERT_OK_PTR(nstoken, "sched_init:default"))
+		goto fail;
+
+	send_data_and_verify("default", 1, 1);
+
 fail:
 	cleanup_netns(nstoken);
 }
@@ -673,8 +696,7 @@ void test_mptcp(void)
 {
 	RUN_MPTCP_TEST(base);
 	RUN_MPTCP_TEST(mptcpify);
-	if (test__start_subtest("default"))
-		test_default();
+	RUN_MPTCP_TEST(default);
 	if (test__start_subtest("first"))
 		test_first();
 	if (test__start_subtest("bkup"))
Signature · 1 line
2.40.1
author reviewer
#5 lore raw

PATCH v5 4/10 Squash to "selftests/bpf: Add bpf scheduler test" 3 time

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

Move time related code into send_data_and_verify.

---
 .../testing/selftests/bpf/prog_tests/mptcp.c  | 23 +++++++++----------
 1 file changed, 11 insertions(+), 12 deletions(-)
tools/testing/selftests/bpf/prog_tests/mptcp.c +11 -12
index 24cd0edc03fc..31808da47ab6 100644
@@ -5,7 +5,6 @@
 #include <linux/const.h>
 #include <netinet/in.h>
 #include <test_progs.h>
-#include <time.h>
 #include "cgroup_helpers.h"
 #include "network_helpers.h"
 #include "mptcp_sock.skel.h"
@@ -388,16 +387,12 @@ static void *server(void *arg)
 static void send_data(int lfd, int fd, char *msg)
 {
 	ssize_t nr_recv = 0, bytes = 0;
-	struct timespec start, end;
-	unsigned int delta_ms;
 	pthread_t srv_thread;
 	void *thread_ret;
 	char batch[1500];
 	int err;
 
 	WRITE_ONCE(stop, 0);
-	if (clock_gettime(CLOCK_MONOTONIC, &start) < 0)
-		return;
 
 	err = pthread_create(&srv_thread, NULL, server, (void *)(long)lfd);
 	if (CHECK(err != 0, "pthread_create", "err:%d errno:%d\n", err, errno))
@@ -414,16 +409,9 @@ static void send_data(int lfd, int fd, char *msg)
 		bytes += nr_recv;
 	}
 
-	if (clock_gettime(CLOCK_MONOTONIC, &end) < 0)
-		return;
-
-	delta_ms = (end.tv_sec - start.tv_sec) * 1000 + (end.tv_nsec - start.tv_nsec) / 1000000;
-
 	CHECK(bytes != total_bytes, "recv", "%zd != %u nr_recv:%zd errno:%d\n",
 	      bytes, total_bytes, nr_recv, errno);
 
-	printf("%s: %u ms\n", msg, delta_ms);
-
 	WRITE_ONCE(stop, 1);
 
 	pthread_join(srv_thread, &thread_ret);
@@ -467,7 +455,9 @@ static int has_bytes_sent(char *addr)
 
 static void send_data_and_verify(char *msg, int addr1, int addr2)
 {
+	struct timespec start, end;
 	int server_fd, client_fd;
+	unsigned int delta_ms;
 
 	server_fd = start_mptcp_server(AF_INET, ADDR_1, PORT_1, 0);
 	if (!ASSERT_NEQ(server_fd, -1, "start_mptcp_server"))
@@ -480,8 +470,17 @@ static void send_data_and_verify(char *msg, int addr1, int addr2)
 	if (set_nonblock(server_fd))
 		goto close_server;
 
+	if (clock_gettime(CLOCK_MONOTONIC, &start) < 0)
+		goto close_server;
+
 	send_data(server_fd, client_fd, msg);
 
+	if (clock_gettime(CLOCK_MONOTONIC, &end) < 0)
+		goto close_server;
+
+	delta_ms = (end.tv_sec - start.tv_sec) * 1000 + (end.tv_nsec - start.tv_nsec) / 1000000;
+	printf("%s: %u ms\n", msg, delta_ms);
+
 	if (addr1)
 		ASSERT_OK(has_bytes_sent(ADDR_1), "Should have bytes_sent on addr1");
 	else
Signature · 1 line
2.40.1
author reviewer
#6 lore raw

PATCH v5 5/10 selftests/bpf: Add MPTCP_SCHED_TEST macro

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

This patch defines MPTCP_SCHED_TEST macro, a template for all scheduler tests. Every scheduler is identified by argument name, and use sysctl to set net.mptcp.scheduler as "bpf_name" to use this sched. Add two veth net devices to simulate the multiple addresses case. Use 'ip mptcp endpoint' command to add the new endpoint ADDR2 to PM netlink. Arguments addr1/add2 means whether the data has been sent on the first/second subflow or not. Send data and check bytes_sent of 'ss' output after it using send_data_and_verify().

---
 .../testing/selftests/bpf/prog_tests/mptcp.c  | 30 +++++++++++++++++++
 1 file changed, 30 insertions(+)
tools/testing/selftests/bpf/prog_tests/mptcp.c +30 -0
index 31808da47ab6..24e3b5a1134c 100644
@@ -509,6 +509,36 @@ static void test_default(void)
 	cleanup_netns(nstoken);
 }
 
+#define MPTCP_SCHED_TEST(name, addr1, addr2)			\
+static void test_##name(void)					\
+{								\
+	struct mptcp_bpf_##name *skel;				\
+	struct nstoken *nstoken;				\
+	struct bpf_link *link;					\
+	struct bpf_map *map;					\
+								\
+	skel = mptcp_bpf_##name##__open_and_load();		\
+	if (!ASSERT_OK_PTR(skel, "open_and_load " #name))	\
+		return;						\
+								\
+	map = bpf_object__find_map_by_name(skel->obj, #name);	\
+	link = bpf_map__attach_struct_ops(map);			\
+	if (!ASSERT_OK_PTR(link, "attach_struct_ops " #name))	\
+		goto skel_destroy;				\
+								\
+	nstoken = sched_init("subflow", "bpf_" #name);		\
+	if (!ASSERT_OK_PTR(nstoken, "sched_init " #name))	\
+		goto link_destroy;				\
+								\
+	send_data_and_verify(#name, atoi(#addr1), atoi(#addr2));\
+								\
+	cleanup_netns(nstoken);					\
+link_destroy:							\
+	bpf_link__destroy(link);				\
+skel_destroy:							\
+	mptcp_bpf_##name##__destroy(skel);			\
+}
+
 static void test_first(void)
 {
 	struct mptcp_bpf_first *first_skel;
Signature · 1 line
2.40.1
author reviewer
#7 lore raw

PATCH v5 6/10 Squash to "selftests/bpf: Add bpf_first scheduler & test"

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

After squashing into this change, the patch "selftests/bpf: Add bpf_first test" can be merged into the patch "selftests/bpf: Add bpf_first scheduler" appending the following lines into commit log:

'''
Using MPTCP_SCHED_TEST macro to add a new test for this bpf_first scheduler, the arguments "1 0" means data has been only sent on the first subflow ADDR1. Run this test by RUN_MPTCP_TEST macro. '''

And update the subject to "selftests/bpf: Add bpf_first scheduler & test".

---
 .../testing/selftests/bpf/prog_tests/mptcp.c  | 38 +------------------
 .../selftests/bpf/progs/mptcp_bpf_first.c     |  1 +
 2 files changed, 3 insertions(+), 36 deletions(-)
tools/testing/selftests/bpf/prog_tests/mptcp.c +2 -36
index 24e3b5a1134c..a6eb437b7a42 100644
@@ -539,40 +539,7 @@ skel_destroy:							\
 	mptcp_bpf_##name##__destroy(skel);			\
 }
 
-static void test_first(void)
-{
-	struct mptcp_bpf_first *first_skel;
-	int server_fd, client_fd;
-	struct nstoken *nstoken;
-	struct bpf_link *link;
-
-	first_skel = mptcp_bpf_first__open_and_load();
-	if (!ASSERT_OK_PTR(first_skel, "bpf_first__open_and_load"))
-		return;
-
-	link = bpf_map__attach_struct_ops(first_skel->maps.first);
-	if (!ASSERT_OK_PTR(link, "bpf_map__attach_struct_ops")) {
-		mptcp_bpf_first__destroy(first_skel);
-		return;
-	}
-
-	nstoken = sched_init("subflow", "bpf_first");
-	if (!ASSERT_OK_PTR(nstoken, "sched_init:bpf_first"))
-		goto fail;
-	server_fd = start_mptcp_server(AF_INET, ADDR_1, PORT_1, 0);
-	client_fd = connect_to_fd(server_fd, 0);
-
-	send_data(server_fd, client_fd, "bpf_first");
-	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");
-
-	close(client_fd);
-	close(server_fd);
-fail:
-	cleanup_netns(nstoken);
-	bpf_link__destroy(link);
-	mptcp_bpf_first__destroy(first_skel);
-}
+MPTCP_SCHED_TEST(first, 1, 0);
 
 static void test_bkup(void)
 {
@@ -726,8 +693,7 @@ void test_mptcp(void)
 	RUN_MPTCP_TEST(base);
 	RUN_MPTCP_TEST(mptcpify);
 	RUN_MPTCP_TEST(default);
-	if (test__start_subtest("first"))
-		test_first();
+	RUN_MPTCP_TEST(first);
 	if (test__start_subtest("bkup"))
 		test_bkup();
 	if (test__start_subtest("rr"))
tools/testing/selftests/bpf/progs/mptcp_bpf_first.c +1 -0
index 23a3e8e69e8f..2d067b25d60b 100644
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 /* Copyright (c) 2022, SUSE. */
+/* Copyright (c) 2024, Kylin Software */
 
 #include <linux/bpf.h>
 #include "bpf_tcp_helpers.h"
Signature · 1 line
2.40.1
author reviewer
#8 lore raw

PATCH v5 7/10 Squash to "selftests/bpf: Add bpf_bkup scheduler & test"

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

After squashing into this change, the patch "selftests/bpf: Add bpf_bkup test" can be merged into the patch "selftests/bpf: Add bpf_bkup scheduler" appending the following lines into commit log:

'''
Using MPTCP_SCHED_TEST macro to add a new test for this bpf_bkup scheduler, the arguments "1 0" means data has been only sent on the first subflow ADDR1. Run this test by RUN_MPTCP_TEST macro. '''

And update the subject to "selftests/bpf: Add bpf_bkup scheduler & test".

---
 .../testing/selftests/bpf/prog_tests/mptcp.c  | 39 +------------------
 .../selftests/bpf/progs/mptcp_bpf_bkup.c      |  1 +
 2 files changed, 3 insertions(+), 37 deletions(-)
tools/testing/selftests/bpf/prog_tests/mptcp.c +2 -37
index a6eb437b7a42..39f83a401c02 100644
@@ -540,41 +540,7 @@ skel_destroy:							\
 }
 
 MPTCP_SCHED_TEST(first, 1, 0);
-
-static void test_bkup(void)
-{
-	struct mptcp_bpf_bkup *bkup_skel;
-	int server_fd, client_fd;
-	struct nstoken *nstoken;
-	struct bpf_link *link;
-
-	bkup_skel = mptcp_bpf_bkup__open_and_load();
-	if (!ASSERT_OK_PTR(bkup_skel, "bpf_bkup__open_and_load"))
-		return;
-
-	link = bpf_map__attach_struct_ops(bkup_skel->maps.bkup);
-	if (!ASSERT_OK_PTR(link, "bpf_map__attach_struct_ops")) {
-		mptcp_bpf_bkup__destroy(bkup_skel);
-		return;
-	}
-
-	nstoken = sched_init("subflow backup", "bpf_bkup");
-	if (!ASSERT_OK_PTR(nstoken, "sched_init:bpf_bkup"))
-		goto fail;
-	server_fd = start_mptcp_server(AF_INET, ADDR_1, PORT_1, 0);
-	client_fd = connect_to_fd(server_fd, 0);
-
-	send_data(server_fd, client_fd, "bpf_bkup");
-	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");
-
-	close(client_fd);
-	close(server_fd);
-fail:
-	cleanup_netns(nstoken);
-	bpf_link__destroy(link);
-	mptcp_bpf_bkup__destroy(bkup_skel);
-}
+MPTCP_SCHED_TEST(bkup, 1, 0);
 
 static void test_rr(void)
 {
@@ -694,8 +660,7 @@ void test_mptcp(void)
 	RUN_MPTCP_TEST(mptcpify);
 	RUN_MPTCP_TEST(default);
 	RUN_MPTCP_TEST(first);
-	if (test__start_subtest("bkup"))
-		test_bkup();
+	RUN_MPTCP_TEST(bkup);
 	if (test__start_subtest("rr"))
 		test_rr();
 	if (test__start_subtest("red"))
tools/testing/selftests/bpf/progs/mptcp_bpf_bkup.c +1 -0
index bfd4644dd592..486407a135c9 100644
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 /* Copyright (c) 2022, SUSE. */
+/* Copyright (c) 2024, Kylin Software */
 
 #include <linux/bpf.h>
 #include "bpf_tcp_helpers.h"
Signature · 1 line
2.40.1
author reviewer
#9 lore raw

PATCH v5 8/10 Squash to "selftests/bpf: Add bpf_rr scheduler & test"

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

After squashing into this change, the patch "selftests/bpf: Add bpf_rr test" can be merged into the patch "selftests/bpf: Add bpf_rr scheduler" appending the following lines into commit log:

'''
Using MPTCP_SCHED_TEST macro to add a new test for this bpf_rr scheduler, the arguments "1 1" means data has been sent on both net devices. Run this test by RUN_MPTCP_TEST macro. '''

And update the subject to "selftests/bpf: Add bpf_rr scheduler & test".

---
 .../testing/selftests/bpf/prog_tests/mptcp.c  | 39 +------------------
 .../selftests/bpf/progs/mptcp_bpf_rr.c        |  1 +
 2 files changed, 3 insertions(+), 37 deletions(-)
tools/testing/selftests/bpf/prog_tests/mptcp.c +2 -37
index 39f83a401c02..36afc0358f9b 100644
@@ -541,41 +541,7 @@ skel_destroy:							\
 
 MPTCP_SCHED_TEST(first, 1, 0);
 MPTCP_SCHED_TEST(bkup, 1, 0);
-
-static void test_rr(void)
-{
-	struct mptcp_bpf_rr *rr_skel;
-	int server_fd, client_fd;
-	struct nstoken *nstoken;
-	struct bpf_link *link;
-
-	rr_skel = mptcp_bpf_rr__open_and_load();
-	if (!ASSERT_OK_PTR(rr_skel, "bpf_rr__open_and_load"))
-		return;
-
-	link = bpf_map__attach_struct_ops(rr_skel->maps.rr);
-	if (!ASSERT_OK_PTR(link, "bpf_map__attach_struct_ops")) {
-		mptcp_bpf_rr__destroy(rr_skel);
-		return;
-	}
-
-	nstoken = sched_init("subflow", "bpf_rr");
-	if (!ASSERT_OK_PTR(nstoken, "sched_init:bpf_rr"))
-		goto fail;
-	server_fd = start_mptcp_server(AF_INET, ADDR_1, PORT_1, 0);
-	client_fd = connect_to_fd(server_fd, 0);
-
-	send_data(server_fd, client_fd, "bpf_rr");
-	ASSERT_OK(has_bytes_sent(ADDR_1), "has_bytes_sent addr 1");
-	ASSERT_OK(has_bytes_sent(ADDR_2), "has_bytes_sent addr 2");
-
-	close(client_fd);
-	close(server_fd);
-fail:
-	cleanup_netns(nstoken);
-	bpf_link__destroy(link);
-	mptcp_bpf_rr__destroy(rr_skel);
-}
+MPTCP_SCHED_TEST(rr, 1, 1);
 
 static void test_red(void)
 {
@@ -661,8 +627,7 @@ void test_mptcp(void)
 	RUN_MPTCP_TEST(default);
 	RUN_MPTCP_TEST(first);
 	RUN_MPTCP_TEST(bkup);
-	if (test__start_subtest("rr"))
-		test_rr();
+	RUN_MPTCP_TEST(rr);
 	if (test__start_subtest("red"))
 		test_red();
 	if (test__start_subtest("burst"))
tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c +1 -0
index 39b7e1cfbbd5..05621467fe48 100644
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 /* Copyright (c) 2022, SUSE. */
+/* Copyright (c) 2024, Kylin Software */
 
 #include <linux/bpf.h>
 #include "bpf_tcp_helpers.h"
Signature · 1 line
2.40.1
author reviewer
#10 lore raw

PATCH v5 9/10 Squash to "selftests/bpf: Add bpf_red scheduler & test"

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

After squashing into this change, the patch "selftests/bpf: Add bpf_red test" can be merged into the patch "selftests/bpf: Add bpf_red scheduler" appending the following lines into commit log:

'''
Using MPTCP_SCHED_TEST macro to add a new test for this bpf_red scheduler, the arguments "1 1" means data has been sent on both net devices. Run this test by RUN_MPTCP_TEST macro. '''

And update the subject to "selftests/bpf: Add bpf_red scheduler & test".

---
 .../testing/selftests/bpf/prog_tests/mptcp.c  | 39 +------------------
 .../selftests/bpf/progs/mptcp_bpf_red.c       |  1 +
 2 files changed, 3 insertions(+), 37 deletions(-)
tools/testing/selftests/bpf/prog_tests/mptcp.c +2 -37
index 36afc0358f9b..110f37e4b159 100644
@@ -542,41 +542,7 @@ skel_destroy:							\
 MPTCP_SCHED_TEST(first, 1, 0);
 MPTCP_SCHED_TEST(bkup, 1, 0);
 MPTCP_SCHED_TEST(rr, 1, 1);
-
-static void test_red(void)
-{
-	struct mptcp_bpf_red *red_skel;
-	int server_fd, client_fd;
-	struct nstoken *nstoken;
-	struct bpf_link *link;
-
-	red_skel = mptcp_bpf_red__open_and_load();
-	if (!ASSERT_OK_PTR(red_skel, "bpf_red__open_and_load"))
-		return;
-
-	link = bpf_map__attach_struct_ops(red_skel->maps.red);
-	if (!ASSERT_OK_PTR(link, "bpf_map__attach_struct_ops")) {
-		mptcp_bpf_red__destroy(red_skel);
-		return;
-	}
-
-	nstoken = sched_init("subflow", "bpf_red");
-	if (!ASSERT_OK_PTR(nstoken, "sched_init:bpf_red"))
-		goto fail;
-	server_fd = start_mptcp_server(AF_INET, ADDR_1, PORT_1, 0);
-	client_fd = connect_to_fd(server_fd, 0);
-
-	send_data(server_fd, client_fd, "bpf_red");
-	ASSERT_OK(has_bytes_sent(ADDR_1), "has_bytes_sent addr 1");
-	ASSERT_OK(has_bytes_sent(ADDR_2), "has_bytes_sent addr 2");
-
-	close(client_fd);
-	close(server_fd);
-fail:
-	cleanup_netns(nstoken);
-	bpf_link__destroy(link);
-	mptcp_bpf_red__destroy(red_skel);
-}
+MPTCP_SCHED_TEST(red, 1, 1);
 
 static void test_burst(void)
 {
@@ -628,8 +594,7 @@ void test_mptcp(void)
 	RUN_MPTCP_TEST(first);
 	RUN_MPTCP_TEST(bkup);
 	RUN_MPTCP_TEST(rr);
-	if (test__start_subtest("red"))
-		test_red();
+	RUN_MPTCP_TEST(red);
 	if (test__start_subtest("burst"))
 		test_burst();
 }
tools/testing/selftests/bpf/progs/mptcp_bpf_red.c +1 -0
index a3f3e5ca5278..62cba8f2d936 100644
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 /* Copyright (c) 2022, SUSE. */
+/* Copyright (c) 2024, Kylin Software */
 
 #include <linux/bpf.h>
 #include "bpf_tcp_helpers.h"
Signature · 1 line
2.40.1
author reviewer
#11 lore raw

PATCH v5 10/10 Squash to "selftests/bpf: Add bpf_burst scheduler & test"

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

After squashing into this change, the patch "selftests/bpf: Add bpf_burst test" can be merged into the patch "selftests/bpf: Add bpf_burst scheduler" appending the following lines into commit log:

'''
Using MPTCP_SCHED_TEST macro to add a new test for this bpf_burst scheduler, the arguments "1 1" means data has been sent on both net devices. Run this test by RUN_MPTCP_TEST macro.
'''

And update the subject to "selftests/bpf: Add bpf_burst scheduler & test".

---
 .../testing/selftests/bpf/prog_tests/mptcp.c  | 40 +------------------
 .../selftests/bpf/progs/mptcp_bpf_burst.c     |  1 +
 2 files changed, 3 insertions(+), 38 deletions(-)
tools/testing/selftests/bpf/prog_tests/mptcp.c +2 -38
index 110f37e4b159..400d329ef2a0 100644
@@ -543,42 +543,7 @@ MPTCP_SCHED_TEST(first, 1, 0);
 MPTCP_SCHED_TEST(bkup, 1, 0);
 MPTCP_SCHED_TEST(rr, 1, 1);
 MPTCP_SCHED_TEST(red, 1, 1);
-
-static void test_burst(void)
-{
-	struct mptcp_bpf_burst *burst_skel;
-	int server_fd, client_fd;
-	struct nstoken *nstoken;
-	struct bpf_link *link;
-
-	burst_skel = mptcp_bpf_burst__open_and_load();
-	if (!ASSERT_OK_PTR(burst_skel, "bpf_burst__open_and_load"))
-		return;
-
-	link = bpf_map__attach_struct_ops(burst_skel->maps.burst);
-	if (!ASSERT_OK_PTR(link, "bpf_map__attach_struct_ops")) {
-		mptcp_bpf_burst__destroy(burst_skel);
-		return;
-	}
-
-	nstoken = sched_init("subflow", "bpf_burst");
-	if (!ASSERT_OK_PTR(nstoken, "sched_init:bpf_burst"))
-		goto fail;
-	server_fd = start_mptcp_server(AF_INET, ADDR_1, PORT_1, 0);
-	client_fd = connect_to_fd(server_fd, 0);
-
-	set_nonblock(server_fd);
-	send_data(server_fd, client_fd, "bpf_burst");
-	ASSERT_OK(has_bytes_sent(ADDR_1), "has_bytes_sent addr 1");
-	ASSERT_OK(has_bytes_sent(ADDR_2), "has_bytes_sent addr 2");
-
-	close(client_fd);
-	close(server_fd);
-fail:
-	cleanup_netns(nstoken);
-	bpf_link__destroy(link);
-	mptcp_bpf_burst__destroy(burst_skel);
-}
+MPTCP_SCHED_TEST(burst, 1, 1);
 
 #define RUN_MPTCP_TEST(suffix)					\
 do {								\
@@ -595,6 +560,5 @@ void test_mptcp(void)
 	RUN_MPTCP_TEST(bkup);
 	RUN_MPTCP_TEST(rr);
 	RUN_MPTCP_TEST(red);
-	if (test__start_subtest("burst"))
-		test_burst();
+	RUN_MPTCP_TEST(burst);
 }
tools/testing/selftests/bpf/progs/mptcp_bpf_burst.c +1 -0
index b3c811564866..6b79267562f1 100644
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 /* Copyright (c) 2023, SUSE. */
+/* Copyright (c) 2024, Kylin Software */
 
 #include <linux/bpf.h>
 #include <limits.h>
Signature · 1 line
2.40.1
#12 lore raw
In reply to Geliang Tang

Hi Geliang,

Thank you for your modifications, that's great!

Our CI did some validations and here is its report:

- KVM Validation: normal: Success! ✅
- KVM Validation: debug: Unstable: 1 failed test(s): selftest_mptcp_join 🔴
- KVM Validation: btf (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/8519039495

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/3619fc2a0f19
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=840483

If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:

    $ cd [kernel source code]
    $ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
        --pull always mptcp/mptcp-upstream-virtme-docker:latest \
        auto-normal

For more details:

https://github.com/multipath-tcp/mptcp-upstream-virtme-docker

Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)

Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)