selftests/bpf: Improve by-name subtest selection logic in prog_tests
Subsystems (3)
PATCH v3 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 | 107 ++++++++++++ tools/testing/selftests/bpf/test_progs.c | 157 +++++++++--------- tools/testing/selftests/bpf/test_progs.h | 15 +- tools/testing/selftests/bpf/testing_helpers.c | 89 ++++++++++ tools/testing/selftests/bpf/testing_helpers.h | 8 + 5 files changed, 288 insertions(+), 88 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/arg_parsing.c
tools/testing/selftests/bpf/prog_tests/arg_parsing.c new file +107 -0
@@ -0,0 +1,107 @@ +// 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; +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 ("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; +ASSERT_EQ (set.tests[1 ].subtest_cnt,0 ,"subtest filters count" ); +ASSERT_EQ (set.tests[2 ].subtest_cnt,0 ,"subtest filters count" ); +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" ); +free_test_filter_set (&set); + +ASSERT_OK (parse_test_list ("bpf_cookie/trace" , &set, false),"parsing" ); +if (!ASSERT_EQ (set.cnt,1 ,"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; +ASSERT_OK (strcmp ("*bpf_cookie*" , set.tests[0 ].name),"test name" ); +ASSERT_OK (strcmp ("*trace*" , set.tests[0 ].subtests[0 ]),"subtest 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 -83
237 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 +89 -0
101 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
This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:
Quoted 8 lines · On Fri, 8 Apr 2022 17:17:49 -0700 you wrote:
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[...]
Here is the summary with links:
- [v3,bpf-next] selftests/bpf: Improve by-name subtest selection logic in prog_tests
https://git.kernel.org/bpf/bpf-next/c/61ddff373ffa
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html