Skip to contentSkip to conversation

run sched tests in a dedicated ns

PATCH In review Geliang Tang 4 participants 14 messages May 17, 2023 – May 19, 2023

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v4 cover run sched tests in a dedicated ns

v4:
- patch #1 could be merged before "mptcp: refactor push_pending logic" as a single fix.
- patch #2 should be merged between "selftests/bpf: Add mptcp sched structs" and "selftests/bpf: Add bpf_first scheduler".

v3:
- add two helpers.
- drop sched_cleanup().

Geliang Tang (6):
selftests/bpf: use random netns name for mptcp
selftests/bpf: add two mptcp netns helpers
Squash to "selftests/bpf: Add bpf_first test"
Squash to "selftests/bpf: Add bpf_bkup test"
Squash to "selftests/bpf: Add bpf_rr test"
Squash to "selftests/bpf: Add bpf_red test"

 .../testing/selftests/bpf/prog_tests/mptcp.c  | 109 +++++++++++-------
 1 file changed, 68 insertions(+), 41 deletions(-)
Signature · 1 line
2.35.3
#1 lore raw

PATCH v4 1/6 selftests/bpf: use random netns name for mptcp

Use rand() to generate a random netns name instead of using the fixed name "mptcp_ns" for every test.

Fixes 02d6a057c7be ("selftests/bpf: run mptcp in a dedicated netns")
---
 tools/testing/selftests/bpf/prog_tests/mptcp.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/mptcp.c +3 -1
index de8b6c68fc30..8040997e4aef 100644
@@ -11,7 +11,7 @@
 #include "mptcp_bpf_rr.skel.h"
 #include "mptcp_bpf_red.skel.h"
 
-#define NS_TEST "mptcp_ns"
+char NS_TEST[32];
 
 #ifndef TCP_CA_NAME_MAX
 #define TCP_CA_NAME_MAX	16
@@ -151,6 +151,8 @@ static void test_base(void)
 	if (!ASSERT_GE(cgroup_fd, 0, "test__join_cgroup"))
 		return;
 
+	srand(time(NULL));
+	snprintf(NS_TEST, sizeof(NS_TEST), "mptcp_ns_%d", rand());
 	SYS(fail, "ip netns add %s", NS_TEST);
 	SYS(fail, "ip -net %s link set dev lo up", NS_TEST);
 
Signature · 1 line
2.35.3
#5 lore raw

PATCH v4 3/6 Squash to "selftests/bpf: Add bpf_first test"

In reply to Geliang Tang

Run mptcp sched test in a dedicated netns.

---
 .../testing/selftests/bpf/prog_tests/mptcp.c  | 51 ++++++++++---------
 1 file changed, 26 insertions(+), 25 deletions(-)
tools/testing/selftests/bpf/prog_tests/mptcp.c +26 -25
index ce9dc3ef3d40..85e37e0f64a3 100644
@@ -285,36 +285,33 @@ 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 struct nstoken *sched_init(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);
-}
+	struct nstoken *nstoken;
 
-static void sched_cleanup(void)
-{
-	system("sysctl -qw net.mptcp.scheduler=default");
-	system("ip mptcp endpoint flush");
-	system("ip link del veth1");
+	nstoken = create_netns();
+	if (!ASSERT_OK_PTR(nstoken, "create_netns"))
+		goto fail;
+
+	SYS(fail, "ip -net %s link add veth1 type veth peer name veth2", NS_TEST);
+	SYS(fail, "ip -net %s addr add %s/24 dev veth1", NS_TEST, ADDR_1);
+	SYS(fail, "ip -net %s link set dev veth1 up", NS_TEST);
+	SYS(fail, "ip -net %s addr add %s/24 dev veth2", NS_TEST, ADDR_2);
+	SYS(fail, "ip -net %s link set dev veth2 up", NS_TEST);
+	SYS(fail, "ip -net %s mptcp endpoint add %s %s", NS_TEST, ADDR_2, flags);
+	SYS(fail, "ip netns exec %s sysctl -qw net.mptcp.scheduler=%s", NS_TEST, sched);
+
+	return nstoken;
+fail:
+	return NULL;
 }
 
 static int has_bytes_sent(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_TEST, addr);
 	return system(cmd);
 }
 
@@ -322,6 +319,7 @@ 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();
@@ -334,7 +332,9 @@ static void test_first(void)
 		return;
 	}
 
