refactor mptcp bpf tests
Subsystems (4)
Geliang Tang
reviewerv6 cover refactor mptcp bpf tests
From: Geliang Tang <[email protected]>
v6:
- drop patch 1 in v5 and rebased.
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 (9):
selftests/bpf: Add RUN_MPTCP_TEST macro
Squash to "selftests/bpf: Add bpf scheduler test" 1 verify Squash to "selftests/bpf: Add bpf scheduler test" 2 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 | 265 +++++------------- .../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, 77 insertions(+), 193 deletions(-)
Signature · 1 line
2.40.1
Geliang Tang
reviewerPATCH v6 1/9 selftests/bpf: Add RUN_MPTCP_TEST macro
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
@@ -653,12 +653,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
Geliang Tang
reviewerPATCH v6 2/9 Squash to "selftests/bpf: Add bpf scheduler test" 1 verify
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
Add send_data_and_verify helper.
--- .../testing/selftests/bpf/prog_tests/mptcp.c | 40 ++++++++++++++----- 1 file changed, 30 insertions(+), 10 deletions(-)
tools/testing/selftests/bpf/prog_tests/mptcp.c +30 -10
@@ -457,23 +457,44 @@ 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; -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" ); +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); }
@@ -663,8 +684,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
Matthieu Baerts
maintainerRe: [PATCH mptcp-next v6 2/9] Squash to "selftests/bpf: Add bpf scheduler test" 1 verify
Hi Geliang,
Quoted 3 lines · Geliang Tang
From: Geliang Tang <[email protected]>
Add
send_data_and_verifyhelper.
Please always add the reason, even if it is just a "to avoid duplicated code".
Quoted 27 lines
Signed-off-by Geliang Tang <[email protected]>--- .../testing/selftests/bpf/prog_tests/mptcp.c | 40 ++++++++++++++----- 1 file changed, 30 insertions(+), 10 deletions(-)tools/testing/selftests/bpf/prog_tests/mptcp.c +4
-5@@ -457,23 +457,44 @@ 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 ; +
tools/testing/selftests/bpf/prog_tests/mptcp.c static int has_bytes_sent(char *addr) · line 474
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/mptcp.c +5
-3client_fd =connect_to_fd (server_fd,0 ); +if (!ASSERT_NEQ (client_fd,-1 ,"connect_to_fd" )) + goto close_server; -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" ); +send_data (server_fd, client_fd, msg); + +if (addr1)
Maybe clearer to use booleans if you use addr1 and addr2 as such, no?
tools/testing/selftests/bpf/prog_tests/mptcp.c static int has_bytes_sent(char *addr) · line 481
Quoted 7 lines
tools/testing/selftests/bpf/prog_tests/mptcp.c +7
-0+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" );
In case of error, will we directly understand from which scheduler the error is linked to? I understood that some BPF tests can be run in parallel, maybe we need a prefix to know which tests had an issue? Or maybe the prefix is not needed because these schedulers tests are executed in sequence and we print which one is being executed?
In other words, what do you see if on purpose you create an error by inverting 'addr2' value for example in only one sched test, and you launch the tests with 'test_progs -j'?
Quoted 5 lines
tools/testing/selftests/bpf/prog_tests/mptcp.c +2
-0close (client_fd); +close_server:close (server_fd); +}
tools/testing/selftests/bpf/prog_tests/mptcp.c static int has_bytes_sent(char *addr) · line 496
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/mptcp.c +10
-0+ +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 );
It is good to have such helper to reduce duplicated code, but having:
1, 1
is really not clear, no?
Maybe clearer (especially later if you use this a lot), to use macros? e.g. to have:
send_data_and_verify("default", USE_ADDR1, NO_ADDR2);or
send_data_and_verify("default", WITH_DATA, WITHOUT_DATA);(we might understand one is for addr1 and the other for addr2)
WDYT? I don't know if it is clearer.
Quoted 5 lines
tools/testing/selftests/bpf/prog_tests/mptcp.c +1
-0+ fail:cleanup_netns (nstoken); }
tools/testing/selftests/bpf/prog_tests/mptcp.c void test_mptcp(void) · line 690
Quoted 9 lines
tools/testing/selftests/bpf/prog_tests/mptcp.c +1
-2@@ -663,8 +684,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" ))
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Geliang Tang
reviewerPATCH v6 3/9 Squash to "selftests/bpf: Add bpf scheduler test" 2 time
In reply to Geliang TangFrom: 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
@@ -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"
@@ -380,16 +379,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))
@@ -406,16 +401,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);
@@ -459,7 +447,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" ))
@@ -469,8 +459,17 @@ static void send_data_and_verify(char *msg, int addr1, int addr2)if (!ASSERT_NEQ (client_fd,-1 ,"connect_to_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
Matthieu Baerts
maintainerRe: [PATCH mptcp-next v6 3/9] Squash to "selftests/bpf: Add bpf scheduler test" 2 time
Hi Geliang,
Quoted 3 lines · Geliang Tang
From: Geliang Tang <[email protected]>
Move time related code into
send_data_and_verify.
Please explain the reason. Now the time will be taken after having waited for the server to stop, the info is then different. It might be OK to do that, but then please explain.
(always add the reason why we need a patch, not just what you did)
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Geliang Tang
reviewerPATCH v6 4/9 selftests/bpf: Add MPTCP_SCHED_TEST macro
In reply to Geliang TangFrom: 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
@@ -498,6 +498,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
Matthieu Baerts
maintainerRe: [PATCH mptcp-next v6 4/9] selftests/bpf: Add MPTCP_SCHED_TEST macro
Hi Geliang,
Quoted 10 lines · Geliang Tang
From: Geliang Tang <[email protected]>
This patch defines
MPTCP_SCHED_TESTmacro, 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 checkbytes_sentof 'ss' output after it usingsend_data_and_verify().
Should we not squash this in "selftests/bpf: Add bpf scheduler test" as well? We already have a lot of different commits.
Quoted 26 lines
Signed-off-by Geliang Tang <[email protected]>--- .../testing/selftests/bpf/prog_tests/mptcp.c | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+)tools/testing/selftests/bpf/prog_tests/mptcp.c +12
-0@@ -498,6 +498,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; \ + \
tools/testing/selftests/bpf/prog_tests/mptcp.c static void test_default(void) · line 522
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/mptcp.c +10
-0+ 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));\
Can you not use the values of addr1 and addr2 directly as number instead of string + atoi()?
tools/testing/selftests/bpf/prog_tests/mptcp.c static void test_default(void) · line 529
Quoted 7 lines
tools/testing/selftests/bpf/prog_tests/mptcp.c +7
-0+ \ +cleanup_netns (nstoken); \ +link_destroy: \ +bpf_link__destroy (link); \ +skel_destroy: \ + mptcp_bpf_##name##__destroy(skel); \ +}
I don't mind having functions defined in macros, but I think we should try to reduce their size to the minimum (if possible) because they are hard to read and debug in case of error.
Here, do you think we could have a smaller macro passing the name as a string (for the error messages) and the different functions pointers you need to a new helper? (+ using generic skel structure?)
Maybe it will not work or will not be easier to read, but worth a try I think. If it is not possible, please explain why.
tools/testing/selftests/bpf/prog_tests/mptcp.c static void test_default(void) · line 533
Quoted 4 lines
tools/testing/selftests/bpf/prog_tests/mptcp.c +1
-0+static void test_first (void ) {struct mptcp_bpf_first *first_skel;
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Geliang Tang
reviewerRe: [PATCH mptcp-next v6 4/9] selftests/bpf: Add MPTCP_SCHED_TEST macro
Hi Matt,
Quoted 84 lines · Matthieu Baerts
Hi Geliang,
Quoted 16 lines · Geliang Tang
From: Geliang Tang <[email protected]>
This patch defines
MPTCP_SCHED_TESTmacro, 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 checkbytes_sentof 'ss' output after it usingsend_data_and_verify().Should we not squash this in "selftests/bpf: Add bpf scheduler test" as
well? We already have a lot of different commits.Quoted 32 lines
Signed-off-by Geliang Tang <[email protected]>---
.../testing/selftests/bpf/prog_tests/mptcp.c | 30
+++++++++++++++++++1 file changed, 30 insertions(+)tools/testing/selftests/bpf/prog_tests/mptcp.c +0
-0@@ -498,6 +498,36 @@ static void test_default(void) cleanup_netns(nstoken); }tools/testing/selftests/bpf/prog_tests/mptcp.c +11
-0+#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;\tools/testing/selftests/bpf/prog_tests/mptcp.c +3
-0+ \ + map = bpf_object__find_map_by_name(skel->obj, #name); \ + link =
bpf_map__attach_struct_ops(map); \tools/testing/selftests/bpf/prog_tests/mptcp.c static void test_default(void) · line 522
Quoted 8 lines
tools/testing/selftests/bpf/prog_tests/mptcp.c +8
-0+ 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));\Can you not use the values of addr1 and addr2 directly as number instead
of string +atoi()?tools/testing/selftests/bpf/prog_tests/mptcp.c static void test_default(void) · line 529
Quoted 8 lines
tools/testing/selftests/bpf/prog_tests/mptcp.c +2
-0+ \ +cleanup_netns (nstoken);\tools/testing/selftests/bpf/prog_tests/mptcp.c +5
-0+link_destroy: \ +bpf_link__destroy (link); \ +skel_destroy: \ + mptcp_bpf_##name##__destroy(skel); \ +}I don't mind having functions defined in macros, but I think we should
try to reduce their size to the minimum (if possible) because they are
hard to read and debug in case of error.
Quoted 5 lines
Here, do you think we could have a smaller macro passing the name as a
string (for the error messages) and the different functions pointers you
need to a new helper? (+ using generic skel structure?)
Thanks for your review, it's very useful. v7 is sent, address all your comments except this one. I didn't got it, please give me more details about this.
-Geliang
Quoted 13 lines
Maybe it will not work or will not be easier to read, but worth a try I
think. If it is not possible, please explain why.Quoted 4 lines
+
static voidtest_first(void)
{
structmptcp_bpf_first*first_skel;Cheers,
Matt
Matthieu Baerts
maintainerRe: [PATCH mptcp-next v6 4/9] selftests/bpf: Add MPTCP_SCHED_TEST macro
Hi Geliang, Mat,
Quoted 93 lines · Geliang Tang
Hi Matt,
Quoted 84 lines · Matthieu Baerts
Hi Geliang,
Quoted 16 lines · Geliang Tang
From: Geliang Tang <[email protected]>
This patch defines
MPTCP_SCHED_TESTmacro, 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 checkbytes_sentof 'ss' output after it usingsend_data_and_verify().Should we not squash this in "selftests/bpf: Add bpf scheduler test" as
well? We already have a lot of different commits.Quoted 32 lines
Signed-off-by Geliang Tang <[email protected]>---
.../testing/selftests/bpf/prog_tests/mptcp.c | 30
+++++++++++++++++++1 file changed, 30 insertions(+)tools/testing/selftests/bpf/prog_tests/mptcp.c +0
-0@@ -498,6 +498,36 @@ static void test_default(void) cleanup_netns(nstoken); }tools/testing/selftests/bpf/prog_tests/mptcp.c +11
-0+#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;\tools/testing/selftests/bpf/prog_tests/mptcp.c +3
-0+ \ + map = bpf_object__find_map_by_name(skel->obj, #name); \ + link =
bpf_map__attach_struct_ops(map); \tools/testing/selftests/bpf/prog_tests/mptcp.c static void test_default(void) · line 522
Quoted 8 lines
tools/testing/selftests/bpf/prog_tests/mptcp.c +8
-0+ 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));\Can you not use the values of addr1 and addr2 directly as number instead
of string +atoi()?tools/testing/selftests/bpf/prog_tests/mptcp.c static void test_default(void) · line 529
Quoted 8 lines
tools/testing/selftests/bpf/prog_tests/mptcp.c +2
-0+ \ +cleanup_netns (nstoken);\tools/testing/selftests/bpf/prog_tests/mptcp.c +5
-0+link_destroy: \ +bpf_link__destroy (link); \ +skel_destroy: \ + mptcp_bpf_##name##__destroy(skel); \ +}I don't mind having functions defined in macros, but I think we should
try to reduce their size to the minimum (if possible) because they are
hard to read and debug in case of error.Quoted 5 lines
Here, do you think we could have a smaller macro passing the name as a
string (for the error messages) and the different functions pointers you
need to a new helper? (+ using generic skel structure?)
Quoted 3 lines
Thanks for your review, it's very useful. v7 is sent, address all your comments except this one. I didn't got it, please give me more details about this.
My comment was similar to the one from Mat:
https://lore.kernel.org/mptcp/[email protected]/
In short: macros can be hard to debug.
I also see why you are using a macro here, all these functions are very similar. Here, there are more functions that can "reduced", so maybe that's OK?
@Mat: what do you think? Or maybe another idea?
(Or maybe it is possible to have a "small" macro, passing function pointers to a (proper) helper? But not sure if it is less complex. And maybe not worth it for the tests.)
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Geliang Tang
reviewerPATCH v6 5/9 Squash to "selftests/bpf: Add bpf_first scheduler & test"
In reply to Geliang TangFrom: 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
@@ -528,40 +528,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 ) {
@@ -714,8 +681,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
@@ -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
Geliang Tang
reviewerPATCH v6 6/9 Squash to "selftests/bpf: Add bpf_bkup scheduler & test"
In reply to Geliang TangFrom: 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
@@ -529,41 +529,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 ) {
@@ -682,8 +648,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
@@ -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
Geliang Tang
reviewerPATCH v6 7/9 Squash to "selftests/bpf: Add bpf_rr scheduler & test"
In reply to Geliang TangFrom: 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
@@ -530,41 +530,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 ) {
@@ -649,8 +615,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
@@ -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
Geliang Tang
reviewerPATCH v6 8/9 Squash to "selftests/bpf: Add bpf_red scheduler & test"
In reply to Geliang TangFrom: 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
@@ -531,41 +531,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 ) {
@@ -616,8 +582,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
@@ -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
Geliang Tang
reviewerPATCH v6 9/9 Squash to "selftests/bpf: Add bpf_burst scheduler & test"
In reply to Geliang TangFrom: 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 | 39 +------------------ .../selftests/bpf/progs/mptcp_bpf_burst.c | 1 + 2 files changed, 3 insertions(+), 37 deletions(-)
tools/testing/selftests/bpf/prog_tests/mptcp.c +2 -37
@@ -532,41 +532,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 ); - -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 { \
@@ -583,6 +549,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
@@ -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
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: Success! ✅
- KVM Validation: btf (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/8555399820
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/c7b5767b70ce
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=841431
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-normalFor 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)
Matthieu Baerts
maintainerHi Geliang,
Quoted 13 lines · Geliang Tang
From: Geliang Tang <[email protected]>
v6:
- drop patch 1 in v5 and rebased.v5:
- drop patch 5 in v4:
Squash to "selftests/bpf: Add bpf scheduler test" 4 cleanupv4:
- addset_nonblockto make BPF tests stable.
- split 'Squash to "selftests/bpf: Add bpf scheduler test"' into 4 patches.
Quoted 8 lines
v3:
- part 1, bpf schedulers.v2:
- add two more helpers,send_single_byteandsend_recv_data.Refactor mptcp bpf tests using newly added macros
MPTCP_BASE_TEST,RUN_MPTCP_TESTandMPTCP_SCHED_TESTmacro.
Thank you for the cleanup.
Please see my comments on the different patches.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.