selftests/bpf: parallel mode improvement
Subsystems (3)
PATCH 1/4 selfetests/bpf: Update vmtest.sh defaults
In reply to Yucong SunFrom: Yucong Sun <[email protected]>
Increase memory to 4G, 8 SMP core with host cpu passthrough. This make it run faster in parallel mode and more likely to succeed.
--- tools/testing/selftests/bpf/vmtest.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/testing/selftests/bpf/vmtest.sh +3 -3
@@ -224,10 +224,10 @@ EOF -nodefaults \ -display none \ -serial mon:stdio \ - -cpu kvm64 \ + -cpu host \ -enable-kvm \ - -smp 4 \ - -m 2G \ + -smp 8 \ + -m 4G \ -drive file="${rootfs_img}",format=raw,index=1,media=disk,if=virtio,cache=none \ -kernel "${kernel_bzimage}" \ -append "root=/dev/vda rw console=ttyS0,115200"
Signature · 1 line
2.30.2
PATCH 2/4 selftests/bpf: print subtest status line
In reply to Yucong SunFrom: Yucong Sun <[email protected]>
This patch restores behavior that prints one status line for each subtest executed. It works in both serial mode and parallel mode, and all verbosity settings.
The logic around IO hijacking could use some more simplification in the future.
--- tools/testing/selftests/bpf/test_progs.c | 56 +++++++++++++++++++----- tools/testing/selftests/bpf/test_progs.h | 4 ++ 2 files changed, 50 insertions(+), 10 deletions(-)
tools/testing/selftests/bpf/test_progs.c +46 -10
@@ -100,6 +100,18 @@ static bool should_run(struct test_selector *sel, int num, const char *name)return num < sel->num_set_len && sel->num_set[num]; } +static void dump_subtest_status (bool display) { +fflush (env.subtest_status_fd); +if (display) { +if (env.subtest_status_cnt) { + env.subtest_status_buf[env.subtest_status_cnt] ='\0' ; +fputs (env.subtest_status_buf, stdout); + } + } +rewind (env.subtest_status_fd); +fflush (env.subtest_status_fd); +} +static void dump_test_log (const struct prog_test_def *test,bool failed) {if (stdout == env.stdout)
@@ -112,12 +124,17 @@ static void dump_test_log(const struct prog_test_def *test, bool failed)fflush (stdout);/* exports env.log_buf & env.log_cnt */ if (env.verbosity >VERBOSE_NONE || test->force_log || failed) { -if (env.log_cnt) { - env.log_buf[env.log_cnt] ='\0' ; -fprintf (env.stdout,"%s" , env.log_buf); -if (env.log_buf[env.log_cnt -1 ] !='\n' ) -fprintf (env.stdout,"\n" ); - } +dump_subtest_status (false); + }else { +rewind (stdout); +dump_subtest_status (true); +fflush (stdout); + } +if (env.log_cnt) { + env.log_buf[env.log_cnt] ='\0' ; +fprintf (env.stdout,"%s" , env.log_buf); +if (env.log_buf[env.log_cnt -1 ] !='\n' ) +fprintf (env.stdout,"\n" ); } }
@@ -183,7 +200,12 @@ void test__end_subtest(void)dump_test_log (test, sub_error_cnt); +// Print two copies here, one as part of full logs, another one will +// only be used if there is no need to show full logs. fprintf (stdout,"#%d/%d %s/%s:%s\n" , + test->test_num, test->subtest_num, test->test_name, test->subtest_name, + sub_error_cnt ?"FAIL" : (test->skip_cnt ?"SKIP" :"OK" )); +fprintf (env.subtest_status_fd,"#%d/%d %s/%s:%s\n" , test->test_num, test->subtest_num, test->test_name, test->subtest_name, sub_error_cnt ?"FAIL" : (test->skip_cnt ?"SKIP" :"OK" ));
@@ -1250,6 +1272,15 @@ static int worker_main(int sock)run_one_test (test_to_run); +// discard logs if we don't need them +if (env.verbosity >VERBOSE_NONE || test->force_log || test->error_cnt) { +dump_subtest_status (false); + }else { +rewind (stdout); +dump_subtest_status (true); +fflush (stdout); + } +stdio_restore ();memset (&msg_done,0 ,sizeof (msg_done));
@@ -1260,10 +1291,9 @@ static int worker_main(int sock) msg_done.test_done.sub_succ_cnt = test->sub_succ_cnt; msg_done.test_done.have_log = false; -if (env.verbosity >VERBOSE_NONE || test->force_log || test->error_cnt) { -if (env.log_cnt) - msg_done.test_done.have_log = true; - } +if (env.log_cnt) + msg_done.test_done.have_log = true; +if (send_message (sock, &msg_done) <0 ) {perror ("Fail to send message done" ); goto out;
@@ -1357,6 +1387,12 @@ int main(int argc, char **argv) env.stdout = stdout; env.stderr = stderr; + env.subtest_status_fd =open_memstream ( + &env.subtest_status_buf, &env.subtest_status_cnt); +if (!env.subtest_status_fd) { +perror ("Failed to setup env.subtest_status_fd" ); +exit (EXIT_ERR_SETUP_INFRA ); + } env.has_testmod = true;if (!env.list_test_names &&load_bpf_testmod ()) {
tools/testing/selftests/bpf/test_progs.h +4 -0
@@ -89,6 +89,10 @@ struct test_env {pid_t *worker_pids;/* array of worker pids */ int *worker_socks;/* array of worker socks */ int *worker_current_test;/* array of current running test for each worker */ + +FILE * subtest_status_fd;/* fd for printing status line for subtests */ +char *subtest_status_buf;/* buffer for subtests status */ +size_t subtest_status_cnt; };#define MAX_LOG_TRUNK_SIZE 8192
Signature · 1 line
2.30.2
cover selftests/bpf: parallel mode improvement
Several patches to improve parallel execution mode, including printing subtest status line, updating vmtest.sh and fixed two previously dropped patch according to feedback.
Yucong Sun (4):
selfetests/bpf: Update vmtest.sh defaults selftests/bpf: print subtest status line selftests/bpf: fix attach_probe in parallel mode selftests/bpf: adding a namespace reset for tc_redirect
.../selftests/bpf/prog_tests/attach_probe.c | 9 ++- .../selftests/bpf/prog_tests/tc_redirect.c | 14 +++++ tools/testing/selftests/bpf/test_progs.c | 56 +++++++++++++++---- tools/testing/selftests/bpf/test_progs.h | 4 ++ tools/testing/selftests/bpf/vmtest.sh | 6 +- 5 files changed, 74 insertions(+), 15 deletions(-)
Signature · 1 line
2.30.2
PATCH 3/4 selftests/bpf: fix attach_probe in parallel mode
From: Yucong Sun <[email protected]>
This patch makes attach_probe uses its own method as attach point, avoiding conflict with other tests like bpf_cookie.
--- tools/testing/selftests/bpf/prog_tests/attach_probe.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/prog_tests/attach_probe.c +7 -2
@@ -5,6 +5,11 @@/* this is how USDT semaphore is actually defined, except volatile modifier */ volatile unsigned short uprobe_ref_ctr __attribute__((unused)) __attribute((section(".probes"))); +/* attach point */ +static void method (void ) { +return ; +} +void test_attach_probe (void ) {DECLARE_LIBBPF_OPTS (bpf_uprobe_opts, uprobe_opts);
@@ -33,7 +38,7 @@ void test_attach_probe(void)if (CHECK (base_addr <0 ,"get_base_addr" ,"failed to find base addr: %zd" , base_addr))return ; - uprobe_offset =get_uprobe_offset (&get_base_addr, base_addr); + uprobe_offset =get_uprobe_offset (&method, base_addr); ref_ctr_offset =get_rel_offset ((uintptr_t )&uprobe_ref_ctr);if (!ASSERT_GE (ref_ctr_offset,0 ,"ref_ctr_offset" ))
@@ -98,7 +103,7 @@ void test_attach_probe(void) goto cleanup;/* trigger & validate uprobe & uretprobe */ -get_base_addr (); +method ();if (CHECK (skel->bss->uprobe_res !=3 ,"check_uprobe_res" ,"wrong uprobe res: %d\n" , skel->bss->uprobe_res))
Signature · 1 line
2.30.2
PATCH 4/4 selftests/bpf: adding a namespace reset for tc_redirect
In reply to Yucong SunFrom: Yucong Sun <[email protected]>
This patch delete ns_src/ns_dst/ns_redir namespaces before recreating them, making the test more robust.
--- .../testing/selftests/bpf/prog_tests/tc_redirect.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
tools/testing/selftests/bpf/prog_tests/tc_redirect.c +14 -0
@@ -176,6 +176,18 @@ static int netns_setup_namespaces(const char *verb)return 0 ; } +static void netns_setup_namespaces_nofail (const char *verb) +{ +const char *const *ns = namespaces; +char cmd[128 ]; + +while (*ns) { +snprintf (cmd,sizeof (cmd),"ip netns %s %s > /dev/null 2>&1" , verb, *ns); +system (cmd); + ns++; + } +} +struct netns_setup_result {int ifindex_veth_src_fwd;int ifindex_veth_dst_fwd;
@@ -762,6 +774,8 @@ static void test_tc_redirect_peer_l3(struct netns_setup_result *setup_result)static void *test_tc_redirect_run_tests (void *arg) { +netns_setup_namespaces_nofail ("delete" ); +RUN_TEST (tc_redirect_peer);RUN_TEST (tc_redirect_peer_l3);RUN_TEST (tc_redirect_neigh);
Signature · 1 line
2.30.2
Re: [PATCH bpf-next 2/4] selftests/bpf: print subtest status line
In reply to Yucong SunQuoted 10 lines · Yucong Sun
From: Yucong Sun <[email protected]>
This patch restores behavior that prints one status line for each subtest executed. It works in both serial mode and parallel mode, and all verbosity settings.
The logic around IO hijacking could use some more simplification in the future.
This feels like a big hack, not a proper solution. What if we extend MSG_TEST_DONE to signal also sub-test completion (along with subtest logs)? Would that work better and result in cleaner logic?
Quoted 11 lines
Signed-off-by Yucong Sun <[email protected]>--- tools/testing/selftests/bpf/test_progs.c | 56 +++++++++++++++++++----- tools/testing/selftests/bpf/test_progs.h | 4 ++ 2 files changed, 50 insertions(+), 10 deletions(-)tools/testing/selftests/bpf/test_progs.c +0
-0
tools/testing/selftests/bpf/test_progs.c static bool should_run(struct test_selector *sel, int num, const char *name) · line 103
Quoted 4 lines
tools/testing/selftests/bpf/test_progs.c +1
-0@@ -100,6 +100,18 @@ static bool should_run(struct test_selector *sel, int num, const char *name)return num < sel->num_set_len && sel->num_set[num]; } +static void dump_subtest_status (bool display) {
please run checkpatch.pl
Quoted 39 lines
tools/testing/selftests/bpf/test_progs.c +22
-6+fflush (env.subtest_status_fd); +if (display) { +if (env.subtest_status_cnt) { + env.subtest_status_buf[env.subtest_status_cnt] ='\0' ; +fputs (env.subtest_status_buf, stdout); + } + } +rewind (env.subtest_status_fd); +fflush (env.subtest_status_fd); +} +static void dump_test_log (const struct prog_test_def *test,bool failed) {if (stdout == env.stdout)@@ -112,12 +124,17 @@ static void dump_test_log(const struct prog_test_def *test, bool failed)fflush (stdout);/* exports env.log_buf & env.log_cnt */ if (env.verbosity >VERBOSE_NONE || test->force_log || failed) { -if (env.log_cnt) { - env.log_buf[env.log_cnt] ='\0' ; -fprintf (env.stdout,"%s" , env.log_buf); -if (env.log_buf[env.log_cnt -1 ] !='\n' ) -fprintf (env.stdout,"\n" ); - } +dump_subtest_status (false); + }else { +rewind (stdout); +dump_subtest_status (true); +fflush (stdout); + } +if (env.log_cnt) { + env.log_buf[env.log_cnt] ='\0' ; +fprintf (env.stdout,"%s" , env.log_buf); +if (env.log_buf[env.log_cnt -1 ] !='\n' ) +fprintf (env.stdout,"\n" ); } }
tools/testing/selftests/bpf/test_progs.c void test__end_subtest(void) · line 204
Quoted 5 lines
tools/testing/selftests/bpf/test_progs.c +2
-0@@ -183,7 +200,12 @@ void test__end_subtest(void)dump_test_log (test, sub_error_cnt); +// Print two copies here, one as part of full logs, another one will +// only be used if there is no need to show full logs.
C++ style comments
tools/testing/selftests/bpf/test_progs.c static int worker_main(int sock) · line 1275
Quoted 12 lines
tools/testing/selftests/bpf/test_progs.c +4
-0fprintf (stdout,"#%d/%d %s/%s:%s\n" , + test->test_num, test->subtest_num, test->test_name, test->subtest_name, + sub_error_cnt ?"FAIL" : (test->skip_cnt ?"SKIP" :"OK" )); +fprintf (env.subtest_status_fd,"#%d/%d %s/%s:%s\n" , test->test_num, test->subtest_num, test->test_name, test->subtest_name, sub_error_cnt ?"FAIL" : (test->skip_cnt ?"SKIP" :"OK" ));@@ -1250,6 +1272,15 @@ static int worker_main(int sock)run_one_test (test_to_run); +// discard logs if we don't need them
C++ style comment
Quoted 26 lines
tools/testing/selftests/bpf/test_progs.c +11
-4+if (env.verbosity >VERBOSE_NONE || test->force_log || test->error_cnt) { +dump_subtest_status (false); + }else { +rewind (stdout); +dump_subtest_status (true); +fflush (stdout); + } +stdio_restore ();memset (&msg_done,0 ,sizeof (msg_done));@@ -1260,10 +1291,9 @@ static int worker_main(int sock) msg_done.test_done.sub_succ_cnt = test->sub_succ_cnt; msg_done.test_done.have_log = false; -if (env.verbosity >VERBOSE_NONE || test->force_log || test->error_cnt) { -if (env.log_cnt) - msg_done.test_done.have_log = true; - } +if (env.log_cnt) + msg_done.test_done.have_log = true; +if (send_message (sock, &msg_done) <0 ) {perror ("Fail to send message done" ); goto out;
tools/testing/selftests/bpf/test_progs.c int main(int argc, char **argv) · line 1390
Quoted 4 lines
tools/testing/selftests/bpf/test_progs.c +1
-0@@ -1357,6 +1387,12 @@ int main(int argc, char **argv) env.stdout = stdout; env.stderr = stderr; + env.subtest_status_fd = open_memstream(
extremely misleading name, it's not an FD at all
Quoted 26 lines
tools/testing/selftests/bpf/test_progs.c +5
-0+ &env.subtest_status_buf, &env.subtest_status_cnt); +if (!env.subtest_status_fd) { +perror ("Failed to setup env.subtest_status_fd" ); +exit (EXIT_ERR_SETUP_INFRA ); + } env.has_testmod = true;if (!env.list_test_names &&load_bpf_testmod ()) {tools/testing/selftests/bpf/test_progs.h +4
-1@@ -89,6 +89,10 @@ struct test_env {pid_t *worker_pids;/* array of worker pids */ int *worker_socks;/* array of worker socks */ int *worker_current_test;/* array of current running test for each worker */ + +FILE * subtest_status_fd;/* fd for printing status line for subtests */ +char *subtest_status_buf;/* buffer for subtests status */ +size_t subtest_status_cnt; };#define MAX_LOG_TRUNK_SIZE 8192 --2.30.2
Re: [PATCH bpf-next 3/4] selftests/bpf: fix attach_probe in parallel mode
In reply to Yucong SunQuoted 16 lines · Yucong Sun
From: Yucong Sun <[email protected]>
This patch makes
attach_probeuses its own method as attach point, avoiding conflict with other tests likebpf_cookie.Signed-off-by Yucong Sun <[email protected]>--- tools/testing/selftests/bpf/prog_tests/attach_probe.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)tools/testing/selftests/bpf/prog_tests/attach_probe.c +0
-0
tools/testing/selftests/bpf/prog_tests/attach_probe.c line 9
Quoted 5 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c +2
-0@@ -5,6 +5,11 @@/* this is how USDT semaphore is actually defined, except volatile modifier */ volatile unsigned short uprobe_ref_ctr __attribute__((unused)) __attribute((section(".probes"))); +/* attach point */ +static void method (void ) {
{ on separate line
let's also mark it as noinline just in case
tools/testing/selftests/bpf/prog_tests/attach_probe.c line 10
Quoted 1 line
tools/testing/selftests/bpf/prog_tests/attach_probe.c +1
-0+return ;
unnecessary return (also extra space before semicolon)
Quoted 26 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c +4
-3+} +void test_attach_probe (void ) {DECLARE_LIBBPF_OPTS (bpf_uprobe_opts, uprobe_opts);@@ -33,7 +38,7 @@ void test_attach_probe(void)if (CHECK (base_addr <0 ,"get_base_addr" ,"failed to find base addr: %zd" , base_addr))return ; - uprobe_offset =get_uprobe_offset (&get_base_addr, base_addr); + uprobe_offset =get_uprobe_offset (&method, base_addr); ref_ctr_offset =get_rel_offset ((uintptr_t )&uprobe_ref_ctr);if (!ASSERT_GE (ref_ctr_offset,0 ,"ref_ctr_offset" ))@@ -98,7 +103,7 @@ void test_attach_probe(void) goto cleanup;/* trigger & validate uprobe & uretprobe */ -get_base_addr (); +method ();if (CHECK (skel->bss->uprobe_res !=3 ,"check_uprobe_res" ,"wrong uprobe res: %d\n" , skel->bss->uprobe_res)) --2.30.2
Re: [PATCH bpf-next 2/4] selftests/bpf: print subtest status line
In reply to Andrii NakryikoQuoted 9 lines · Andrii Nakryiko
Quoted 7 lines · Yucong Sun
From: Yucong Sun <[email protected]>
This patch restores behavior that prints one status line for each subtest executed. It works in both serial mode and parallel mode, and all verbosity settings.
Quoted 7 lines
Quoted 3 lines
The logic around IO hijacking could use some more simplification in the future.
This feels like a big hack, not a proper solution. What if we extend
MSG_TEST_DONEto signal also sub-test completion (along with subtest logs)? Would that work better and result in cleaner logic?
I think the current solution is actually cleaner. Yes we could add fields in task struct to record each subtest's name and status and generate the status line separately, but it will only work in situations where all tests pass.
When there is an error, we do want to mix the status line with the actual stdout logs, which we won't be able to do afterwards.
Besides, we will still need to implement separate logic in 3 places (serial mode, parallel mode in worker process, and serial part of parallel mode execution). Having two copies of stdout logs is actually not that bad.
Quoted 108 lines
Quoted 12 lines
Signed-off-by Yucong Sun <[email protected]>--- tools/testing/selftests/bpf/test_progs.c | 56 +++++++++++++++++++----- tools/testing/selftests/bpf/test_progs.h | 4 ++ 2 files changed, 50 insertions(+), 10 deletions(-)tools/testing/selftests/bpf/test_progs.c +0
-0tools/testing/selftests/bpf/test_progs.c static bool should_run(struct test_selector *sel, int num, const char *name) · line 103
Quoted 4 lines
tools/testing/selftests/bpf/test_progs.c +1
-0@@ -100,6 +100,18 @@ static bool should_run(struct test_selector *sel, int num, const char *name)return num < sel->num_set_len && sel->num_set[num]; } +static void dump_subtest_status (bool display) {please run checkpatch.pl
Quoted 39 lines
tools/testing/selftests/bpf/test_progs.c +22
-6+fflush (env.subtest_status_fd); +if (display) { +if (env.subtest_status_cnt) { + env.subtest_status_buf[env.subtest_status_cnt] ='\0' ; +fputs (env.subtest_status_buf, stdout); + } + } +rewind (env.subtest_status_fd); +fflush (env.subtest_status_fd); +} +static void dump_test_log (const struct prog_test_def *test,bool failed) {if (stdout == env.stdout)@@ -112,12 +124,17 @@ static void dump_test_log(const struct prog_test_def *test, bool failed)fflush (stdout);/* exports env.log_buf & env.log_cnt */ if (env.verbosity >VERBOSE_NONE || test->force_log || failed) { -if (env.log_cnt) { - env.log_buf[env.log_cnt] ='\0' ; -fprintf (env.stdout,"%s" , env.log_buf); -if (env.log_buf[env.log_cnt -1 ] !='\n' ) -fprintf (env.stdout,"\n" ); - } +dump_subtest_status (false); + }else { +rewind (stdout); +dump_subtest_status (true); +fflush (stdout); + } +if (env.log_cnt) { + env.log_buf[env.log_cnt] ='\0' ; +fprintf (env.stdout,"%s" , env.log_buf); +if (env.log_buf[env.log_cnt -1 ] !='\n' ) +fprintf (env.stdout,"\n" ); } }tools/testing/selftests/bpf/test_progs.c void test__end_subtest(void) · line 204
Quoted 5 lines
tools/testing/selftests/bpf/test_progs.c +2
-0@@ -183,7 +200,12 @@ void test__end_subtest(void)dump_test_log (test, sub_error_cnt); +// Print two copies here, one as part of full logs, another one will +// only be used if there is no need to show full logs. C++ style comments
tools/testing/selftests/bpf/test_progs.c static int worker_main(int sock) · line 1275
Quoted 12 lines
tools/testing/selftests/bpf/test_progs.c +4
-0fprintf (stdout,"#%d/%d %s/%s:%s\n" , + test->test_num, test->subtest_num, test->test_name, test->subtest_name, + sub_error_cnt ?"FAIL" : (test->skip_cnt ?"SKIP" :"OK" )); +fprintf (env.subtest_status_fd,"#%d/%d %s/%s:%s\n" , test->test_num, test->subtest_num, test->test_name, test->subtest_name, sub_error_cnt ?"FAIL" : (test->skip_cnt ?"SKIP" :"OK" ));@@ -1250,6 +1272,15 @@ static int worker_main(int sock)run_one_test (test_to_run); +// discard logs if we don't need them C++ style comment
Quoted 27 lines
tools/testing/selftests/bpf/test_progs.c +11
-4+if (env.verbosity >VERBOSE_NONE || test->force_log || test->error_cnt) { +dump_subtest_status (false); + }else { +rewind (stdout); +dump_subtest_status (true); +fflush (stdout); + } +stdio_restore ();memset (&msg_done,0 ,sizeof (msg_done));@@ -1260,10 +1291,9 @@ static int worker_main(int sock) msg_done.test_done.sub_succ_cnt = test->sub_succ_cnt; msg_done.test_done.have_log = false; -if (env.verbosity >VERBOSE_NONE || test->force_log || test->error_cnt) { -if (env.log_cnt) - msg_done.test_done.have_log = true; - } +if (env.log_cnt) + msg_done.test_done.have_log = true; +if (send_message (sock, &msg_done) <0 ) {perror ("Fail to send message done" ); goto out;@@ -1357,6 +1387,12 @@ int main(int argc, char **argv)
Quoted 5 lines
tools/testing/selftests/bpf/test_progs.c int main(int argc, char **argv) · line 1390
Quoted 3 lines
tools/testing/selftests/bpf/test_progs.c +1
-0env.stdout = stdout; env.stderr = stderr; + env.subtest_status_fd = open_memstream(extremely misleading name, it's not an FD at all
it is indeed a file descriptor, isn't it? What's a better name for it?
Quoted 27 lines
Quoted 27 lines
tools/testing/selftests/bpf/test_progs.c +5
-0+ &env.subtest_status_buf, &env.subtest_status_cnt); +if (!env.subtest_status_fd) { +perror ("Failed to setup env.subtest_status_fd" ); +exit (EXIT_ERR_SETUP_INFRA ); + } env.has_testmod = true;if (!env.list_test_names &&load_bpf_testmod ()) {tools/testing/selftests/bpf/test_progs.h +4
-1@@ -89,6 +89,10 @@ struct test_env {pid_t *worker_pids;/* array of worker pids */ int *worker_socks;/* array of worker socks */ int *worker_current_test;/* array of current running test for each worker */ + +FILE * subtest_status_fd;/* fd for printing status line for subtests */ +char *subtest_status_buf;/* buffer for subtests status */ +size_t subtest_status_cnt; };#define MAX_LOG_TRUNK_SIZE 8192 --2.30.2
Re: [PATCH bpf-next 2/4] selftests/bpf: print subtest status line
Quoted 16 lines · On Tue, Oct 26, 2021 at 10:24 AM [email protected] <[email protected]>…
Quoted 13 lines · Andrii Nakryiko
Quoted 10 lines · Yucong Sun
From: Yucong Sun <[email protected]>
This patch restores behavior that prints one status line for each subtest executed. It works in both serial mode and parallel mode, and all verbosity settings.
The logic around IO hijacking could use some more simplification in the future.
Quoted 5 lines
Quoted 3 lines
This feels like a big hack, not a proper solution. What if we extend
MSG_TEST_DONEto signal also sub-test completion (along with subtest logs)? Would that work better and result in cleaner logic?I think the current solution is actually cleaner. Yes we could add
I disagree. Subtest is a first-class citizen, even if it's harder to parallelize due to more dynamic nature. Having protocol that reflects the fact that test can consist of subtests is the right way to go, I think.
Quoted 5 lines
fields in task struct to record each subtest's name and status and generate the status line separately, but it will only work in situations where all tests pass.
When there is an error, we do want to mix the status line with the actual stdout logs, which we won't be able to do afterwards.
I don't understand why success of failure is different. Worker shouldn't log status line into the logs and should send subtest logs separately from subtest name and status. And then dispatcher thread will print log (depending on success/failure and/or verbosity settings) and pre-defined status line. Status line is a fixed-format thing that's derived from subtest name and its success/failure result. It's not part of "log" per se.
Quoted 5 lines
Besides, we will still need to implement separate logic in 3 places (serial mode, parallel mode in worker process, and serial part of parallel mode execution). Having two copies of stdout logs is actually not that bad.
Which is exactly why I was asking to reuse sequential loop, so that we only have 2 loops. You felt it's not big deal. Maybe now is time to rethink this?
Two copies of logs is certainly a design smell, so please give it some thought and try to fix the protocol to accommodate subtests as a concept.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Signed-off-by Yucong Sun <[email protected]>--- tools/testing/selftests/bpf/test_progs.c | 56 +++++++++++++++++++----- tools/testing/selftests/bpf/test_progs.h | 4 ++ 2 files changed, 50 insertions(+), 10 deletions(-)
[...]
Quoted 9 lines
Quoted 7 lines
tools/testing/selftests/bpf/test_progs.c int main(int argc, char **argv) · line 1390
Quoted 5 lines
tools/testing/selftests/bpf/test_progs.c +1
-0@@ -1357,6 +1387,12 @@ int main(int argc, char **argv) env.stdout = stdout; env.stderr = stderr; + env.subtest_status_fd = open_memstream(extremely misleading name, it's not an FD at all
it is indeed a file descriptor, isn't it? What's a better name for it?
FD is an integer. This one is FILE *, so it may be "file", but certainly not an fd.
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
tools/testing/selftests/bpf/test_progs.c +5
-0+ &env.subtest_status_buf, &env.subtest_status_cnt); +if (!env.subtest_status_fd) { +perror ("Failed to setup env.subtest_status_fd" ); +exit (EXIT_ERR_SETUP_INFRA ); + } env.has_testmod = true;if (!env.list_test_names &&load_bpf_testmod ()) {tools/testing/selftests/bpf/test_progs.h +4
-1@@ -89,6 +89,10 @@ struct test_env {pid_t *worker_pids;/* array of worker pids */ int *worker_socks;/* array of worker socks */ int *worker_current_test;/* array of current running test for each worker */ + +FILE * subtest_status_fd;/* fd for printing status line for subtests */ +char *subtest_status_buf;/* buffer for subtests status */ +size_t subtest_status_cnt; };#define MAX_LOG_TRUNK_SIZE 8192 --2.30.2
Quoted 5 lines · Yucong Sun
Several patches to improve parallel execution mode, including printing subtest status line, updating
vmtest.shand fixed two previously dropped patch according to feedback.
I've dropped the second patch and applied all the rest. I can run sudo ./test_progs -j pretty reliably with no failures now and get 30-35 second saving on average. Thanks.
Let's keep discussing the subtest support separately.
Quoted 17 lines
Yucong Sun (4):
selfetests/bpf: Updatevmtest.shdefaults selftests/bpf: print subtest status line selftests/bpf: fixattach_probein parallel mode selftests/bpf: adding a namespace reset fortc_redirect.../selftests/bpf/prog_tests/attach_probe.c | 9 ++- .../selftests/bpf/prog_tests/tc_redirect.c | 14 +++++ tools/testing/selftests/bpf/test_progs.c | 56 +++++++++++++++---- tools/testing/selftests/bpf/test_progs.h | 4 ++ tools/testing/selftests/bpf/vmtest.sh | 6 +- 5 files changed, 74 insertions(+), 15 deletions(-)--
2.30.2