-	sched_init("subflow", "bpf_first");
+	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, 0, 0);
 	client_fd = connect_to_fd(server_fd, 0);
 
@@ -344,7 +344,8 @@ static void test_first(void)
 
 	close(client_fd);
 	close(server_fd);
-	sched_cleanup();
+fail:
+	cleanup_netns(nstoken);
 	bpf_link__destroy(link);
 	mptcp_bpf_first__destroy(first_skel);
 }
Signature · 1 line
2.35.3
#3 lore raw

PATCH v4 2/6 selftests/bpf: add two mptcp netns helpers

In reply to Geliang Tang

Add two netns helpers for mptcp tests: create_netns() and cleanup_netns(). Use them in test_base().

---
 .../testing/selftests/bpf/prog_tests/mptcp.c  | 34 +++++++++++++------
 1 file changed, 23 insertions(+), 11 deletions(-)
tools/testing/selftests/bpf/prog_tests/mptcp.c +23 -11
index 8040997e4aef..ce9dc3ef3d40 100644
@@ -142,6 +142,26 @@ static int run_test(int cgroup_fd, int server_fd, bool is_mptcp)
 	return err;
 }
 
+static struct nstoken *create_netns(void)
+{
+	srand(time(NULL));
+	snprintf(NS_TEST, sizeof(NS_TEST), "mptcp_ns_%d", rand());
+	SYS(fail, "ip netns add %s", NS_TEST);
+	SYS(fail, "ip -net %s link set dev lo up", NS_TEST);
+
+	return open_netns(NS_TEST);
+fail:
+	return NULL;
+}
+
+static void cleanup_netns(struct nstoken *nstoken)
+{
+	if (nstoken)
+		close_netns(nstoken);
+
+	SYS_NOFAIL("ip netns del %s &> /dev/null", NS_TEST);
+}
+
 static void test_base(void)
 {
 	struct nstoken *nstoken = NULL;
@@ -151,13 +171,8 @@ static void test_base(void)
 	if (!ASSERT_GE(cgroup_fd, 0, "test__join_cgroup"))
 		return;
 
-	srand(time(NULL));
-	snprintf(NS_TEST, sizeof(NS_TEST), "mptcp_ns_%d", rand());
-	SYS(fail, "ip netns add %s", NS_TEST);
-	SYS(fail, "ip -net %s link set dev lo up", NS_TEST);
-
-	nstoken = open_netns(NS_TEST);
-	if (!ASSERT_OK_PTR(nstoken, "open_netns"))
+	nstoken = create_netns();
+	if (!ASSERT_OK_PTR(nstoken, "create_netns"))
 		goto fail;
 
 	/* without MPTCP */
@@ -180,10 +195,7 @@ static void test_base(void)
 	close(server_fd);
 
 fail:
-	if (nstoken)
-		close_netns(nstoken);
-
-	SYS_NOFAIL("ip netns del " NS_TEST " &> /dev/null");
+	cleanup_netns(nstoken);
 
 	close(cgroup_fd);
 }
Signature · 1 line
2.35.3
#6 lore raw

PATCH v4 4/6 Squash to "selftests/bpf: Add bpf_bkup test"

In reply to Geliang Tang

Run mptcp sched test in a dedicated netns.

---
 tools/testing/selftests/bpf/prog_tests/mptcp.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/prog_tests/mptcp.c +6 -2
index 85e37e0f64a3..3d99b6a1aebf 100644
@@ -354,6 +354,7 @@ 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();
@@ -366,7 +367,9 @@ static void test_bkup(void)
 		return;
 	}
 
-	sched_init("subflow backup", "bpf_bkup");
+	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, 0, 0);
 	client_fd = connect_to_fd(server_fd, 0);
 
@@ -376,7 +379,8 @@ static void test_bkup(void)
 
 	close(client_fd);
 	close(server_fd);
-	sched_cleanup();
+fail:
+	cleanup_netns(nstoken);
 	bpf_link__destroy(link);
 	mptcp_bpf_bkup__destroy(bkup_skel);
 }
Signature · 1 line
2.35.3
#7 lore raw

PATCH v4 5/6 Squash to "selftests/bpf: Add bpf_rr test"

In reply to Geliang Tang

Run mptcp sched test in a dedicated netns.

---
 tools/testing/selftests/bpf/prog_tests/mptcp.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/prog_tests/mptcp.c +6 -2
index 3d99b6a1aebf..13594084d095 100644
@@ -389,6 +389,7 @@ 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();
@@ -401,7 +402,9 @@ static void test_rr(void)
 		return;
 	}
 
