selftests/bpf: consolidate common code in run_one_test function
Subsystems (3)
PATCH 1/1 selftests/bpf: consolidate common code in run_one_test function
This is a pre-req to add separate logging for each subtest.
Move all the mutable test data to the test_result struct. Move per-test init/de-init into the run_one_test function. Consolidate data aggregation and final log output in calculate_and_print_summary function.
As a side effect, this patch fixes double counting of errors for subtests and possible duplicate output of subtest log on failures.
Also, add prog_tests_framework.c test to verify some of the counting logic.
As part of verification, confirmed that number of reported tests is the same before and after the change for both parallel and sequential test execution.
--- .../bpf/prog_tests/prog_tests_framework.c | 55 ++++ tools/testing/selftests/bpf/test_progs.c | 301 +++++++----------- tools/testing/selftests/bpf/test_progs.h | 32 +- 3 files changed, 195 insertions(+), 193 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/prog_tests_framework.c
tools/testing/selftests/bpf/prog_tests/prog_tests_framework.c new file +55 -0
@@ -0,0 +1,55 @@ +// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) + +#include "test_progs.h" +#include "testing_helpers.h" + +static void clear_test_result (struct test_result *result) +{ + result->error_cnt =0 ; + result->sub_succ_cnt =0 ; + result->skip_cnt =0 ; +} + +void test_prog_tests_framework (void ) +{ +struct test_result *result = env.test_result; + +// in all the ASSERT calls below we need to return on the first +// error due to the fact that we are cleaning the test state after +// each dummy subtest + +// test we properly count skipped tests with subtests +if (test__start_subtest ("test_good_subtest" )) +test__end_subtest (); +if (!ASSERT_EQ (result->skip_cnt,0 ,"skip_cnt_check" )) +return ; +if (!ASSERT_EQ (result->error_cnt,0 ,"error_cnt_check" )) +return ; +if (!ASSERT_EQ (result->subtest_num,1 ,"subtest_num_check" )) +return ; +clear_test_result (result); + +if (test__start_subtest ("test_skip_subtest" )) { +test__skip (); +test__end_subtest (); + } +if (test__start_subtest ("test_skip_subtest" )) { +test__skip (); +test__end_subtest (); + } +if (!ASSERT_EQ (result->skip_cnt,2 ,"skip_cnt_check" )) +return ; +if (!ASSERT_EQ (result->subtest_num,3 ,"subtest_num_check" )) +return ; +clear_test_result (result); + +if (test__start_subtest ("test_fail_subtest" )) { +test__fail (); +test__end_subtest (); + } +if (!ASSERT_EQ (result->error_cnt,1 ,"error_cnt_check" )) +return ; +if (!ASSERT_EQ (result->subtest_num,4 ,"subtest_num_check" )) +return ; +clear_test_result (result); +}
tools/testing/selftests/bpf/test_progs.c +114 -187
507 lines not on this page · raw message
tools/testing/selftests/bpf/test_progs.h +26 -6
@@ -64,6 +64,24 @@ struct test_selector {int num_set_len; }; +struct test_result { +bool tested; + +int error_cnt; +int skip_cnt; +int subtest_skip_cnt; +int sub_succ_cnt; + +char *subtest_name; +int subtest_num; + +/* store counts before subtest started */ +int old_error_cnt; + +size_t log_cnt; +char *log_buf; +}; +struct test_env {struct test_selector test_selector;struct test_selector subtest_selector;
@@ -76,7 +94,8 @@ struct test_env {bool get_test_cnt;bool list_test_names; -struct prog_test_def *test;/* current running tests */ +struct prog_test_def *test;/* current running test */ +struct test_result *test_result;/* current running test result */ FILE *stdout;FILE *stderr;
@@ -126,11 +145,12 @@ struct msg {extern struct test_env env; -extern void test__force_log (); -extern bool test__start_subtest (const char *name); -extern void test__skip (void ); -extern void test__fail (void ); -extern int test__join_cgroup (const char *path); +void test__force_log (void ); +bool test__start_subtest (const char *name); +void test__end_subtest (void ); +void test__skip (void ); +void test__fail (void ); +int test__join_cgroup (const char *path); #define PRINT_FAIL(format...) \ ({ \
Signature · 1 line
2.30.2
Quoted 14 lines · Mykola Lysenko
This is a pre-req to add separate logging for each subtest.
Move all the mutable test data to the
test_resultstruct. Move per-testinit/de-initinto therun_one_testfunction. Consolidate data aggregation and final log output incalculate_and_print_summaryfunction.
As a side effect, this patch fixes double counting of errors for subtests and possible duplicate output of subtest log on failures.Also, add
prog_tests_framework.ctest to verify some of the counting logic.
Quoted 6 lines
As part of verification, confirmed that number of reported tests is the same before and after the change for both parallel and sequential test execution.
Signed-off-by Mykola Lysenko <[email protected]>---
The consolidation of the per-test logic in one place is great, thanks for tackling this! But I tried this locally and understood what you were mentioning as completely buffered output. It really sucks and is a big step back, I think :(
Running sudo ./test_progs -j I see no output for a long while and only then get entire output at the end:
#239 xdp_noinline:OK
#240 xdp_perf:OK
#241 xdpwall:OK
All error logs:
#58 fexit_sleep:FAIL
test_fexit_sleep:PASS:fexit_skel_load 0 nsec
test_fexit_sleep:PASS:fexit_attach 0 nsec
test_fexit_sleep:PASS:clone 0 nsec
test_fexit_sleep:PASS:fexit_cnt 0 nsec
test_fexit_sleep:PASS:waitpid 0 nsec
test_fexit_sleep:PASS:exitstatus 0 nsec
test_fexit_sleep:FAIL:fexit_cnt 2
Summary: 240/1156 PASSED, 34 SKIPPED, 1 FAILED
First, just not seeing the progress made me wonder for a good minute or more whether something is just stuck and deadlock. Which is anxiety inducing and I'd rather avoid this :)
Second, as you can see, fexit_sleep actually failed (it does sometimes in parallel mode). But I saw this only at the very end, while normally I'd notice it as soon as it completes. In this case I know fexit_sleep can fail and I'd ignore, but if there was some subtest that suddenly breaks, I don't wait for all the tests to finish, I ctrl-C and go investigate. Now I can't do that.
How much of a problem is it to preserve old behavior of streaming results of tests as they come, but consolidate duplicate logic in one place?
Quoted 23 lines
.../bpf/prog_tests/prog_tests_framework.c | 55 ++++ tools/testing/selftests/bpf/test_progs.c | 301 +++++++----------- tools/testing/selftests/bpf/test_progs.h | 32 +- 3 files changed, 195 insertions(+), 193 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/prog_tests_framework.ctools/testing/selftests/bpf/prog_tests/prog_tests_framework.c new file +11
-0@@ -0,0 +1,55 @@ +// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) + +#include "test_progs.h" +#include "testing_helpers.h" + +static void clear_test_result (struct test_result *result) +{ + result->error_cnt =0 ; + result->sub_succ_cnt =0 ; + result->skip_cnt =0 ; +}
tools/testing/selftests/bpf/prog_tests/prog_tests_framework.c line 21
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/prog_tests_framework.c new file +10
-0+ +void test_prog_tests_framework (void ) +{ +struct test_result *result = env.test_result; + +// in all the ASSERT calls below we need to return on the first +// error due to the fact that we are cleaning the test state after +// each dummy subtest + +// test we properly count skipped tests with subtests
C++ comments, please use /* */
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/prog_tests_framework.c new file +10
-0+if (test__start_subtest ("test_good_subtest" )) +test__end_subtest (); +if (!ASSERT_EQ (result->skip_cnt,0 ,"skip_cnt_check" )) +return ; +if (!ASSERT_EQ (result->error_cnt,0 ,"error_cnt_check" )) +return ; +if (!ASSERT_EQ (result->subtest_num,1 ,"subtest_num_check" )) +return ; +clear_test_result (result); +
[...]
Quoted 23 lines · Andrii Nakryiko
Quoted 18 lines · Mykola Lysenko
This is a pre-req to add separate logging for each subtest.
Move all the mutable test data to the
test_resultstruct. Move per-testinit/de-initinto therun_one_testfunction. Consolidate data aggregation and final log output incalculate_and_print_summaryfunction.
As a side effect, this patch fixes double counting of errors for subtests and possible duplicate output of subtest log on failures.Also, add
prog_tests_framework.ctest to verify some of the counting logic.As part of verification, confirmed that number of reported tests is the same before and after the change for both parallel and sequential test execution.
Quoted 7 lines
Quoted 2 lines
Signed-off-by Mykola Lysenko <[email protected]>---
The consolidation of the per-test logic in one place is great, thanks for tackling this! But I tried this locally and understood what you were mentioning as completely buffered output. It really sucks and is a big step back, I think :(
Thanks Andrii! Your points make sense, in the next revision I will keep this behavior untouched.
Quoted 63 lines
Running sudo ./test_progs -j I see no output for a long while and only then get entire output at the end:
#239 xdp_noinline:OK
#240 xdp_perf:OK
#241 xdpwall:OKAll error logs:
#58 fexit_sleep:FAIL
test_fexit_sleep:PASS:fexit_skel_load 0 nsec
test_fexit_sleep:PASS:fexit_attach 0 nsec
test_fexit_sleep:PASS:clone 0 nsec
test_fexit_sleep:PASS:fexit_cnt 0 nsec
test_fexit_sleep:PASS:waitpid 0 nsec
test_fexit_sleep:PASS:exitstatus 0 nsec
test_fexit_sleep:FAIL:fexit_cnt 2
Summary: 240/1156 PASSED, 34 SKIPPED, 1 FAILEDFirst, just not seeing the progress made me wonder for a good minute or more whether something is just stuck and deadlock. Which is anxiety inducing and I'd rather avoid this :)
Second, as you can see,
fexit_sleepactually failed (it does sometimes in parallel mode). But I saw this only at the very end, while normally I'd notice it as soon as it completes. In this case I knowfexit_sleepcan fail and I'd ignore, but if there was some subtest that suddenly breaks, I don't wait for all the tests to finish, I ctrl-C and go investigate. Now I can't do that.How much of a problem is it to preserve old behavior of streaming results of tests as they come, but consolidate duplicate logic in one place?
Quoted 27 lines
.../bpf/prog_tests/prog_tests_framework.c| 55 ++++tools/testing/selftests/bpf/test_progs.c| 301 +++++++-----------tools/testing/selftests/bpf/test_progs.h| 32 +-3 files changed, 195 insertions(+), 193 deletions(-)create mode 100644
tools/testing/selftests/bpf/prog_tests/prog_tests_framework.ctools/testing/selftests/bpf/prog_tests/prog_tests_framework.c new file +15
-0@@ -0,0 +1,55 @@ +// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) + +#include "test_progs.h" +#include "testing_helpers.h" + +static void clear_test_result (struct test_result *result) +{ + result->error_cnt =0 ; + result->sub_succ_cnt =0 ; + result->skip_cnt =0 ; +} + +void test_prog_tests_framework (void ) +{ +struct test_result *result = env.test_result;
Quoted 8 lines
tools/testing/selftests/bpf/prog_tests/prog_tests_framework.c line 21
Quoted 6 lines
tools/testing/selftests/bpf/prog_tests/prog_tests_framework.c new file +6
-0+ +// in all the ASSERT calls below we need to return on the first +// error due to the fact that we are cleaning the test state after +// each dummy subtest + +// test we properly count skipped tests with subtests C++ comments, please use /* */
Will fix.
Quoted 14 lines
Quoted 12 lines
tools/testing/selftests/bpf/prog_tests/prog_tests_framework.c new file +10
-0+if (test__start_subtest ("test_good_subtest" )) +test__end_subtest (); +if (!ASSERT_EQ (result->skip_cnt,0 ,"skip_cnt_check" )) +return ; +if (!ASSERT_EQ (result->error_cnt,0 ,"error_cnt_check" )) +return ; +if (!ASSERT_EQ (result->subtest_num,1 ,"subtest_num_check" )) +return ; +clear_test_result (result); +[...]