2019-05-28 17:10:09 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2017-03-31 04:45:41 +00:00
|
|
|
/* Copyright (c) 2017 Facebook
|
|
|
|
*/
|
2020-03-14 01:39:32 +00:00
|
|
|
#define _GNU_SOURCE
|
2019-03-02 03:42:13 +00:00
|
|
|
#include "test_progs.h"
|
2019-09-04 16:25:04 +00:00
|
|
|
#include "cgroup_helpers.h"
|
2018-02-26 21:34:32 +00:00
|
|
|
#include "bpf_rlimit.h"
|
2019-07-28 03:25:24 +00:00
|
|
|
#include <argp.h>
|
2020-03-14 01:39:32 +00:00
|
|
|
#include <pthread.h>
|
|
|
|
#include <sched.h>
|
2020-02-25 00:08:47 +00:00
|
|
|
#include <signal.h>
|
2020-03-14 01:39:32 +00:00
|
|
|
#include <string.h>
|
2020-02-25 00:08:47 +00:00
|
|
|
#include <execinfo.h> /* backtrace */
|
2021-01-12 07:55:17 +00:00
|
|
|
#include <linux/membarrier.h>
|
2017-03-31 04:45:41 +00:00
|
|
|
|
2020-07-07 07:12:19 +00:00
|
|
|
#define EXIT_NO_TEST 2
|
2020-07-07 07:12:25 +00:00
|
|
|
#define EXIT_ERR_SETUP_INFRA 3
|
2020-07-07 07:12:19 +00:00
|
|
|
|
2019-07-28 03:25:28 +00:00
|
|
|
/* defined in test_progs.h */
|
selftests/bpf: Add whitelist/blacklist of test names to test_progs
Add ability to specify a list of test name substrings for selecting which
tests to run. So now -t is accepting a comma-separated list of strings,
similarly to how -n accepts a comma-separated list of test numbers.
Additionally, add ability to blacklist tests by name. Blacklist takes
precedence over whitelist. Blacklisting is important for cases where it's
known that some tests can't pass (e.g., due to perf hardware events that are
not available within VM). This is going to be used for libbpf testing in
Travis CI in its Github repo.
Example runs with just whitelist and whitelist + blacklist:
$ sudo ./test_progs -tattach,core/existence
#1 attach_probe:OK
#6 cgroup_attach_autodetach:OK
#7 cgroup_attach_multi:OK
#8 cgroup_attach_override:OK
#9 core_extern:OK
#10/44 existence:OK
#10/45 existence___minimal:OK
#10/46 existence__err_int_sz:OK
#10/47 existence__err_int_type:OK
#10/48 existence__err_int_kind:OK
#10/49 existence__err_arr_kind:OK
#10/50 existence__err_arr_value_type:OK
#10/51 existence__err_struct_type:OK
#10 core_reloc:OK
#19 flow_dissector_reattach:OK
#60 tp_attach_query:OK
Summary: 8/8 PASSED, 0 SKIPPED, 0 FAILED
$ sudo ./test_progs -tattach,core/existence -bcgroup,flow/arr
#1 attach_probe:OK
#9 core_extern:OK
#10/44 existence:OK
#10/45 existence___minimal:OK
#10/46 existence__err_int_sz:OK
#10/47 existence__err_int_type:OK
#10/48 existence__err_int_kind:OK
#10/51 existence__err_struct_type:OK
#10 core_reloc:OK
#60 tp_attach_query:OK
Summary: 4/6 PASSED, 0 SKIPPED, 0 FAILED
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Cc: Julia Kartseva <hex@fb.com>
Link: https://lore.kernel.org/bpf/20200116005549.3644118-1-andriin@fb.com
2020-01-16 00:55:49 +00:00
|
|
|
struct test_env env = {};
|
2019-07-28 03:25:28 +00:00
|
|
|
|
|
|
|
struct prog_test_def {
|
|
|
|
const char *test_name;
|
|
|
|
int test_num;
|
|
|
|
void (*run_test)(void);
|
|
|
|
bool force_log;
|
|
|
|
int error_cnt;
|
2019-08-21 23:44:24 +00:00
|
|
|
int skip_cnt;
|
2019-07-28 03:25:28 +00:00
|
|
|
bool tested;
|
2019-09-04 16:25:04 +00:00
|
|
|
bool need_cgroup_cleanup;
|
selftests/bpf: add sub-tests support for test_progs
Allow tests to have their own set of sub-tests. Also add ability to do
test/subtest selection using `-t <test-name>/<subtest-name>` and `-n
<test-nums-set>/<subtest-nums-set>`, as an extension of existing -t/-n
selector options. For the <test-num-set> format: it's a comma-separated
list of either individual test numbers (1-based), or range of test
numbers. E.g., all of the following are valid sets of test numbers:
- 10
- 1,2,3
- 1-3
- 5-10,1,3-4
'/<subtest' part is optional, but has the same format. E.g., to select
test #3 and its sub-tests #10 through #15, use: -t 3/10-15.
Similarly, to select tests by name, use `-t verif/strobe`:
$ sudo ./test_progs -t verif/strobe
#3/12 strobemeta.o:OK
#3/13 strobemeta_nounroll1.o:OK
#3/14 strobemeta_nounroll2.o:OK
#3 bpf_verif_scale:OK
Summary: 1/3 PASSED, 0 FAILED
Example of using subtest API is in the next patch, converting
bpf_verif_scale.c tests to use sub-tests.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-07-28 03:25:29 +00:00
|
|
|
|
2019-10-21 03:39:00 +00:00
|
|
|
char *subtest_name;
|
selftests/bpf: add sub-tests support for test_progs
Allow tests to have their own set of sub-tests. Also add ability to do
test/subtest selection using `-t <test-name>/<subtest-name>` and `-n
<test-nums-set>/<subtest-nums-set>`, as an extension of existing -t/-n
selector options. For the <test-num-set> format: it's a comma-separated
list of either individual test numbers (1-based), or range of test
numbers. E.g., all of the following are valid sets of test numbers:
- 10
- 1,2,3
- 1-3
- 5-10,1,3-4
'/<subtest' part is optional, but has the same format. E.g., to select
test #3 and its sub-tests #10 through #15, use: -t 3/10-15.
Similarly, to select tests by name, use `-t verif/strobe`:
$ sudo ./test_progs -t verif/strobe
#3/12 strobemeta.o:OK
#3/13 strobemeta_nounroll1.o:OK
#3/14 strobemeta_nounroll2.o:OK
#3 bpf_verif_scale:OK
Summary: 1/3 PASSED, 0 FAILED
Example of using subtest API is in the next patch, converting
bpf_verif_scale.c tests to use sub-tests.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-07-28 03:25:29 +00:00
|
|
|
int subtest_num;
|
|
|
|
|
|
|
|
/* store counts before subtest started */
|
|
|
|
int old_error_cnt;
|
2019-07-28 03:25:28 +00:00
|
|
|
};
|
|
|
|
|
2020-03-11 18:53:45 +00:00
|
|
|
/* Override C runtime library's usleep() implementation to ensure nanosleep()
|
|
|
|
* is always called. Usleep is frequently used in selftests as a way to
|
|
|
|
* trigger kprobe and tracepoints.
|
|
|
|
*/
|
|
|
|
int usleep(useconds_t usec)
|
|
|
|
{
|
2020-03-14 00:27:43 +00:00
|
|
|
struct timespec ts = {
|
|
|
|
.tv_sec = usec / 1000000,
|
|
|
|
.tv_nsec = (usec % 1000000) * 1000,
|
|
|
|
};
|
2020-03-13 06:18:37 +00:00
|
|
|
|
2020-03-14 00:27:43 +00:00
|
|
|
return syscall(__NR_nanosleep, &ts, NULL);
|
2020-03-11 18:53:45 +00:00
|
|
|
}
|
|
|
|
|
selftests/bpf: add sub-tests support for test_progs
Allow tests to have their own set of sub-tests. Also add ability to do
test/subtest selection using `-t <test-name>/<subtest-name>` and `-n
<test-nums-set>/<subtest-nums-set>`, as an extension of existing -t/-n
selector options. For the <test-num-set> format: it's a comma-separated
list of either individual test numbers (1-based), or range of test
numbers. E.g., all of the following are valid sets of test numbers:
- 10
- 1,2,3
- 1-3
- 5-10,1,3-4
'/<subtest' part is optional, but has the same format. E.g., to select
test #3 and its sub-tests #10 through #15, use: -t 3/10-15.
Similarly, to select tests by name, use `-t verif/strobe`:
$ sudo ./test_progs -t verif/strobe
#3/12 strobemeta.o:OK
#3/13 strobemeta_nounroll1.o:OK
#3/14 strobemeta_nounroll2.o:OK
#3 bpf_verif_scale:OK
Summary: 1/3 PASSED, 0 FAILED
Example of using subtest API is in the next patch, converting
bpf_verif_scale.c tests to use sub-tests.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-07-28 03:25:29 +00:00
|
|
|
static bool should_run(struct test_selector *sel, int num, const char *name)
|
|
|
|
{
|
selftests/bpf: Add whitelist/blacklist of test names to test_progs
Add ability to specify a list of test name substrings for selecting which
tests to run. So now -t is accepting a comma-separated list of strings,
similarly to how -n accepts a comma-separated list of test numbers.
Additionally, add ability to blacklist tests by name. Blacklist takes
precedence over whitelist. Blacklisting is important for cases where it's
known that some tests can't pass (e.g., due to perf hardware events that are
not available within VM). This is going to be used for libbpf testing in
Travis CI in its Github repo.
Example runs with just whitelist and whitelist + blacklist:
$ sudo ./test_progs -tattach,core/existence
#1 attach_probe:OK
#6 cgroup_attach_autodetach:OK
#7 cgroup_attach_multi:OK
#8 cgroup_attach_override:OK
#9 core_extern:OK
#10/44 existence:OK
#10/45 existence___minimal:OK
#10/46 existence__err_int_sz:OK
#10/47 existence__err_int_type:OK
#10/48 existence__err_int_kind:OK
#10/49 existence__err_arr_kind:OK
#10/50 existence__err_arr_value_type:OK
#10/51 existence__err_struct_type:OK
#10 core_reloc:OK
#19 flow_dissector_reattach:OK
#60 tp_attach_query:OK
Summary: 8/8 PASSED, 0 SKIPPED, 0 FAILED
$ sudo ./test_progs -tattach,core/existence -bcgroup,flow/arr
#1 attach_probe:OK
#9 core_extern:OK
#10/44 existence:OK
#10/45 existence___minimal:OK
#10/46 existence__err_int_sz:OK
#10/47 existence__err_int_type:OK
#10/48 existence__err_int_kind:OK
#10/51 existence__err_struct_type:OK
#10 core_reloc:OK
#60 tp_attach_query:OK
Summary: 4/6 PASSED, 0 SKIPPED, 0 FAILED
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Cc: Julia Kartseva <hex@fb.com>
Link: https://lore.kernel.org/bpf/20200116005549.3644118-1-andriin@fb.com
2020-01-16 00:55:49 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < sel->blacklist.cnt; i++) {
|
|
|
|
if (strstr(name, sel->blacklist.strs[i]))
|
|
|
|
return false;
|
|
|
|
}
|
selftests/bpf: add sub-tests support for test_progs
Allow tests to have their own set of sub-tests. Also add ability to do
test/subtest selection using `-t <test-name>/<subtest-name>` and `-n
<test-nums-set>/<subtest-nums-set>`, as an extension of existing -t/-n
selector options. For the <test-num-set> format: it's a comma-separated
list of either individual test numbers (1-based), or range of test
numbers. E.g., all of the following are valid sets of test numbers:
- 10
- 1,2,3
- 1-3
- 5-10,1,3-4
'/<subtest' part is optional, but has the same format. E.g., to select
test #3 and its sub-tests #10 through #15, use: -t 3/10-15.
Similarly, to select tests by name, use `-t verif/strobe`:
$ sudo ./test_progs -t verif/strobe
#3/12 strobemeta.o:OK
#3/13 strobemeta_nounroll1.o:OK
#3/14 strobemeta_nounroll2.o:OK
#3 bpf_verif_scale:OK
Summary: 1/3 PASSED, 0 FAILED
Example of using subtest API is in the next patch, converting
bpf_verif_scale.c tests to use sub-tests.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-07-28 03:25:29 +00:00
|
|
|
|
selftests/bpf: Add whitelist/blacklist of test names to test_progs
Add ability to specify a list of test name substrings for selecting which
tests to run. So now -t is accepting a comma-separated list of strings,
similarly to how -n accepts a comma-separated list of test numbers.
Additionally, add ability to blacklist tests by name. Blacklist takes
precedence over whitelist. Blacklisting is important for cases where it's
known that some tests can't pass (e.g., due to perf hardware events that are
not available within VM). This is going to be used for libbpf testing in
Travis CI in its Github repo.
Example runs with just whitelist and whitelist + blacklist:
$ sudo ./test_progs -tattach,core/existence
#1 attach_probe:OK
#6 cgroup_attach_autodetach:OK
#7 cgroup_attach_multi:OK
#8 cgroup_attach_override:OK
#9 core_extern:OK
#10/44 existence:OK
#10/45 existence___minimal:OK
#10/46 existence__err_int_sz:OK
#10/47 existence__err_int_type:OK
#10/48 existence__err_int_kind:OK
#10/49 existence__err_arr_kind:OK
#10/50 existence__err_arr_value_type:OK
#10/51 existence__err_struct_type:OK
#10 core_reloc:OK
#19 flow_dissector_reattach:OK
#60 tp_attach_query:OK
Summary: 8/8 PASSED, 0 SKIPPED, 0 FAILED
$ sudo ./test_progs -tattach,core/existence -bcgroup,flow/arr
#1 attach_probe:OK
#9 core_extern:OK
#10/44 existence:OK
#10/45 existence___minimal:OK
#10/46 existence__err_int_sz:OK
#10/47 existence__err_int_type:OK
#10/48 existence__err_int_kind:OK
#10/51 existence__err_struct_type:OK
#10 core_reloc:OK
#60 tp_attach_query:OK
Summary: 4/6 PASSED, 0 SKIPPED, 0 FAILED
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Cc: Julia Kartseva <hex@fb.com>
Link: https://lore.kernel.org/bpf/20200116005549.3644118-1-andriin@fb.com
2020-01-16 00:55:49 +00:00
|
|
|
for (i = 0; i < sel->whitelist.cnt; i++) {
|
|
|
|
if (strstr(name, sel->whitelist.strs[i]))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!sel->whitelist.cnt && !sel->num_set)
|
selftests/bpf: add sub-tests support for test_progs
Allow tests to have their own set of sub-tests. Also add ability to do
test/subtest selection using `-t <test-name>/<subtest-name>` and `-n
<test-nums-set>/<subtest-nums-set>`, as an extension of existing -t/-n
selector options. For the <test-num-set> format: it's a comma-separated
list of either individual test numbers (1-based), or range of test
numbers. E.g., all of the following are valid sets of test numbers:
- 10
- 1,2,3
- 1-3
- 5-10,1,3-4
'/<subtest' part is optional, but has the same format. E.g., to select
test #3 and its sub-tests #10 through #15, use: -t 3/10-15.
Similarly, to select tests by name, use `-t verif/strobe`:
$ sudo ./test_progs -t verif/strobe
#3/12 strobemeta.o:OK
#3/13 strobemeta_nounroll1.o:OK
#3/14 strobemeta_nounroll2.o:OK
#3 bpf_verif_scale:OK
Summary: 1/3 PASSED, 0 FAILED
Example of using subtest API is in the next patch, converting
bpf_verif_scale.c tests to use sub-tests.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-07-28 03:25:29 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return num < sel->num_set_len && sel->num_set[num];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dump_test_log(const struct prog_test_def *test, bool failed)
|
|
|
|
{
|
2019-08-06 17:45:27 +00:00
|
|
|
if (stdout == env.stdout)
|
|
|
|
return;
|
|
|
|
|
|
|
|
fflush(stdout); /* exports env.log_buf & env.log_cnt */
|
|
|
|
|
2019-11-20 00:35:48 +00:00
|
|
|
if (env.verbosity > VERBOSE_NONE || test->force_log || failed) {
|
selftests/bpf: add sub-tests support for test_progs
Allow tests to have their own set of sub-tests. Also add ability to do
test/subtest selection using `-t <test-name>/<subtest-name>` and `-n
<test-nums-set>/<subtest-nums-set>`, as an extension of existing -t/-n
selector options. For the <test-num-set> format: it's a comma-separated
list of either individual test numbers (1-based), or range of test
numbers. E.g., all of the following are valid sets of test numbers:
- 10
- 1,2,3
- 1-3
- 5-10,1,3-4
'/<subtest' part is optional, but has the same format. E.g., to select
test #3 and its sub-tests #10 through #15, use: -t 3/10-15.
Similarly, to select tests by name, use `-t verif/strobe`:
$ sudo ./test_progs -t verif/strobe
#3/12 strobemeta.o:OK
#3/13 strobemeta_nounroll1.o:OK
#3/14 strobemeta_nounroll2.o:OK
#3 bpf_verif_scale:OK
Summary: 1/3 PASSED, 0 FAILED
Example of using subtest API is in the next patch, converting
bpf_verif_scale.c tests to use sub-tests.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-07-28 03:25:29 +00:00
|
|
|
if (env.log_cnt) {
|
selftests/bpf: test_progs: fix verbose mode garbage
fseeko(.., 0, SEEK_SET) on a memstream just puts the buffer pointer
to the beginning so when we call fflush on it we get some garbage
log data from the previous test. Let's manually set terminating
byte to zero at the reported buffer size.
To show the issue consider the following snippet:
stream = open_memstream (&buf, &len);
fprintf(stream, "aaa");
fflush(stream);
printf("buf=%s, len=%zu\n", buf, len);
fseeko(stream, 0, SEEK_SET);
fprintf(stream, "b");
fflush(stream);
printf("buf=%s, len=%zu\n", buf, len);
Output:
buf=aaa, len=3
buf=baa, len=1
Fixes: 946152b3c5d6 ("selftests/bpf: test_progs: switch to open_memstream")
Signed-off-by: Stanislav Fomichev <sdf@google.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-08-31 02:34:26 +00:00
|
|
|
env.log_buf[env.log_cnt] = '\0';
|
2019-08-06 17:45:27 +00:00
|
|
|
fprintf(env.stdout, "%s", env.log_buf);
|
selftests/bpf: add sub-tests support for test_progs
Allow tests to have their own set of sub-tests. Also add ability to do
test/subtest selection using `-t <test-name>/<subtest-name>` and `-n
<test-nums-set>/<subtest-nums-set>`, as an extension of existing -t/-n
selector options. For the <test-num-set> format: it's a comma-separated
list of either individual test numbers (1-based), or range of test
numbers. E.g., all of the following are valid sets of test numbers:
- 10
- 1,2,3
- 1-3
- 5-10,1,3-4
'/<subtest' part is optional, but has the same format. E.g., to select
test #3 and its sub-tests #10 through #15, use: -t 3/10-15.
Similarly, to select tests by name, use `-t verif/strobe`:
$ sudo ./test_progs -t verif/strobe
#3/12 strobemeta.o:OK
#3/13 strobemeta_nounroll1.o:OK
#3/14 strobemeta_nounroll2.o:OK
#3 bpf_verif_scale:OK
Summary: 1/3 PASSED, 0 FAILED
Example of using subtest API is in the next patch, converting
bpf_verif_scale.c tests to use sub-tests.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-07-28 03:25:29 +00:00
|
|
|
if (env.log_buf[env.log_cnt - 1] != '\n')
|
2019-08-06 17:45:27 +00:00
|
|
|
fprintf(env.stdout, "\n");
|
selftests/bpf: add sub-tests support for test_progs
Allow tests to have their own set of sub-tests. Also add ability to do
test/subtest selection using `-t <test-name>/<subtest-name>` and `-n
<test-nums-set>/<subtest-nums-set>`, as an extension of existing -t/-n
selector options. For the <test-num-set> format: it's a comma-separated
list of either individual test numbers (1-based), or range of test
numbers. E.g., all of the following are valid sets of test numbers:
- 10
- 1,2,3
- 1-3
- 5-10,1,3-4
'/<subtest' part is optional, but has the same format. E.g., to select
test #3 and its sub-tests #10 through #15, use: -t 3/10-15.
Similarly, to select tests by name, use `-t verif/strobe`:
$ sudo ./test_progs -t verif/strobe
#3/12 strobemeta.o:OK
#3/13 strobemeta_nounroll1.o:OK
#3/14 strobemeta_nounroll2.o:OK
#3 bpf_verif_scale:OK
Summary: 1/3 PASSED, 0 FAILED
Example of using subtest API is in the next patch, converting
bpf_verif_scale.c tests to use sub-tests.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-07-28 03:25:29 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-06 17:45:27 +00:00
|
|
|
|
|
|
|
fseeko(stdout, 0, SEEK_SET); /* rewind */
|
selftests/bpf: add sub-tests support for test_progs
Allow tests to have their own set of sub-tests. Also add ability to do
test/subtest selection using `-t <test-name>/<subtest-name>` and `-n
<test-nums-set>/<subtest-nums-set>`, as an extension of existing -t/-n
selector options. For the <test-num-set> format: it's a comma-separated
list of either individual test numbers (1-based), or range of test
numbers. E.g., all of the following are valid sets of test numbers:
- 10
- 1,2,3
- 1-3
- 5-10,1,3-4
'/<subtest' part is optional, but has the same format. E.g., to select
test #3 and its sub-tests #10 through #15, use: -t 3/10-15.
Similarly, to select tests by name, use `-t verif/strobe`:
$ sudo ./test_progs -t verif/strobe
#3/12 strobemeta.o:OK
#3/13 strobemeta_nounroll1.o:OK
#3/14 strobemeta_nounroll2.o:OK
#3 bpf_verif_scale:OK
Summary: 1/3 PASSED, 0 FAILED
Example of using subtest API is in the next patch, converting
bpf_verif_scale.c tests to use sub-tests.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-07-28 03:25:29 +00:00
|
|
|
}
|
|
|
|
|
2019-08-21 23:44:24 +00:00
|
|
|
static void skip_account(void)
|
|
|
|
{
|
|
|
|
if (env.test->skip_cnt) {
|
|
|
|
env.skip_cnt++;
|
|
|
|
env.test->skip_cnt = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-14 01:39:32 +00:00
|
|
|
static void stdio_restore(void);
|
|
|
|
|
|
|
|
/* A bunch of tests set custom affinity per-thread and/or per-process. Reset
|
|
|
|
* it after each test/sub-test.
|
|
|
|
*/
|
|
|
|
static void reset_affinity() {
|
|
|
|
|
|
|
|
cpu_set_t cpuset;
|
|
|
|
int i, err;
|
|
|
|
|
|
|
|
CPU_ZERO(&cpuset);
|
|
|
|
for (i = 0; i < env.nr_cpus; i++)
|
|
|
|
CPU_SET(i, &cpuset);
|
|
|
|
|
|
|
|
err = sched_setaffinity(0, sizeof(cpuset), &cpuset);
|
|
|
|
if (err < 0) {
|
|
|
|
stdio_restore();
|
|
|
|
fprintf(stderr, "Failed to reset process affinity: %d!\n", err);
|
2020-07-07 07:12:25 +00:00
|
|
|
exit(EXIT_ERR_SETUP_INFRA);
|
2020-03-14 01:39:32 +00:00
|
|
|
}
|
|
|
|
err = pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset);
|
|
|
|
if (err < 0) {
|
|
|
|
stdio_restore();
|
|
|
|
fprintf(stderr, "Failed to reset thread affinity: %d!\n", err);
|
2020-07-07 07:12:25 +00:00
|
|
|
exit(EXIT_ERR_SETUP_INFRA);
|
2020-03-14 01:39:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-02 00:48:58 +00:00
|
|
|
static void save_netns(void)
|
|
|
|
{
|
|
|
|
env.saved_netns_fd = open("/proc/self/ns/net", O_RDONLY);
|
|
|
|
if (env.saved_netns_fd == -1) {
|
|
|
|
perror("open(/proc/self/ns/net)");
|
2020-07-07 07:12:25 +00:00
|
|
|
exit(EXIT_ERR_SETUP_INFRA);
|
2020-07-02 00:48:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void restore_netns(void)
|
|
|
|
{
|
|
|
|
if (setns(env.saved_netns_fd, CLONE_NEWNET) == -1) {
|
|
|
|
stdio_restore();
|
|
|
|
perror("setns(CLONE_NEWNS)");
|
2020-07-07 07:12:25 +00:00
|
|
|
exit(EXIT_ERR_SETUP_INFRA);
|
2020-07-02 00:48:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
selftests/bpf: add sub-tests support for test_progs
Allow tests to have their own set of sub-tests. Also add ability to do
test/subtest selection using `-t <test-name>/<subtest-name>` and `-n
<test-nums-set>/<subtest-nums-set>`, as an extension of existing -t/-n
selector options. For the <test-num-set> format: it's a comma-separated
list of either individual test numbers (1-based), or range of test
numbers. E.g., all of the following are valid sets of test numbers:
- 10
- 1,2,3
- 1-3
- 5-10,1,3-4
'/<subtest' part is optional, but has the same format. E.g., to select
test #3 and its sub-tests #10 through #15, use: -t 3/10-15.
Similarly, to select tests by name, use `-t verif/strobe`:
$ sudo ./test_progs -t verif/strobe
#3/12 strobemeta.o:OK
#3/13 strobemeta_nounroll1.o:OK
#3/14 strobemeta_nounroll2.o:OK
#3 bpf_verif_scale:OK
Summary: 1/3 PASSED, 0 FAILED
Example of using subtest API is in the next patch, converting
bpf_verif_scale.c tests to use sub-tests.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-07-28 03:25:29 +00:00
|
|
|
void test__end_subtest()
|
|
|
|
{
|
|
|
|
struct prog_test_def *test = env.test;
|
2019-08-21 23:44:25 +00:00
|
|
|
int sub_error_cnt = test->error_cnt - test->old_error_cnt;
|
selftests/bpf: add sub-tests support for test_progs
Allow tests to have their own set of sub-tests. Also add ability to do
test/subtest selection using `-t <test-name>/<subtest-name>` and `-n
<test-nums-set>/<subtest-nums-set>`, as an extension of existing -t/-n
selector options. For the <test-num-set> format: it's a comma-separated
list of either individual test numbers (1-based), or range of test
numbers. E.g., all of the following are valid sets of test numbers:
- 10
- 1,2,3
- 1-3
- 5-10,1,3-4
'/<subtest' part is optional, but has the same format. E.g., to select
test #3 and its sub-tests #10 through #15, use: -t 3/10-15.
Similarly, to select tests by name, use `-t verif/strobe`:
$ sudo ./test_progs -t verif/strobe
#3/12 strobemeta.o:OK
#3/13 strobemeta_nounroll1.o:OK
#3/14 strobemeta_nounroll2.o:OK
#3 bpf_verif_scale:OK
Summary: 1/3 PASSED, 0 FAILED
Example of using subtest API is in the next patch, converting
bpf_verif_scale.c tests to use sub-tests.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-07-28 03:25:29 +00:00
|
|
|
|
|
|
|
if (sub_error_cnt)
|
|
|
|
env.fail_cnt++;
|
2020-12-03 20:46:27 +00:00
|
|
|
else if (test->skip_cnt == 0)
|
selftests/bpf: add sub-tests support for test_progs
Allow tests to have their own set of sub-tests. Also add ability to do
test/subtest selection using `-t <test-name>/<subtest-name>` and `-n
<test-nums-set>/<subtest-nums-set>`, as an extension of existing -t/-n
selector options. For the <test-num-set> format: it's a comma-separated
list of either individual test numbers (1-based), or range of test
numbers. E.g., all of the following are valid sets of test numbers:
- 10
- 1,2,3
- 1-3
- 5-10,1,3-4
'/<subtest' part is optional, but has the same format. E.g., to select
test #3 and its sub-tests #10 through #15, use: -t 3/10-15.
Similarly, to select tests by name, use `-t verif/strobe`:
$ sudo ./test_progs -t verif/strobe
#3/12 strobemeta.o:OK
#3/13 strobemeta_nounroll1.o:OK
#3/14 strobemeta_nounroll2.o:OK
#3 bpf_verif_scale:OK
Summary: 1/3 PASSED, 0 FAILED
Example of using subtest API is in the next patch, converting
bpf_verif_scale.c tests to use sub-tests.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-07-28 03:25:29 +00:00
|
|
|
env.sub_succ_cnt++;
|
2019-08-21 23:44:24 +00:00
|
|
|
skip_account();
|
selftests/bpf: add sub-tests support for test_progs
Allow tests to have their own set of sub-tests. Also add ability to do
test/subtest selection using `-t <test-name>/<subtest-name>` and `-n
<test-nums-set>/<subtest-nums-set>`, as an extension of existing -t/-n
selector options. For the <test-num-set> format: it's a comma-separated
list of either individual test numbers (1-based), or range of test
numbers. E.g., all of the following are valid sets of test numbers:
- 10
- 1,2,3
- 1-3
- 5-10,1,3-4
'/<subtest' part is optional, but has the same format. E.g., to select
test #3 and its sub-tests #10 through #15, use: -t 3/10-15.
Similarly, to select tests by name, use `-t verif/strobe`:
$ sudo ./test_progs -t verif/strobe
#3/12 strobemeta.o:OK
#3/13 strobemeta_nounroll1.o:OK
#3/14 strobemeta_nounroll2.o:OK
#3 bpf_verif_scale:OK
Summary: 1/3 PASSED, 0 FAILED
Example of using subtest API is in the next patch, converting
bpf_verif_scale.c tests to use sub-tests.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-07-28 03:25:29 +00:00
|
|
|
|
|
|
|
dump_test_log(test, sub_error_cnt);
|
|
|
|
|
2019-08-06 17:45:27 +00:00
|
|
|
fprintf(env.stdout, "#%d/%d %s:%s\n",
|
2020-12-03 20:46:27 +00:00
|
|
|
test->test_num, test->subtest_num, test->subtest_name,
|
|
|
|
sub_error_cnt ? "FAIL" : (test->skip_cnt ? "SKIP" : "OK"));
|
2019-10-21 03:39:00 +00:00
|
|
|
|
|
|
|
free(test->subtest_name);
|
|
|
|
test->subtest_name = NULL;
|
selftests/bpf: add sub-tests support for test_progs
Allow tests to have their own set of sub-tests. Also add ability to do
test/subtest selection using `-t <test-name>/<subtest-name>` and `-n
<test-nums-set>/<subtest-nums-set>`, as an extension of existing -t/-n
selector options. For the <test-num-set> format: it's a comma-separated
list of either individual test numbers (1-based), or range of test
numbers. E.g., all of the following are valid sets of test numbers:
- 10
- 1,2,3
- 1-3
- 5-10,1,3-4
'/<subtest' part is optional, but has the same format. E.g., to select
test #3 and its sub-tests #10 through #15, use: -t 3/10-15.
Similarly, to select tests by name, use `-t verif/strobe`:
$ sudo ./test_progs -t verif/strobe
#3/12 strobemeta.o:OK
#3/13 strobemeta_nounroll1.o:OK
#3/14 strobemeta_nounroll2.o:OK
#3 bpf_verif_scale:OK
Summary: 1/3 PASSED, 0 FAILED
Example of using subtest API is in the next patch, converting
bpf_verif_scale.c tests to use sub-tests.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-07-28 03:25:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool test__start_subtest(const char *name)
|
|
|
|
{
|
|
|
|
struct prog_test_def *test = env.test;
|
|
|
|
|
2019-10-21 03:39:00 +00:00
|
|
|
if (test->subtest_name)
|
selftests/bpf: add sub-tests support for test_progs
Allow tests to have their own set of sub-tests. Also add ability to do
test/subtest selection using `-t <test-name>/<subtest-name>` and `-n
<test-nums-set>/<subtest-nums-set>`, as an extension of existing -t/-n
selector options. For the <test-num-set> format: it's a comma-separated
list of either individual test numbers (1-based), or range of test
numbers. E.g., all of the following are valid sets of test numbers:
- 10
- 1,2,3
- 1-3
- 5-10,1,3-4
'/<subtest' part is optional, but has the same format. E.g., to select
test #3 and its sub-tests #10 through #15, use: -t 3/10-15.
Similarly, to select tests by name, use `-t verif/strobe`:
$ sudo ./test_progs -t verif/strobe
#3/12 strobemeta.o:OK
#3/13 strobemeta_nounroll1.o:OK
#3/14 strobemeta_nounroll2.o:OK
#3 bpf_verif_scale:OK
Summary: 1/3 PASSED, 0 FAILED
Example of using subtest API is in the next patch, converting
bpf_verif_scale.c tests to use sub-tests.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-07-28 03:25:29 +00:00
|
|
|
test__end_subtest();
|
|
|
|
|
|
|
|
test->subtest_num++;
|
|
|
|
|
|
|
|
if (!name || !name[0]) {
|
2019-08-06 17:45:27 +00:00
|
|
|
fprintf(env.stderr,
|
|
|
|
"Subtest #%d didn't provide sub-test name!\n",
|
selftests/bpf: add sub-tests support for test_progs
Allow tests to have their own set of sub-tests. Also add ability to do
test/subtest selection using `-t <test-name>/<subtest-name>` and `-n
<test-nums-set>/<subtest-nums-set>`, as an extension of existing -t/-n
selector options. For the <test-num-set> format: it's a comma-separated
list of either individual test numbers (1-based), or range of test
numbers. E.g., all of the following are valid sets of test numbers:
- 10
- 1,2,3
- 1-3
- 5-10,1,3-4
'/<subtest' part is optional, but has the same format. E.g., to select
test #3 and its sub-tests #10 through #15, use: -t 3/10-15.
Similarly, to select tests by name, use `-t verif/strobe`:
$ sudo ./test_progs -t verif/strobe
#3/12 strobemeta.o:OK
#3/13 strobemeta_nounroll1.o:OK
#3/14 strobemeta_nounroll2.o:OK
#3 bpf_verif_scale:OK
Summary: 1/3 PASSED, 0 FAILED
Example of using subtest API is in the next patch, converting
bpf_verif_scale.c tests to use sub-tests.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-07-28 03:25:29 +00:00
|
|
|
test->subtest_num);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!should_run(&env.subtest_selector, test->subtest_num, name))
|
|
|
|
return false;
|
|
|
|
|
2019-10-21 03:39:00 +00:00
|
|
|
test->subtest_name = strdup(name);
|
|
|
|
if (!test->subtest_name) {
|
|
|
|
fprintf(env.stderr,
|
|
|
|
"Subtest #%d: failed to copy subtest name!\n",
|
|
|
|
test->subtest_num);
|
|
|
|
return false;
|
|
|
|
}
|
2019-08-21 23:44:25 +00:00
|
|
|
env.test->old_error_cnt = env.test->error_cnt;
|
selftests/bpf: add sub-tests support for test_progs
Allow tests to have their own set of sub-tests. Also add ability to do
test/subtest selection using `-t <test-name>/<subtest-name>` and `-n
<test-nums-set>/<subtest-nums-set>`, as an extension of existing -t/-n
selector options. For the <test-num-set> format: it's a comma-separated
list of either individual test numbers (1-based), or range of test
numbers. E.g., all of the following are valid sets of test numbers:
- 10
- 1,2,3
- 1-3
- 5-10,1,3-4
'/<subtest' part is optional, but has the same format. E.g., to select
test #3 and its sub-tests #10 through #15, use: -t 3/10-15.
Similarly, to select tests by name, use `-t verif/strobe`:
$ sudo ./test_progs -t verif/strobe
#3/12 strobemeta.o:OK
#3/13 strobemeta_nounroll1.o:OK
#3/14 strobemeta_nounroll2.o:OK
#3 bpf_verif_scale:OK
Summary: 1/3 PASSED, 0 FAILED
Example of using subtest API is in the next patch, converting
bpf_verif_scale.c tests to use sub-tests.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-07-28 03:25:29 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-07-28 03:25:28 +00:00
|
|
|
void test__force_log() {
|
|
|
|
env.test->force_log = true;
|
|
|
|
}
|
|
|
|
|
2019-08-21 23:44:24 +00:00
|
|
|
void test__skip(void)
|
|
|
|
{
|
|
|
|
env.test->skip_cnt++;
|
|
|
|
}
|
|
|
|
|
2019-08-21 23:44:25 +00:00
|
|
|
void test__fail(void)
|
|
|
|
{
|
|
|
|
env.test->error_cnt++;
|
|
|
|
}
|
|
|
|
|
2019-09-04 16:25:04 +00:00
|
|
|
int test__join_cgroup(const char *path)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
if (!env.test->need_cgroup_cleanup) {
|
|
|
|
if (setup_cgroup_environment()) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"#%d %s: Failed to setup cgroup environment\n",
|
|
|
|
env.test->test_num, env.test->test_name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
env.test->need_cgroup_cleanup = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
fd = create_and_get_cgroup(path);
|
|
|
|
if (fd < 0) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"#%d %s: Failed to create cgroup '%s' (errno=%d)\n",
|
|
|
|
env.test->test_num, env.test->test_name, path, errno);
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (join_cgroup(path)) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"#%d %s: Failed to join cgroup '%s' (errno=%d)\n",
|
|
|
|
env.test->test_num, env.test->test_name, path, errno);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
2019-03-02 03:42:13 +00:00
|
|
|
int bpf_find_map(const char *test, struct bpf_object *obj, const char *name)
|
2017-03-31 04:45:42 +00:00
|
|
|
{
|
|
|
|
struct bpf_map *map;
|
|
|
|
|
|
|
|
map = bpf_object__find_map_by_name(obj, name);
|
|
|
|
if (!map) {
|
2020-03-13 17:23:33 +00:00
|
|
|
fprintf(stdout, "%s:FAIL:map '%s' not found\n", test, name);
|
2019-08-21 23:44:25 +00:00
|
|
|
test__fail();
|
2017-03-31 04:45:42 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return bpf_map__fd(map);
|
|
|
|
}
|
|
|
|
|
2018-04-29 05:28:15 +00:00
|
|
|
static bool is_jit_enabled(void)
|
|
|
|
{
|
|
|
|
const char *jit_sysctl = "/proc/sys/net/core/bpf_jit_enable";
|
|
|
|
bool enabled = false;
|
|
|
|
int sysctl_fd;
|
|
|
|
|
|
|
|
sysctl_fd = open(jit_sysctl, 0, O_RDONLY);
|
|
|
|
if (sysctl_fd != -1) {
|
|
|
|
char tmpc;
|
|
|
|
|
|
|
|
if (read(sysctl_fd, &tmpc, sizeof(tmpc)) == 1)
|
|
|
|
enabled = (tmpc != '0');
|
|
|
|
close(sysctl_fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
return enabled;
|
|
|
|
}
|
|
|
|
|
2019-03-02 03:42:16 +00:00
|
|
|
int compare_map_keys(int map1_fd, int map2_fd)
|
2018-01-04 21:55:04 +00:00
|
|
|
{
|
|
|
|
__u32 key, next_key;
|
2018-03-14 17:23:22 +00:00
|
|
|
char val_buf[PERF_MAX_STACK_DEPTH *
|
|
|
|
sizeof(struct bpf_stack_build_id)];
|
2018-01-04 21:55:04 +00:00
|
|
|
int err;
|
|
|
|
|
|
|
|
err = bpf_map_get_next_key(map1_fd, NULL, &key);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
err = bpf_map_lookup_elem(map2_fd, &key, val_buf);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
while (bpf_map_get_next_key(map1_fd, &key, &next_key) == 0) {
|
|
|
|
err = bpf_map_lookup_elem(map2_fd, &next_key, val_buf);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
key = next_key;
|
|
|
|
}
|
|
|
|
if (errno != ENOENT)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-03-02 03:42:16 +00:00
|
|
|
int compare_stack_ips(int smap_fd, int amap_fd, int stack_trace_len)
|
2018-04-29 05:28:16 +00:00
|
|
|
{
|
|
|
|
__u32 key, next_key, *cur_key_p, *next_key_p;
|
|
|
|
char *val_buf1, *val_buf2;
|
|
|
|
int i, err = 0;
|
|
|
|
|
|
|
|
val_buf1 = malloc(stack_trace_len);
|
|
|
|
val_buf2 = malloc(stack_trace_len);
|
|
|
|
cur_key_p = NULL;
|
|
|
|
next_key_p = &key;
|
|
|
|
while (bpf_map_get_next_key(smap_fd, cur_key_p, next_key_p) == 0) {
|
|
|
|
err = bpf_map_lookup_elem(smap_fd, next_key_p, val_buf1);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
err = bpf_map_lookup_elem(amap_fd, next_key_p, val_buf2);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
for (i = 0; i < stack_trace_len; i++) {
|
|
|
|
if (val_buf1[i] != val_buf2[i]) {
|
|
|
|
err = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
key = *next_key_p;
|
|
|
|
cur_key_p = &key;
|
|
|
|
next_key_p = &next_key;
|
|
|
|
}
|
|
|
|
if (errno != ENOENT)
|
|
|
|
err = -1;
|
|
|
|
|
|
|
|
out:
|
|
|
|
free(val_buf1);
|
|
|
|
free(val_buf2);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2019-03-02 03:42:16 +00:00
|
|
|
int extract_build_id(char *build_id, size_t size)
|
2018-03-14 17:23:22 +00:00
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
char *line = NULL;
|
|
|
|
size_t len = 0;
|
|
|
|
|
|
|
|
fp = popen("readelf -n ./urandom_read | grep 'Build ID'", "r");
|
|
|
|
if (fp == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (getline(&line, &len, fp) == -1)
|
|
|
|
goto err;
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
if (len > size)
|
|
|
|
len = size;
|
|
|
|
memcpy(build_id, line, len);
|
|
|
|
build_id[len] = '\0';
|
2020-04-29 01:21:06 +00:00
|
|
|
free(line);
|
2018-03-14 17:23:22 +00:00
|
|
|
return 0;
|
|
|
|
err:
|
|
|
|
fclose(fp);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-12-03 20:46:26 +00:00
|
|
|
static int finit_module(int fd, const char *param_values, int flags)
|
|
|
|
{
|
|
|
|
return syscall(__NR_finit_module, fd, param_values, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int delete_module(const char *name, int flags)
|
|
|
|
{
|
|
|
|
return syscall(__NR_delete_module, name, flags);
|
|
|
|
}
|
|
|
|
|
2021-01-12 07:55:17 +00:00
|
|
|
/*
|
|
|
|
* Trigger synchronize_rcu() in kernel.
|
|
|
|
*/
|
|
|
|
int kern_sync_rcu(void)
|
|
|
|
{
|
|
|
|
return syscall(__NR_membarrier, MEMBARRIER_CMD_SHARED, 0, 0);
|
|
|
|
}
|
|
|
|
|
2020-12-03 20:46:26 +00:00
|
|
|
static void unload_bpf_testmod(void)
|
|
|
|
{
|
2021-01-12 07:55:17 +00:00
|
|
|
if (kern_sync_rcu())
|
|
|
|
fprintf(env.stderr, "Failed to trigger kernel-side RCU sync!\n");
|
2020-12-03 20:46:26 +00:00
|
|
|
if (delete_module("bpf_testmod", 0)) {
|
|
|
|
if (errno == ENOENT) {
|
|
|
|
if (env.verbosity > VERBOSE_NONE)
|
|
|
|
fprintf(stdout, "bpf_testmod.ko is already unloaded.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fprintf(env.stderr, "Failed to unload bpf_testmod.ko from kernel: %d\n", -errno);
|
2021-01-26 06:50:18 +00:00
|
|
|
return;
|
2020-12-03 20:46:26 +00:00
|
|
|
}
|
|
|
|
if (env.verbosity > VERBOSE_NONE)
|
|
|
|
fprintf(stdout, "Successfully unloaded bpf_testmod.ko.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static int load_bpf_testmod(void)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
/* ensure previous instance of the module is unloaded */
|
|
|
|
unload_bpf_testmod();
|
|
|
|
|
|
|
|
if (env.verbosity > VERBOSE_NONE)
|
|
|
|
fprintf(stdout, "Loading bpf_testmod.ko...\n");
|
|
|
|
|
|
|
|
fd = open("bpf_testmod.ko", O_RDONLY);
|
|
|
|
if (fd < 0) {
|
|
|
|
fprintf(env.stderr, "Can't find bpf_testmod.ko kernel module: %d\n", -errno);
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
if (finit_module(fd, "", 0)) {
|
|
|
|
fprintf(env.stderr, "Failed to load bpf_testmod.ko into the kernel: %d\n", -errno);
|
|
|
|
close(fd);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
if (env.verbosity > VERBOSE_NONE)
|
|
|
|
fprintf(stdout, "Successfully loaded bpf_testmod.ko.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-07-28 03:25:24 +00:00
|
|
|
/* extern declarations for test funcs */
|
2019-10-16 06:00:45 +00:00
|
|
|
#define DEFINE_TEST(name) extern void test_##name(void);
|
2019-03-02 03:42:13 +00:00
|
|
|
#include <prog_tests/tests.h>
|
2019-07-28 03:25:24 +00:00
|
|
|
#undef DEFINE_TEST
|
2019-03-02 03:42:13 +00:00
|
|
|
|
2019-07-28 03:25:24 +00:00
|
|
|
static struct prog_test_def prog_test_defs[] = {
|
2019-07-28 03:25:28 +00:00
|
|
|
#define DEFINE_TEST(name) { \
|
|
|
|
.test_name = #name, \
|
|
|
|
.run_test = &test_##name, \
|
2019-07-28 03:25:24 +00:00
|
|
|
},
|
|
|
|
#include <prog_tests/tests.h>
|
|
|
|
#undef DEFINE_TEST
|
|
|
|
};
|
2019-07-28 03:25:28 +00:00
|
|
|
const int prog_test_cnt = ARRAY_SIZE(prog_test_defs);
|
2019-07-28 03:25:24 +00:00
|
|
|
|
|
|
|
const char *argp_program_version = "test_progs 0.1";
|
|
|
|
const char *argp_program_bug_address = "<bpf@vger.kernel.org>";
|
|
|
|
const char argp_program_doc[] = "BPF selftests test runner";
|
|
|
|
|
|
|
|
enum ARG_KEYS {
|
2019-07-28 03:25:25 +00:00
|
|
|
ARG_TEST_NUM = 'n',
|
|
|
|
ARG_TEST_NAME = 't',
|
selftests/bpf: Add whitelist/blacklist of test names to test_progs
Add ability to specify a list of test name substrings for selecting which
tests to run. So now -t is accepting a comma-separated list of strings,
similarly to how -n accepts a comma-separated list of test numbers.
Additionally, add ability to blacklist tests by name. Blacklist takes
precedence over whitelist. Blacklisting is important for cases where it's
known that some tests can't pass (e.g., due to perf hardware events that are
not available within VM). This is going to be used for libbpf testing in
Travis CI in its Github repo.
Example runs with just whitelist and whitelist + blacklist:
$ sudo ./test_progs -tattach,core/existence
#1 attach_probe:OK
#6 cgroup_attach_autodetach:OK
#7 cgroup_attach_multi:OK
#8 cgroup_attach_override:OK
#9 core_extern:OK
#10/44 existence:OK
#10/45 existence___minimal:OK
#10/46 existence__err_int_sz:OK
#10/47 existence__err_int_type:OK
#10/48 existence__err_int_kind:OK
#10/49 existence__err_arr_kind:OK
#10/50 existence__err_arr_value_type:OK
#10/51 existence__err_struct_type:OK
#10 core_reloc:OK
#19 flow_dissector_reattach:OK
#60 tp_attach_query:OK
Summary: 8/8 PASSED, 0 SKIPPED, 0 FAILED
$ sudo ./test_progs -tattach,core/existence -bcgroup,flow/arr
#1 attach_probe:OK
#9 core_extern:OK
#10/44 existence:OK
#10/45 existence___minimal:OK
#10/46 existence__err_int_sz:OK
#10/47 existence__err_int_type:OK
#10/48 existence__err_int_kind:OK
#10/51 existence__err_struct_type:OK
#10 core_reloc:OK
#60 tp_attach_query:OK
Summary: 4/6 PASSED, 0 SKIPPED, 0 FAILED
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Cc: Julia Kartseva <hex@fb.com>
Link: https://lore.kernel.org/bpf/20200116005549.3644118-1-andriin@fb.com
2020-01-16 00:55:49 +00:00
|
|
|
ARG_TEST_NAME_BLACKLIST = 'b',
|
2019-07-28 03:25:24 +00:00
|
|
|
ARG_VERIFIER_STATS = 's',
|
2019-07-28 03:25:27 +00:00
|
|
|
ARG_VERBOSE = 'v',
|
2020-07-01 21:44:12 +00:00
|
|
|
ARG_GET_TEST_CNT = 'c',
|
2020-07-01 21:44:17 +00:00
|
|
|
ARG_LIST_TEST_NAMES = 'l',
|
2019-07-28 03:25:24 +00:00
|
|
|
};
|
2019-08-06 17:45:29 +00:00
|
|
|
|
2019-07-28 03:25:24 +00:00
|
|
|
static const struct argp_option opts[] = {
|
2019-07-28 03:25:25 +00:00
|
|
|
{ "num", ARG_TEST_NUM, "NUM", 0,
|
|
|
|
"Run test number NUM only " },
|
selftests/bpf: Add whitelist/blacklist of test names to test_progs
Add ability to specify a list of test name substrings for selecting which
tests to run. So now -t is accepting a comma-separated list of strings,
similarly to how -n accepts a comma-separated list of test numbers.
Additionally, add ability to blacklist tests by name. Blacklist takes
precedence over whitelist. Blacklisting is important for cases where it's
known that some tests can't pass (e.g., due to perf hardware events that are
not available within VM). This is going to be used for libbpf testing in
Travis CI in its Github repo.
Example runs with just whitelist and whitelist + blacklist:
$ sudo ./test_progs -tattach,core/existence
#1 attach_probe:OK
#6 cgroup_attach_autodetach:OK
#7 cgroup_attach_multi:OK
#8 cgroup_attach_override:OK
#9 core_extern:OK
#10/44 existence:OK
#10/45 existence___minimal:OK
#10/46 existence__err_int_sz:OK
#10/47 existence__err_int_type:OK
#10/48 existence__err_int_kind:OK
#10/49 existence__err_arr_kind:OK
#10/50 existence__err_arr_value_type:OK
#10/51 existence__err_struct_type:OK
#10 core_reloc:OK
#19 flow_dissector_reattach:OK
#60 tp_attach_query:OK
Summary: 8/8 PASSED, 0 SKIPPED, 0 FAILED
$ sudo ./test_progs -tattach,core/existence -bcgroup,flow/arr
#1 attach_probe:OK
#9 core_extern:OK
#10/44 existence:OK
#10/45 existence___minimal:OK
#10/46 existence__err_int_sz:OK
#10/47 existence__err_int_type:OK
#10/48 existence__err_int_kind:OK
#10/51 existence__err_struct_type:OK
#10 core_reloc:OK
#60 tp_attach_query:OK
Summary: 4/6 PASSED, 0 SKIPPED, 0 FAILED
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Cc: Julia Kartseva <hex@fb.com>
Link: https://lore.kernel.org/bpf/20200116005549.3644118-1-andriin@fb.com
2020-01-16 00:55:49 +00:00
|
|
|
{ "name", ARG_TEST_NAME, "NAMES", 0,
|
|
|
|
"Run tests with names containing any string from NAMES list" },
|
|
|
|
{ "name-blacklist", ARG_TEST_NAME_BLACKLIST, "NAMES", 0,
|
|
|
|
"Don't run tests with names containing any string from NAMES list" },
|
2019-07-28 03:25:24 +00:00
|
|
|
{ "verifier-stats", ARG_VERIFIER_STATS, NULL, 0,
|
|
|
|
"Output verifier statistics", },
|
2019-07-28 03:25:27 +00:00
|
|
|
{ "verbose", ARG_VERBOSE, "LEVEL", OPTION_ARG_OPTIONAL,
|
2019-11-20 00:35:48 +00:00
|
|
|
"Verbose output (use -vv or -vvv for progressively verbose output)" },
|
2020-07-01 21:44:12 +00:00
|
|
|
{ "count", ARG_GET_TEST_CNT, NULL, 0,
|
|
|
|
"Get number of selected top-level tests " },
|
2020-07-01 21:44:17 +00:00
|
|
|
{ "list", ARG_LIST_TEST_NAMES, NULL, 0,
|
|
|
|
"List test names that would run (without running them) " },
|
2019-07-28 03:25:24 +00:00
|
|
|
{},
|
|
|
|
};
|
|
|
|
|
2019-07-28 03:25:27 +00:00
|
|
|
static int libbpf_print_fn(enum libbpf_print_level level,
|
|
|
|
const char *format, va_list args)
|
|
|
|
{
|
2019-11-20 00:35:48 +00:00
|
|
|
if (env.verbosity < VERBOSE_VERY && level == LIBBPF_DEBUG)
|
2019-07-28 03:25:27 +00:00
|
|
|
return 0;
|
2020-03-13 17:23:33 +00:00
|
|
|
vfprintf(stdout, format, args);
|
2019-07-28 03:25:28 +00:00
|
|
|
return 0;
|
2019-07-28 03:25:27 +00:00
|
|
|
}
|
|
|
|
|
2020-04-29 01:21:05 +00:00
|
|
|
static void free_str_set(const struct str_set *set)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!set)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < set->cnt; i++)
|
|
|
|
free((void *)set->strs[i]);
|
|
|
|
free(set->strs);
|
|
|
|
}
|
|
|
|
|
selftests/bpf: Add whitelist/blacklist of test names to test_progs
Add ability to specify a list of test name substrings for selecting which
tests to run. So now -t is accepting a comma-separated list of strings,
similarly to how -n accepts a comma-separated list of test numbers.
Additionally, add ability to blacklist tests by name. Blacklist takes
precedence over whitelist. Blacklisting is important for cases where it's
known that some tests can't pass (e.g., due to perf hardware events that are
not available within VM). This is going to be used for libbpf testing in
Travis CI in its Github repo.
Example runs with just whitelist and whitelist + blacklist:
$ sudo ./test_progs -tattach,core/existence
#1 attach_probe:OK
#6 cgroup_attach_autodetach:OK
#7 cgroup_attach_multi:OK
#8 cgroup_attach_override:OK
#9 core_extern:OK
#10/44 existence:OK
#10/45 existence___minimal:OK
#10/46 existence__err_int_sz:OK
#10/47 existence__err_int_type:OK
#10/48 existence__err_int_kind:OK
#10/49 existence__err_arr_kind:OK
#10/50 existence__err_arr_value_type:OK
#10/51 existence__err_struct_type:OK
#10 core_reloc:OK
#19 flow_dissector_reattach:OK
#60 tp_attach_query:OK
Summary: 8/8 PASSED, 0 SKIPPED, 0 FAILED
$ sudo ./test_progs -tattach,core/existence -bcgroup,flow/arr
#1 attach_probe:OK
#9 core_extern:OK
#10/44 existence:OK
#10/45 existence___minimal:OK
#10/46 existence__err_int_sz:OK
#10/47 existence__err_int_type:OK
#10/48 existence__err_int_kind:OK
#10/51 existence__err_struct_type:OK
#10 core_reloc:OK
#60 tp_attach_query:OK
Summary: 4/6 PASSED, 0 SKIPPED, 0 FAILED
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Cc: Julia Kartseva <hex@fb.com>
Link: https://lore.kernel.org/bpf/20200116005549.3644118-1-andriin@fb.com
2020-01-16 00:55:49 +00:00
|
|
|
static int parse_str_list(const char *s, struct str_set *set)
|
|
|
|
{
|
|
|
|
char *input, *state = NULL, *next, **tmp, **strs = NULL;
|
|
|
|
int cnt = 0;
|
|
|
|
|
|
|
|
input = strdup(s);
|
|
|
|
if (!input)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
set->cnt = 0;
|
|
|
|
set->strs = NULL;
|
|
|
|
|
|
|
|
while ((next = strtok_r(state ? NULL : input, ",", &state))) {
|
|
|
|
tmp = realloc(strs, sizeof(*strs) * (cnt + 1));
|
|
|
|
if (!tmp)
|
|
|
|
goto err;
|
|
|
|
strs = tmp;
|
|
|
|
|
|
|
|
strs[cnt] = strdup(next);
|
|
|
|
if (!strs[cnt])
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
cnt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
set->cnt = cnt;
|
|
|
|
set->strs = (const char **)strs;
|
|
|
|
free(input);
|
|
|
|
return 0;
|
|
|
|
err:
|
|
|
|
free(strs);
|
|
|
|
free(input);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2019-11-20 00:35:48 +00:00
|
|
|
extern int extra_prog_load_log_flags;
|
|
|
|
|
2019-07-28 03:25:24 +00:00
|
|
|
static error_t parse_arg(int key, char *arg, struct argp_state *state)
|
2017-03-31 04:45:41 +00:00
|
|
|
{
|
2019-07-28 03:25:24 +00:00
|
|
|
struct test_env *env = state->input;
|
|
|
|
|
|
|
|
switch (key) {
|
2019-07-28 03:25:25 +00:00
|
|
|
case ARG_TEST_NUM: {
|
selftests/bpf: add sub-tests support for test_progs
Allow tests to have their own set of sub-tests. Also add ability to do
test/subtest selection using `-t <test-name>/<subtest-name>` and `-n
<test-nums-set>/<subtest-nums-set>`, as an extension of existing -t/-n
selector options. For the <test-num-set> format: it's a comma-separated
list of either individual test numbers (1-based), or range of test
numbers. E.g., all of the following are valid sets of test numbers:
- 10
- 1,2,3
- 1-3
- 5-10,1,3-4
'/<subtest' part is optional, but has the same format. E.g., to select
test #3 and its sub-tests #10 through #15, use: -t 3/10-15.
Similarly, to select tests by name, use `-t verif/strobe`:
$ sudo ./test_progs -t verif/strobe
#3/12 strobemeta.o:OK
#3/13 strobemeta_nounroll1.o:OK
#3/14 strobemeta_nounroll2.o:OK
#3 bpf_verif_scale:OK
Summary: 1/3 PASSED, 0 FAILED
Example of using subtest API is in the next patch, converting
bpf_verif_scale.c tests to use sub-tests.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-07-28 03:25:29 +00:00
|
|
|
char *subtest_str = strchr(arg, '/');
|
2019-07-28 03:25:25 +00:00
|
|
|
|
selftests/bpf: add sub-tests support for test_progs
Allow tests to have their own set of sub-tests. Also add ability to do
test/subtest selection using `-t <test-name>/<subtest-name>` and `-n
<test-nums-set>/<subtest-nums-set>`, as an extension of existing -t/-n
selector options. For the <test-num-set> format: it's a comma-separated
list of either individual test numbers (1-based), or range of test
numbers. E.g., all of the following are valid sets of test numbers:
- 10
- 1,2,3
- 1-3
- 5-10,1,3-4
'/<subtest' part is optional, but has the same format. E.g., to select
test #3 and its sub-tests #10 through #15, use: -t 3/10-15.
Similarly, to select tests by name, use `-t verif/strobe`:
$ sudo ./test_progs -t verif/strobe
#3/12 strobemeta.o:OK
#3/13 strobemeta_nounroll1.o:OK
#3/14 strobemeta_nounroll2.o:OK
#3 bpf_verif_scale:OK
Summary: 1/3 PASSED, 0 FAILED
Example of using subtest API is in the next patch, converting
bpf_verif_scale.c tests to use sub-tests.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-07-28 03:25:29 +00:00
|
|
|
if (subtest_str) {
|
|
|
|
*subtest_str = '\0';
|
|
|
|
if (parse_num_list(subtest_str + 1,
|
2020-05-12 19:24:42 +00:00
|
|
|
&env->subtest_selector.num_set,
|
|
|
|
&env->subtest_selector.num_set_len)) {
|
selftests/bpf: add sub-tests support for test_progs
Allow tests to have their own set of sub-tests. Also add ability to do
test/subtest selection using `-t <test-name>/<subtest-name>` and `-n
<test-nums-set>/<subtest-nums-set>`, as an extension of existing -t/-n
selector options. For the <test-num-set> format: it's a comma-separated
list of either individual test numbers (1-based), or range of test
numbers. E.g., all of the following are valid sets of test numbers:
- 10
- 1,2,3
- 1-3
- 5-10,1,3-4
'/<subtest' part is optional, but has the same format. E.g., to select
test #3 and its sub-tests #10 through #15, use: -t 3/10-15.
Similarly, to select tests by name, use `-t verif/strobe`:
$ sudo ./test_progs -t verif/strobe
#3/12 strobemeta.o:OK
#3/13 strobemeta_nounroll1.o:OK
#3/14 strobemeta_nounroll2.o:OK
#3 bpf_verif_scale:OK
Summary: 1/3 PASSED, 0 FAILED
Example of using subtest API is in the next patch, converting
bpf_verif_scale.c tests to use sub-tests.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-07-28 03:25:29 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"Failed to parse subtest numbers.\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
2020-05-12 19:24:42 +00:00
|
|
|
if (parse_num_list(arg, &env->test_selector.num_set,
|
|
|
|
&env->test_selector.num_set_len)) {
|
selftests/bpf: add sub-tests support for test_progs
Allow tests to have their own set of sub-tests. Also add ability to do
test/subtest selection using `-t <test-name>/<subtest-name>` and `-n
<test-nums-set>/<subtest-nums-set>`, as an extension of existing -t/-n
selector options. For the <test-num-set> format: it's a comma-separated
list of either individual test numbers (1-based), or range of test
numbers. E.g., all of the following are valid sets of test numbers:
- 10
- 1,2,3
- 1-3
- 5-10,1,3-4
'/<subtest' part is optional, but has the same format. E.g., to select
test #3 and its sub-tests #10 through #15, use: -t 3/10-15.
Similarly, to select tests by name, use `-t verif/strobe`:
$ sudo ./test_progs -t verif/strobe
#3/12 strobemeta.o:OK
#3/13 strobemeta_nounroll1.o:OK
#3/14 strobemeta_nounroll2.o:OK
#3 bpf_verif_scale:OK
Summary: 1/3 PASSED, 0 FAILED
Example of using subtest API is in the next patch, converting
bpf_verif_scale.c tests to use sub-tests.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-07-28 03:25:29 +00:00
|
|
|
fprintf(stderr, "Failed to parse test numbers.\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2019-07-28 03:25:25 +00:00
|
|
|
break;
|
|
|
|
}
|
selftests/bpf: add sub-tests support for test_progs
Allow tests to have their own set of sub-tests. Also add ability to do
test/subtest selection using `-t <test-name>/<subtest-name>` and `-n
<test-nums-set>/<subtest-nums-set>`, as an extension of existing -t/-n
selector options. For the <test-num-set> format: it's a comma-separated
list of either individual test numbers (1-based), or range of test
numbers. E.g., all of the following are valid sets of test numbers:
- 10
- 1,2,3
- 1-3
- 5-10,1,3-4
'/<subtest' part is optional, but has the same format. E.g., to select
test #3 and its sub-tests #10 through #15, use: -t 3/10-15.
Similarly, to select tests by name, use `-t verif/strobe`:
$ sudo ./test_progs -t verif/strobe
#3/12 strobemeta.o:OK
#3/13 strobemeta_nounroll1.o:OK
#3/14 strobemeta_nounroll2.o:OK
#3 bpf_verif_scale:OK
Summary: 1/3 PASSED, 0 FAILED
Example of using subtest API is in the next patch, converting
bpf_verif_scale.c tests to use sub-tests.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-07-28 03:25:29 +00:00
|
|
|
case ARG_TEST_NAME: {
|
|
|
|
char *subtest_str = strchr(arg, '/');
|
|
|
|
|
|
|
|
if (subtest_str) {
|
|
|
|
*subtest_str = '\0';
|
selftests/bpf: Add whitelist/blacklist of test names to test_progs
Add ability to specify a list of test name substrings for selecting which
tests to run. So now -t is accepting a comma-separated list of strings,
similarly to how -n accepts a comma-separated list of test numbers.
Additionally, add ability to blacklist tests by name. Blacklist takes
precedence over whitelist. Blacklisting is important for cases where it's
known that some tests can't pass (e.g., due to perf hardware events that are
not available within VM). This is going to be used for libbpf testing in
Travis CI in its Github repo.
Example runs with just whitelist and whitelist + blacklist:
$ sudo ./test_progs -tattach,core/existence
#1 attach_probe:OK
#6 cgroup_attach_autodetach:OK
#7 cgroup_attach_multi:OK
#8 cgroup_attach_override:OK
#9 core_extern:OK
#10/44 existence:OK
#10/45 existence___minimal:OK
#10/46 existence__err_int_sz:OK
#10/47 existence__err_int_type:OK
#10/48 existence__err_int_kind:OK
#10/49 existence__err_arr_kind:OK
#10/50 existence__err_arr_value_type:OK
#10/51 existence__err_struct_type:OK
#10 core_reloc:OK
#19 flow_dissector_reattach:OK
#60 tp_attach_query:OK
Summary: 8/8 PASSED, 0 SKIPPED, 0 FAILED
$ sudo ./test_progs -tattach,core/existence -bcgroup,flow/arr
#1 attach_probe:OK
#9 core_extern:OK
#10/44 existence:OK
#10/45 existence___minimal:OK
#10/46 existence__err_int_sz:OK
#10/47 existence__err_int_type:OK
#10/48 existence__err_int_kind:OK
#10/51 existence__err_struct_type:OK
#10 core_reloc:OK
#60 tp_attach_query:OK
Summary: 4/6 PASSED, 0 SKIPPED, 0 FAILED
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Cc: Julia Kartseva <hex@fb.com>
Link: https://lore.kernel.org/bpf/20200116005549.3644118-1-andriin@fb.com
2020-01-16 00:55:49 +00:00
|
|
|
if (parse_str_list(subtest_str + 1,
|
|
|
|
&env->subtest_selector.whitelist))
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
if (parse_str_list(arg, &env->test_selector.whitelist))
|
|
|
|
return -ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ARG_TEST_NAME_BLACKLIST: {
|
|
|
|
char *subtest_str = strchr(arg, '/');
|
|
|
|
|
|
|
|
if (subtest_str) {
|
|
|
|
*subtest_str = '\0';
|
|
|
|
if (parse_str_list(subtest_str + 1,
|
|
|
|
&env->subtest_selector.blacklist))
|
selftests/bpf: add sub-tests support for test_progs
Allow tests to have their own set of sub-tests. Also add ability to do
test/subtest selection using `-t <test-name>/<subtest-name>` and `-n
<test-nums-set>/<subtest-nums-set>`, as an extension of existing -t/-n
selector options. For the <test-num-set> format: it's a comma-separated
list of either individual test numbers (1-based), or range of test
numbers. E.g., all of the following are valid sets of test numbers:
- 10
- 1,2,3
- 1-3
- 5-10,1,3-4
'/<subtest' part is optional, but has the same format. E.g., to select
test #3 and its sub-tests #10 through #15, use: -t 3/10-15.
Similarly, to select tests by name, use `-t verif/strobe`:
$ sudo ./test_progs -t verif/strobe
#3/12 strobemeta.o:OK
#3/13 strobemeta_nounroll1.o:OK
#3/14 strobemeta_nounroll2.o:OK
#3 bpf_verif_scale:OK
Summary: 1/3 PASSED, 0 FAILED
Example of using subtest API is in the next patch, converting
bpf_verif_scale.c tests to use sub-tests.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-07-28 03:25:29 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
selftests/bpf: Add whitelist/blacklist of test names to test_progs
Add ability to specify a list of test name substrings for selecting which
tests to run. So now -t is accepting a comma-separated list of strings,
similarly to how -n accepts a comma-separated list of test numbers.
Additionally, add ability to blacklist tests by name. Blacklist takes
precedence over whitelist. Blacklisting is important for cases where it's
known that some tests can't pass (e.g., due to perf hardware events that are
not available within VM). This is going to be used for libbpf testing in
Travis CI in its Github repo.
Example runs with just whitelist and whitelist + blacklist:
$ sudo ./test_progs -tattach,core/existence
#1 attach_probe:OK
#6 cgroup_attach_autodetach:OK
#7 cgroup_attach_multi:OK
#8 cgroup_attach_override:OK
#9 core_extern:OK
#10/44 existence:OK
#10/45 existence___minimal:OK
#10/46 existence__err_int_sz:OK
#10/47 existence__err_int_type:OK
#10/48 existence__err_int_kind:OK
#10/49 existence__err_arr_kind:OK
#10/50 existence__err_arr_value_type:OK
#10/51 existence__err_struct_type:OK
#10 core_reloc:OK
#19 flow_dissector_reattach:OK
#60 tp_attach_query:OK
Summary: 8/8 PASSED, 0 SKIPPED, 0 FAILED
$ sudo ./test_progs -tattach,core/existence -bcgroup,flow/arr
#1 attach_probe:OK
#9 core_extern:OK
#10/44 existence:OK
#10/45 existence___minimal:OK
#10/46 existence__err_int_sz:OK
#10/47 existence__err_int_type:OK
#10/48 existence__err_int_kind:OK
#10/51 existence__err_struct_type:OK
#10 core_reloc:OK
#60 tp_attach_query:OK
Summary: 4/6 PASSED, 0 SKIPPED, 0 FAILED
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Cc: Julia Kartseva <hex@fb.com>
Link: https://lore.kernel.org/bpf/20200116005549.3644118-1-andriin@fb.com
2020-01-16 00:55:49 +00:00
|
|
|
if (parse_str_list(arg, &env->test_selector.blacklist))
|
selftests/bpf: add sub-tests support for test_progs
Allow tests to have their own set of sub-tests. Also add ability to do
test/subtest selection using `-t <test-name>/<subtest-name>` and `-n
<test-nums-set>/<subtest-nums-set>`, as an extension of existing -t/-n
selector options. For the <test-num-set> format: it's a comma-separated
list of either individual test numbers (1-based), or range of test
numbers. E.g., all of the following are valid sets of test numbers:
- 10
- 1,2,3
- 1-3
- 5-10,1,3-4
'/<subtest' part is optional, but has the same format. E.g., to select
test #3 and its sub-tests #10 through #15, use: -t 3/10-15.
Similarly, to select tests by name, use `-t verif/strobe`:
$ sudo ./test_progs -t verif/strobe
#3/12 strobemeta.o:OK
#3/13 strobemeta_nounroll1.o:OK
#3/14 strobemeta_nounroll2.o:OK
#3 bpf_verif_scale:OK
Summary: 1/3 PASSED, 0 FAILED
Example of using subtest API is in the next patch, converting
bpf_verif_scale.c tests to use sub-tests.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-07-28 03:25:29 +00:00
|
|
|
return -ENOMEM;
|
2019-07-28 03:25:25 +00:00
|
|
|
break;
|
selftests/bpf: add sub-tests support for test_progs
Allow tests to have their own set of sub-tests. Also add ability to do
test/subtest selection using `-t <test-name>/<subtest-name>` and `-n
<test-nums-set>/<subtest-nums-set>`, as an extension of existing -t/-n
selector options. For the <test-num-set> format: it's a comma-separated
list of either individual test numbers (1-based), or range of test
numbers. E.g., all of the following are valid sets of test numbers:
- 10
- 1,2,3
- 1-3
- 5-10,1,3-4
'/<subtest' part is optional, but has the same format. E.g., to select
test #3 and its sub-tests #10 through #15, use: -t 3/10-15.
Similarly, to select tests by name, use `-t verif/strobe`:
$ sudo ./test_progs -t verif/strobe
#3/12 strobemeta.o:OK
#3/13 strobemeta_nounroll1.o:OK
#3/14 strobemeta_nounroll2.o:OK
#3 bpf_verif_scale:OK
Summary: 1/3 PASSED, 0 FAILED
Example of using subtest API is in the next patch, converting
bpf_verif_scale.c tests to use sub-tests.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-07-28 03:25:29 +00:00
|
|
|
}
|
2019-07-28 03:25:24 +00:00
|
|
|
case ARG_VERIFIER_STATS:
|
|
|
|
env->verifier_stats = true;
|
|
|
|
break;
|
2019-07-28 03:25:27 +00:00
|
|
|
case ARG_VERBOSE:
|
2019-11-20 00:35:48 +00:00
|
|
|
env->verbosity = VERBOSE_NORMAL;
|
2019-07-28 03:25:27 +00:00
|
|
|
if (arg) {
|
|
|
|
if (strcmp(arg, "v") == 0) {
|
2019-11-20 00:35:48 +00:00
|
|
|
env->verbosity = VERBOSE_VERY;
|
|
|
|
extra_prog_load_log_flags = 1;
|
|
|
|
} else if (strcmp(arg, "vv") == 0) {
|
|
|
|
env->verbosity = VERBOSE_SUPER;
|
|
|
|
extra_prog_load_log_flags = 2;
|
2019-07-28 03:25:27 +00:00
|
|
|
} else {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Unrecognized verbosity setting ('%s'), only -v and -vv are supported\n",
|
|
|
|
arg);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
2020-12-11 01:07:11 +00:00
|
|
|
|
|
|
|
if (env->verbosity > VERBOSE_NONE) {
|
|
|
|
if (setenv("SELFTESTS_VERBOSE", "1", 1) == -1) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Unable to setenv SELFTESTS_VERBOSE=1 (errno=%d)",
|
|
|
|
errno);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-28 03:25:27 +00:00
|
|
|
break;
|
2020-07-01 21:44:12 +00:00
|
|
|
case ARG_GET_TEST_CNT:
|
|
|
|
env->get_test_cnt = true;
|
|
|
|
break;
|
2020-07-01 21:44:17 +00:00
|
|
|
case ARG_LIST_TEST_NAMES:
|
|
|
|
env->list_test_names = true;
|
|
|
|
break;
|
2019-07-28 03:25:24 +00:00
|
|
|
case ARGP_KEY_ARG:
|
|
|
|
argp_usage(state);
|
|
|
|
break;
|
|
|
|
case ARGP_KEY_END:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return ARGP_ERR_UNKNOWN;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-08-06 17:45:27 +00:00
|
|
|
static void stdio_hijack(void)
|
|
|
|
{
|
|
|
|
#ifdef __GLIBC__
|
|
|
|
env.stdout = stdout;
|
|
|
|
env.stderr = stderr;
|
|
|
|
|
2019-11-20 00:35:48 +00:00
|
|
|
if (env.verbosity > VERBOSE_NONE) {
|
2019-08-06 17:45:27 +00:00
|
|
|
/* nothing to do, output to stdout by default */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* stdout and stderr -> buffer */
|
|
|
|
fflush(stdout);
|
|
|
|
|
|
|
|
stdout = open_memstream(&env.log_buf, &env.log_cnt);
|
|
|
|
if (!stdout) {
|
|
|
|
stdout = env.stdout;
|
|
|
|
perror("open_memstream");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
stderr = stdout;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void stdio_restore(void)
|
|
|
|
{
|
|
|
|
#ifdef __GLIBC__
|
|
|
|
if (stdout == env.stdout)
|
|
|
|
return;
|
|
|
|
|
|
|
|
fclose(stdout);
|
|
|
|
free(env.log_buf);
|
|
|
|
|
|
|
|
env.log_buf = NULL;
|
|
|
|
env.log_cnt = 0;
|
|
|
|
|
|
|
|
stdout = env.stdout;
|
|
|
|
stderr = env.stderr;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-10-16 06:00:45 +00:00
|
|
|
/*
|
|
|
|
* Determine if test_progs is running as a "flavored" test runner and switch
|
|
|
|
* into corresponding sub-directory to load correct BPF objects.
|
|
|
|
*
|
|
|
|
* This is done by looking at executable name. If it contains "-flavor"
|
|
|
|
* suffix, then we are running as a flavored test runner.
|
|
|
|
*/
|
|
|
|
int cd_flavor_subdir(const char *exec_name)
|
|
|
|
{
|
|
|
|
/* General form of argv[0] passed here is:
|
|
|
|
* some/path/to/test_progs[-flavor], where -flavor part is optional.
|
|
|
|
* First cut out "test_progs[-flavor]" part, then extract "flavor"
|
|
|
|
* part, if it's there.
|
|
|
|
*/
|
|
|
|
const char *flavor = strrchr(exec_name, '/');
|
|
|
|
|
|
|
|
if (!flavor)
|
|
|
|
return 0;
|
|
|
|
flavor++;
|
|
|
|
flavor = strrchr(flavor, '-');
|
|
|
|
if (!flavor)
|
|
|
|
return 0;
|
|
|
|
flavor++;
|
2020-08-24 11:57:20 +00:00
|
|
|
if (env.verbosity > VERBOSE_NONE)
|
|
|
|
fprintf(stdout, "Switching to flavor '%s' subdirectory...\n", flavor);
|
|
|
|
|
2019-10-16 06:00:45 +00:00
|
|
|
return chdir(flavor);
|
|
|
|
}
|
|
|
|
|
2020-02-25 00:08:47 +00:00
|
|
|
#define MAX_BACKTRACE_SZ 128
|
|
|
|
void crash_handler(int signum)
|
|
|
|
{
|
|
|
|
void *bt[MAX_BACKTRACE_SZ];
|
|
|
|
size_t sz;
|
|
|
|
|
|
|
|
sz = backtrace(bt, ARRAY_SIZE(bt));
|
|
|
|
|
|
|
|
if (env.test)
|
|
|
|
dump_test_log(env.test, true);
|
|
|
|
if (env.stdout)
|
|
|
|
stdio_restore();
|
|
|
|
|
|
|
|
fprintf(stderr, "Caught signal #%d!\nStack trace:\n", signum);
|
|
|
|
backtrace_symbols_fd(bt, sz, STDERR_FILENO);
|
|
|
|
}
|
|
|
|
|
2019-07-28 03:25:24 +00:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
static const struct argp argp = {
|
|
|
|
.options = opts,
|
|
|
|
.parser = parse_arg,
|
|
|
|
.doc = argp_program_doc,
|
|
|
|
};
|
2020-02-25 00:08:47 +00:00
|
|
|
struct sigaction sigact = {
|
|
|
|
.sa_handler = crash_handler,
|
|
|
|
.sa_flags = SA_RESETHAND,
|
|
|
|
};
|
2019-07-28 03:25:24 +00:00
|
|
|
int err, i;
|
|
|
|
|
2020-02-25 00:08:47 +00:00
|
|
|
sigaction(SIGSEGV, &sigact, NULL);
|
|
|
|
|
2019-07-28 03:25:24 +00:00
|
|
|
err = argp_parse(&argp, argc, argv, 0, NULL, &env);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2019-10-16 06:00:45 +00:00
|
|
|
err = cd_flavor_subdir(argv[0]);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2021-05-25 03:59:32 +00:00
|
|
|
/* Use libbpf 1.0 API mode */
|
|
|
|
libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
|
|
|
|
|
2019-07-28 03:25:27 +00:00
|
|
|
libbpf_set_print(libbpf_print_fn);
|
|
|
|
|
2018-10-18 13:16:41 +00:00
|
|
|
srand(time(NULL));
|
|
|
|
|
2019-07-28 03:25:28 +00:00
|
|
|
env.jit_enabled = is_jit_enabled();
|
2020-03-14 01:39:32 +00:00
|
|
|
env.nr_cpus = libbpf_num_possible_cpus();
|
|
|
|
if (env.nr_cpus < 0) {
|
|
|
|
fprintf(stderr, "Failed to get number of CPUs: %d!\n",
|
|
|
|
env.nr_cpus);
|
|
|
|
return -1;
|
|
|
|
}
|
2018-04-29 05:28:15 +00:00
|
|
|
|
2020-07-02 00:48:58 +00:00
|
|
|
save_netns();
|
2019-08-06 17:45:27 +00:00
|
|
|
stdio_hijack();
|
2020-12-03 20:46:26 +00:00
|
|
|
env.has_testmod = true;
|
|
|
|
if (load_bpf_testmod()) {
|
|
|
|
fprintf(env.stderr, "WARNING! Selftests relying on bpf_testmod.ko will be skipped.\n");
|
|
|
|
env.has_testmod = false;
|
|
|
|
}
|
2019-07-28 03:25:28 +00:00
|
|
|
for (i = 0; i < prog_test_cnt; i++) {
|
|
|
|
struct prog_test_def *test = &prog_test_defs[i];
|
2019-07-28 03:25:25 +00:00
|
|
|
|
2019-07-28 03:25:28 +00:00
|
|
|
env.test = test;
|
2019-07-28 03:25:25 +00:00
|
|
|
test->test_num = i + 1;
|
|
|
|
|
selftests/bpf: add sub-tests support for test_progs
Allow tests to have their own set of sub-tests. Also add ability to do
test/subtest selection using `-t <test-name>/<subtest-name>` and `-n
<test-nums-set>/<subtest-nums-set>`, as an extension of existing -t/-n
selector options. For the <test-num-set> format: it's a comma-separated
list of either individual test numbers (1-based), or range of test
numbers. E.g., all of the following are valid sets of test numbers:
- 10
- 1,2,3
- 1-3
- 5-10,1,3-4
'/<subtest' part is optional, but has the same format. E.g., to select
test #3 and its sub-tests #10 through #15, use: -t 3/10-15.
Similarly, to select tests by name, use `-t verif/strobe`:
$ sudo ./test_progs -t verif/strobe
#3/12 strobemeta.o:OK
#3/13 strobemeta_nounroll1.o:OK
#3/14 strobemeta_nounroll2.o:OK
#3 bpf_verif_scale:OK
Summary: 1/3 PASSED, 0 FAILED
Example of using subtest API is in the next patch, converting
bpf_verif_scale.c tests to use sub-tests.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-07-28 03:25:29 +00:00
|
|
|
if (!should_run(&env.test_selector,
|
|
|
|
test->test_num, test->test_name))
|
2019-07-28 03:25:25 +00:00
|
|
|
continue;
|
|
|
|
|
2020-07-01 21:44:12 +00:00
|
|
|
if (env.get_test_cnt) {
|
|
|
|
env.succ_cnt++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-07-01 21:44:17 +00:00
|
|
|
if (env.list_test_names) {
|
|
|
|
fprintf(env.stdout, "%s\n", test->test_name);
|
|
|
|
env.succ_cnt++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-07-28 03:25:25 +00:00
|
|
|
test->run_test();
|
selftests/bpf: add sub-tests support for test_progs
Allow tests to have their own set of sub-tests. Also add ability to do
test/subtest selection using `-t <test-name>/<subtest-name>` and `-n
<test-nums-set>/<subtest-nums-set>`, as an extension of existing -t/-n
selector options. For the <test-num-set> format: it's a comma-separated
list of either individual test numbers (1-based), or range of test
numbers. E.g., all of the following are valid sets of test numbers:
- 10
- 1,2,3
- 1-3
- 5-10,1,3-4
'/<subtest' part is optional, but has the same format. E.g., to select
test #3 and its sub-tests #10 through #15, use: -t 3/10-15.
Similarly, to select tests by name, use `-t verif/strobe`:
$ sudo ./test_progs -t verif/strobe
#3/12 strobemeta.o:OK
#3/13 strobemeta_nounroll1.o:OK
#3/14 strobemeta_nounroll2.o:OK
#3 bpf_verif_scale:OK
Summary: 1/3 PASSED, 0 FAILED
Example of using subtest API is in the next patch, converting
bpf_verif_scale.c tests to use sub-tests.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-07-28 03:25:29 +00:00
|
|
|
/* ensure last sub-test is finalized properly */
|
|
|
|
if (test->subtest_name)
|
|
|
|
test__end_subtest();
|
|
|
|
|
2019-07-28 03:25:28 +00:00
|
|
|
test->tested = true;
|
|
|
|
if (test->error_cnt)
|
|
|
|
env.fail_cnt++;
|
|
|
|
else
|
|
|
|
env.succ_cnt++;
|
2019-08-21 23:44:24 +00:00
|
|
|
skip_account();
|
2019-07-28 03:25:28 +00:00
|
|
|
|
selftests/bpf: add sub-tests support for test_progs
Allow tests to have their own set of sub-tests. Also add ability to do
test/subtest selection using `-t <test-name>/<subtest-name>` and `-n
<test-nums-set>/<subtest-nums-set>`, as an extension of existing -t/-n
selector options. For the <test-num-set> format: it's a comma-separated
list of either individual test numbers (1-based), or range of test
numbers. E.g., all of the following are valid sets of test numbers:
- 10
- 1,2,3
- 1-3
- 5-10,1,3-4
'/<subtest' part is optional, but has the same format. E.g., to select
test #3 and its sub-tests #10 through #15, use: -t 3/10-15.
Similarly, to select tests by name, use `-t verif/strobe`:
$ sudo ./test_progs -t verif/strobe
#3/12 strobemeta.o:OK
#3/13 strobemeta_nounroll1.o:OK
#3/14 strobemeta_nounroll2.o:OK
#3 bpf_verif_scale:OK
Summary: 1/3 PASSED, 0 FAILED
Example of using subtest API is in the next patch, converting
bpf_verif_scale.c tests to use sub-tests.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-07-28 03:25:29 +00:00
|
|
|
dump_test_log(test, test->error_cnt);
|
2019-07-28 03:25:28 +00:00
|
|
|
|
2019-08-06 17:45:27 +00:00
|
|
|
fprintf(env.stdout, "#%d %s:%s\n",
|
|
|
|
test->test_num, test->test_name,
|
|
|
|
test->error_cnt ? "FAIL" : "OK");
|
2019-09-04 16:25:04 +00:00
|
|
|
|
2020-03-14 01:39:32 +00:00
|
|
|
reset_affinity();
|
2020-07-02 00:48:58 +00:00
|
|
|
restore_netns();
|
2019-09-04 16:25:04 +00:00
|
|
|
if (test->need_cgroup_cleanup)
|
|
|
|
cleanup_cgroup_environment();
|
2019-07-28 03:25:24 +00:00
|
|
|
}
|
2020-12-03 20:46:26 +00:00
|
|
|
if (env.has_testmod)
|
|
|
|
unload_bpf_testmod();
|
2019-08-06 17:45:27 +00:00
|
|
|
stdio_restore();
|
2020-07-01 21:44:12 +00:00
|
|
|
|
|
|
|
if (env.get_test_cnt) {
|
|
|
|
printf("%d\n", env.succ_cnt);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2020-07-01 21:44:17 +00:00
|
|
|
if (env.list_test_names)
|
|
|
|
goto out;
|
|
|
|
|
2020-03-13 17:23:33 +00:00
|
|
|
fprintf(stdout, "Summary: %d/%d PASSED, %d SKIPPED, %d FAILED\n",
|
|
|
|
env.succ_cnt, env.sub_succ_cnt, env.skip_cnt, env.fail_cnt);
|
2019-07-28 03:25:28 +00:00
|
|
|
|
2020-07-01 21:44:12 +00:00
|
|
|
out:
|
2020-04-29 01:21:05 +00:00
|
|
|
free_str_set(&env.test_selector.blacklist);
|
|
|
|
free_str_set(&env.test_selector.whitelist);
|
selftests/bpf: add sub-tests support for test_progs
Allow tests to have their own set of sub-tests. Also add ability to do
test/subtest selection using `-t <test-name>/<subtest-name>` and `-n
<test-nums-set>/<subtest-nums-set>`, as an extension of existing -t/-n
selector options. For the <test-num-set> format: it's a comma-separated
list of either individual test numbers (1-based), or range of test
numbers. E.g., all of the following are valid sets of test numbers:
- 10
- 1,2,3
- 1-3
- 5-10,1,3-4
'/<subtest' part is optional, but has the same format. E.g., to select
test #3 and its sub-tests #10 through #15, use: -t 3/10-15.
Similarly, to select tests by name, use `-t verif/strobe`:
$ sudo ./test_progs -t verif/strobe
#3/12 strobemeta.o:OK
#3/13 strobemeta_nounroll1.o:OK
#3/14 strobemeta_nounroll2.o:OK
#3 bpf_verif_scale:OK
Summary: 1/3 PASSED, 0 FAILED
Example of using subtest API is in the next patch, converting
bpf_verif_scale.c tests to use sub-tests.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-07-28 03:25:29 +00:00
|
|
|
free(env.test_selector.num_set);
|
2020-04-29 01:21:05 +00:00
|
|
|
free_str_set(&env.subtest_selector.blacklist);
|
|
|
|
free_str_set(&env.subtest_selector.whitelist);
|
selftests/bpf: add sub-tests support for test_progs
Allow tests to have their own set of sub-tests. Also add ability to do
test/subtest selection using `-t <test-name>/<subtest-name>` and `-n
<test-nums-set>/<subtest-nums-set>`, as an extension of existing -t/-n
selector options. For the <test-num-set> format: it's a comma-separated
list of either individual test numbers (1-based), or range of test
numbers. E.g., all of the following are valid sets of test numbers:
- 10
- 1,2,3
- 1-3
- 5-10,1,3-4
'/<subtest' part is optional, but has the same format. E.g., to select
test #3 and its sub-tests #10 through #15, use: -t 3/10-15.
Similarly, to select tests by name, use `-t verif/strobe`:
$ sudo ./test_progs -t verif/strobe
#3/12 strobemeta.o:OK
#3/13 strobemeta_nounroll1.o:OK
#3/14 strobemeta_nounroll2.o:OK
#3 bpf_verif_scale:OK
Summary: 1/3 PASSED, 0 FAILED
Example of using subtest API is in the next patch, converting
bpf_verif_scale.c tests to use sub-tests.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-07-28 03:25:29 +00:00
|
|
|
free(env.subtest_selector.num_set);
|
2020-07-02 00:48:58 +00:00
|
|
|
close(env.saved_netns_fd);
|
2017-03-31 04:45:41 +00:00
|
|
|
|
2020-07-01 21:44:07 +00:00
|
|
|
if (env.succ_cnt + env.fail_cnt + env.skip_cnt == 0)
|
2020-07-07 07:12:19 +00:00
|
|
|
return EXIT_NO_TEST;
|
2020-07-01 21:44:07 +00:00
|
|
|
|
2019-08-21 23:44:25 +00:00
|
|
|
return env.fail_cnt ? EXIT_FAILURE : EXIT_SUCCESS;
|
2017-03-31 04:45:41 +00:00
|
|
|
}
|