-	sched_init("subflow", "bpf_rr");
+	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, 0, 0);
 	client_fd = connect_to_fd(server_fd, 0);
 
@@ -411,7 +414,8 @@ static void test_rr(void)
 
 	close(client_fd);
 	close(server_fd);
-	sched_cleanup();
+fail:
+	cleanup_netns(nstoken);
 	bpf_link__destroy(link);
 	mptcp_bpf_rr__destroy(rr_skel);
 }
Signature · 1 line
2.35.3
#8 lore raw

PATCH v4 6/6 Squash to "selftests/bpf: Add bpf_red test"

In reply to Geliang Tang

Run mptcp sched test in a dedicated netns.

---
 tools/testing/selftests/bpf/prog_tests/mptcp.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/prog_tests/mptcp.c +6 -2
index 13594084d095..a968641cc94a 100644
@@ -424,6 +424,7 @@ 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();
@@ -436,7 +437,9 @@ static void test_red(void)
 		return;
 	}
 
-	sched_init("subflow", "bpf_red");
+	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, 0, 0);
 	client_fd = connect_to_fd(server_fd, 0);
 
@@ -446,7 +449,8 @@ static void test_red(void)
 
 	close(client_fd);
 	close(server_fd);
-	sched_cleanup();
+fail:
+	cleanup_netns(nstoken);
 	bpf_link__destroy(link);
 	mptcp_bpf_red__destroy(red_skel);
 }
Signature · 1 line
2.35.3
#9 lore raw

Re: Squash to "selftests/bpf: Add bpf_red test": Tests Results

Hi Geliang,

Thank you for your modifications, that's great!

Our CI did some validations and here is its report:

- KVM Validation: normal (except selftest_mptcp_join):
- Success! ✅:
- Task: https://cirrus-ci.com/task/5629867937497088
- Summary: https://api.cirrus-ci.com/v1/artifact/task/5629867937497088/summary/summary.txt

- KVM Validation: normal (only selftest_mptcp_join):
- Success! ✅:
- Task: https://cirrus-ci.com/task/5066917984075776
- Summary: https://api.cirrus-ci.com/v1/artifact/task/5066917984075776/summary/summary.txt

- KVM Validation: debug (except selftest_mptcp_join):
- Unstable: 4 failed test(s): packetdrill_fastopen packetdrill_mp_capable packetdrill_sockopts selftest_diag 🔴:
- Task: https://cirrus-ci.com/task/6192817890918400
- Summary: https://api.cirrus-ci.com/v1/artifact/task/6192817890918400/summary/summary.txt

- KVM Validation: debug (only selftest_mptcp_join):
- Success! ✅:
- Task: https://cirrus-ci.com/task/4785443007365120
- Summary: https://api.cirrus-ci.com/v1/artifact/task/4785443007365120/summary/summary.txt

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/12e66cbae9ae

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-debug

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 (Tessares)

Reviewed-by on the v4 series
#11 lore raw
In reply to Geliang Tang

Hi Geliang,

Quoted 5 lines · Geliang Tang

v4:
- patch #1 could be merged before "mptcp: refactor push_pending logic" as a single fix.
- patch #2 should be merged between "selftests/bpf: Add mptcp sched structs" and "selftests/bpf: Add bpf_first scheduler".

Thank you for the new version and for the explanations!

I suggest to apply the first patch also between "selftests/bpf: Add mptcp sched structs" and "selftests/bpf: Add bpf_first scheduler" as it seems not needed before (see my comment on this patch).

Cheers,
Matt

Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net
#2 lore raw

Re: [PATCH mptcp-next v4 1/6] selftests/bpf: use random netns name for mptcp

In reply to Geliang Tang

Hi Geliang,

Quoted 4 lines · Geliang Tang

Use rand() to generate a random netns name instead of using the fixed name "mptcp_ns" for every test.

Fixes 02d6a057c7be ("selftests/bpf: run mptcp in a dedicated netns")

If we add the "Fixes" tag, it somehow means the previous behaviour was buggy. I agree that it is better to do what you did here just in case the previous netns has not been removed when re-launching the same test multiple time (what a CI would not do I guess) but I also see that most (all?) other BPF tests creating netns' use a fixed name.

I hope you don't mind if I then remove this Fixes tag when applying the patch.

While at it, I will also explain the reason why this patch is needed, something like:

