selftests/bpf: Improve by-name subtest selection logic in prog_tests
Subsystems (3)
PATCH v2 1/1 selftests/bpf: Improve by-name subtest selection logic in prog_tests
Improve subtest selection logic when using -t/-a/-d parameters. In particular, more than one subtest can be specified or a combination of tests / subtests.
-a send_signal -d send_signal/send_signal_nmi* - runs send_signal test without nmi tests
-a send_signal/send_signal_nmi*,find_vma - runs two send_signal subtests and find_vma test
-a 'send_signal*' -a find_vma -d send_signal/send_signal_nmi* - runs 2 send_signal test and find_vma test. Disables two send_signal nmi subtests
-t send_signal -t find_vma - runs two *send_signal* tests and one *find_vma* test
This will allow us to have granular control over which subtests to disable in the CI system instead of disabling whole tests.
Also, add new selftest to avoid possible regression when changing prog_test test name selection logic.
--- .../selftests/bpf/prog_tests/arg_parsing.c | 99 +++++++++++ tools/testing/selftests/bpf/test_progs.c | 156 +++++++++--------- tools/testing/selftests/bpf/test_progs.h | 15 +- tools/testing/selftests/bpf/testing_helpers.c | 84 ++++++++++ tools/testing/selftests/bpf/testing_helpers.h | 8 + 5 files changed, 275 insertions(+), 87 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/arg_parsing.c
tools/testing/selftests/bpf/prog_tests/arg_parsing.c new file +99 -0
@@ -0,0 +1,99 @@ +// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) + +#include "test_progs.h" +#include "testing_helpers.h" + +static void init_test_filter_set (struct test_filter_set *set) +{ + set->cnt =0 ; + set->tests =NULL ; +} + +static void free_test_filter_set (struct test_filter_set *set) +{ +int i, j; + +for (i =0 ; i < set->cnt; i++) { +for (j =0 ; j < set->tests[i].subtest_cnt; j++) +free ((void *)set->tests[i].subtests[j]); +free (set->tests[i].subtests); +free (set->tests[i].name); + } + +free (set->tests); +init_test_filter_set (set); +} + +static void test_parse_test_list (void ) +{ +struct test_filter_set set; + +init_test_filter_set (&set); + +ASSERT_OK (parse_test_list ("arg_parsing" , &set, true),"parsing" ); +if (!ASSERT_EQ (set.cnt,1 ,"test filters count" )) + goto error; +if (!ASSERT_OK_PTR (set.tests,"test filters initialized" )) + goto error; +ASSERT_EQ (set.tests[0 ].subtest_cnt,0 ,"subtest filters count" ); +ASSERT_OK (strcmp ("arg_parsing" , set.tests[0 ].name),"subtest name" ); +free_test_filter_set (&set); + +ASSERT_OK (parse_test_list ("arg_parsing,bpf_cookie" , &set, true), +"parsing" ); +if (!ASSERT_EQ (set.cnt,2 ,"count of test filters" )) + goto error; +if (!ASSERT_OK_PTR (set.tests,"test filters initialized" )) + goto error; +ASSERT_EQ (set.tests[0 ].subtest_cnt,0 ,"subtest filters count" ); +ASSERT_EQ (set.tests[1 ].subtest_cnt,0 ,"subtest filters count" ); +ASSERT_OK (strcmp ("arg_parsing" , set.tests[0 ].name),"test name" ); +ASSERT_OK (strcmp ("bpf_cookie" , set.tests[1 ].name),"test name" ); +free_test_filter_set (&set); + +ASSERT_OK (parse_test_list ("arg_parsing/arg_parsing,bpf_cookie" , + &set, + true), +"parsing" ); +if (!ASSERT_EQ (set.cnt,2 ,"count of test filters" )) + goto error; +if (!ASSERT_OK_PTR (set.tests,"test filters initialized" )) + goto error; +if (!ASSERT_EQ (set.tests[0 ].subtest_cnt,1 ,"subtest filters count" )) + goto error; +if (!ASSERT_EQ (set.tests[1 ].subtest_cnt,0 ,"subtest filters count" )) + goto error; +ASSERT_OK (strcmp ("arg_parsing" , set.tests[0 ].name),"test name" ); +ASSERT_OK (strcmp ("arg_parsing" , set.tests[0 ].subtests[0 ]), +"subtest name" ); +ASSERT_OK (strcmp ("bpf_cookie" , set.tests[1 ].name),"test name" ); +free_test_filter_set (&set); + +ASSERT_OK (parse_test_list ("arg_parsing/arg_parsing" , &set, true), +"parsing" ); +ASSERT_OK (parse_test_list ("bpf_cookie" , &set, true),"parsing" ); +ASSERT_OK (parse_test_list ("send_signal" , &set, true),"parsing" ); +if (!ASSERT_EQ (set.cnt,3 ,"count of test filters" )) + goto error; +if (!ASSERT_OK_PTR (set.tests,"test filters initialized" )) + goto error; +if (!ASSERT_EQ (set.tests[0 ].subtest_cnt,1 ,"subtest filters count" )) + goto error; +if (!ASSERT_EQ (set.tests[1 ].subtest_cnt,0 ,"subtest filters count" )) + goto error; +if (!ASSERT_EQ (set.tests[2 ].subtest_cnt,0 ,"subtest filters count" )) + goto error; +ASSERT_OK (strcmp ("arg_parsing" , set.tests[0 ].name),"test name" ); +ASSERT_OK (strcmp ("arg_parsing" , set.tests[0 ].subtests[0 ]), +"subtest name" ); +ASSERT_OK (strcmp ("bpf_cookie" , set.tests[1 ].name),"test name" ); +ASSERT_OK (strcmp ("send_signal" , set.tests[2 ].name),"test name" ); +error: +free_test_filter_set (&set); +} + +void test_arg_parsing (void ) +{ +if (test__start_subtest ("test_parse_test_list" )) +test_parse_test_list (); +}
tools/testing/selftests/bpf/test_progs.c +74 -82
230 lines not on this page · raw message
tools/testing/selftests/bpf/test_progs.h +10 -5
@@ -37,7 +37,6 @@ typedef __u16 __sum16;#include <bpf/bpf_endian.h> #include "trace_helpers.h" #include "testing_helpers.h" -#include "flow_dissector_load.h" enum verbosity {VERBOSE_NONE ,
@@ -46,14 +45,20 @@ enum verbosity { VERBOSE_SUPER, }; -struct str_set { -const char **strs; +struct test_filter { +char *name; +char **subtests; +int subtest_cnt; +}; + +struct test_filter_set { +struct test_filter *tests;int cnt; };struct test_selector { -struct str_set whitelist; -struct str_set blacklist; +struct test_filter_set whitelist; +struct test_filter_set blacklist;bool *num_set;int num_set_len; };
tools/testing/selftests/bpf/testing_helpers.c +84 -0
96 lines not on this page · raw message
tools/testing/selftests/bpf/testing_helpers.h +8 -0
@@ -12,3 +12,11 @@ int bpf_test_load_program(enum bpf_prog_type type, const struct bpf_insn *insns, size_t insns_cnt, const char *license, __u32 kern_version, char *log_buf, size_t log_buf_sz); + +/* +* below function is exported for testing in prog_test test +*/ +struct test_filter_set ; +int parse_test_list (const char *s, +struct test_filter_set *test_set, +bool is_glob_pattern);
Signature · 1 line
2.30.2
Quoted 18 lines · Mykola Lysenko
Improve subtest selection logic when using -t/-a/-d parameters. In particular, more than one subtest can be specified or a combination of tests / subtests.
-a
send_signal-d send_signal/send_signal_nmi* - runssend_signaltest without nmi tests-a send_signal/send_signal_nmi*,find_vma - runs two
send_signalsubtests andfind_vmatest-a 'send_signal*' -a
find_vma-d send_signal/send_signal_nmi* - runs 2send_signaltest andfind_vmatest. Disables twosend_signalnmi subtests-t
send_signal-tfind_vma- runs two *send_signal* tests and one *find_vma* test
Quoted 8 lines
This will allow us to have granular control over which subtests to disable in the CI system instead of disabling whole tests.
Also, add new selftest to avoid possible regression when changing
prog_testtest name selection logic.Signed-off-by Mykola Lysenko <[email protected]>---
Unfortunately there is some regression introduced by these changes, which is not easy to spot unless you try hard because of the annoying lack of visibility into subtest results. But if you try running:
sudo ./test_progs -v -t bpf_cookie/trace
You'll notice that with our change we don't execute any subtest at all. While before we'd execute bpf_cookie/tracepoint subtest properly. Please take a look, must be some subtle thing somewhere.
Quoted 7 lines
.../selftests/bpf/prog_tests/arg_parsing.c | 99 +++++++++++ tools/testing/selftests/bpf/test_progs.c | 156 +++++++++--------- tools/testing/selftests/bpf/test_progs.h | 15 +- tools/testing/selftests/bpf/testing_helpers.c | 84 ++++++++++ tools/testing/selftests/bpf/testing_helpers.h | 8 + 5 files changed, 275 insertions(+), 87 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/arg_parsing.c
[...]
Quoted 36 lines · Andrii Nakryiko
Quoted 18 lines · Mykola Lysenko
Improve subtest selection logic when using -t/-a/-d parameters. In particular, more than one subtest can be specified or a combination of tests / subtests.
-a
send_signal-d send_signal/send_signal_nmi* - runssend_signaltest without nmi tests-a send_signal/send_signal_nmi*,find_vma - runs two
send_signalsubtests andfind_vmatest-a 'send_signal*' -a
find_vma-d send_signal/send_signal_nmi* - runs 2send_signaltest andfind_vmatest. Disables twosend_signalnmi subtests-t
send_signal-tfind_vma- runs two *send_signal* tests and one *find_vma* testQuoted 8 lines
This will allow us to have granular control over which subtests to disable in the CI system instead of disabling whole tests.
Also, add new selftest to avoid possible regression when changing
prog_testtest name selection logic.Signed-off-by Mykola Lysenko <[email protected]>---
Unfortunately there is some regression introduced by these changes, which is not easy to spot unless you try hard because of the annoying lack of visibility into subtest results. But if you try running:
Quoted 5 lines
sudo ./test_progs -v -t bpf_cookie/trace
You'll notice that with our change we don't execute any subtest at all. While before we'd execute bpf_cookie/tracepoint subtest properly. Please take a look, must be some subtle thing somewhere.
Good catch. It is because I am not adding ‘*’ character around subtest name when -t parameter is used. Let me fix this.
Will add test around this as well.
Quoted 10 lines
Quoted 8 lines
.../selftests/bpf/prog_tests/arg_parsing.c| 99 +++++++++++tools/testing/selftests/bpf/test_progs.c| 156 +++++++++---------tools/testing/selftests/bpf/test_progs.h| 15 +-tools/testing/selftests/bpf/testing_helpers.c| 84 ++++++++++tools/testing/selftests/bpf/testing_helpers.h| 8 +5 files changed, 275 insertions(+), 87 deletions(-)create mode 100644
tools/testing/selftests/bpf/prog_tests/arg_parsing.c[...]