By doing that, we can re-launch the test even if there was an issue removing the previous netns or if by accident, a netns with this generic name already existed on the system. Note that using a different name each will also help adding more subtests in future commits.

Cheers,
Matt

Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net
#4 lore raw

Re: [PATCH mptcp-next v4 2/6] selftests/bpf: add two mptcp netns helpers

In reply to Geliang Tang
Quoted 2 lines · Geliang Tang

Add two netns helpers for mptcp tests: create_netns() and cleanup_netns(). Use them in test_base().

I suggest to add the reason behind this patch:

These new helpers will be re-used in future other subtests.

Cheers,
Matt

Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net
#12 lore raw
In reply to Matthieu Baerts
Quoted 10 lines · Matthieu Baerts <[email protected]> 于2023年5月19日周五 17:36写道:

Hi Geliang,

Quoted 5 lines · Geliang Tang

v4:
- patch #1 could be merged before "mptcp: refactor push_pending logic" as a single fix.
- patch #2 should be merged between "selftests/bpf: Add mptcp sched structs" and "selftests/bpf: Add bpf_first scheduler".

Quoted 5 lines

Thank you for the new version and for the explanations!

I suggest to apply the first patch also between "selftests/bpf: Add mptcp sched structs" and "selftests/bpf: Add bpf_first scheduler" as it seems not needed before (see my comment on this patch).

I agree. Please update the commit logs for me when merging them.

Thanks,
-Geliang

Quoted 9 lines

Cheers,
Matt
--
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net

#13 lore raw

Hi Geliang,

Quoted 11 lines · Geliang Tang
Quoted 10 lines · Matthieu Baerts <[email protected]> 于2023年5月19日周五 17:36写道:

Hi Geliang,

Quoted 5 lines · Geliang Tang

v4:
- patch #1 could be merged before "mptcp: refactor push_pending logic" as a single fix.
- patch #2 should be merged between "selftests/bpf: Add mptcp sched structs" and "selftests/bpf: Add bpf_first scheduler".

Quoted 7 lines
Quoted 5 lines

Thank you for the new version and for the explanations!

I suggest to apply the first patch also between "selftests/bpf: Add mptcp sched structs" and "selftests/bpf: Add bpf_first scheduler" as it seems not needed before (see my comment on this patch).

I agree. Please update the commit logs for me when merging them.

Great, just did, hopefully as expected.

New patches for t/upstream:
- 022ddca0dd31: selftests/bpf: use random netns name for mptcp
- fa066ce14aa8: selftests/bpf: add two mptcp netns helpers
- 90d56a205185: "squashed" patch 3/6 in "selftests/bpf: Add bpf_first test"
- e17099987f21: "squashed" patch 4/6 in "selftests/bpf: Add bpf_bkup test"
- 8c10fe1b6365: "squashed" patch 5/6 in "selftests/bpf: Add bpf_rr test"
- 4101020d41c3: "squashed" patch 6/6 in "selftests/bpf: Add bpf_red test"
- Results: c20d0380b999..577d6a7db2fb (export)

Tests are now in progress:

https://cirrus-ci.com/github/multipath-tcp/mptcp_net-next/export/20230519T120144

Cheers,
Matt

Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net
#10 lore raw

Re: Squash to "selftests/bpf: Add bpf_red test": Tests Results

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 (except selftest_mptcp_join):
- Unstable: 1 failed test(s): packetdrill_fastopen 🔴:
- Task: https://cirrus-ci.com/task/6168255878922240
- Summary: https://api.cirrus-ci.com/v1/artifact/task/6168255878922240/summary/summary.txt

- {"code":404,"message":
- "Can't find artifacts containing file conclusion.txt"}:
- Task: https://cirrus-ci.com/task/6731205832343552
- Summary: https://api.cirrus-ci.com/v1/artifact/task/6731205832343552/summary/summary.txt

- KVM Validation: normal (only selftest_mptcp_join):
- Unstable: 1 failed test(s): selftest_mptcp_join 🔴:
- Task: https://cirrus-ci.com/task/5605305925500928
- Summary: https://api.cirrus-ci.com/v1/artifact/task/5605305925500928/summary/summary.txt

- KVM Validation: debug (only selftest_mptcp_join):
- Success! ✅:
- Task: https://cirrus-ci.com/task/4532182576791552
- Summary: https://api.cirrus-ci.com/v1/artifact/task/4532182576791552/summary/summary.txt

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/abe0cca432fc

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-debug

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 (Tessares)