2019-05-29 01:10:09 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2017-03-31 12:45:41 +08:00
|
|
|
/* Copyright (c) 2017 Facebook
|
|
|
|
*/
|
2019-03-02 11:42:13 +08:00
|
|
|
#include "test_progs.h"
|
2018-02-27 05:34:32 +08:00
|
|
|
#include "bpf_rlimit.h"
|
2019-07-28 11:25:24 +08:00
|
|
|
#include <argp.h>
|
2019-07-28 11:25:25 +08:00
|
|
|
#include <string.h>
|
2017-03-31 12:45:41 +08:00
|
|
|
|
2019-07-28 11:25:28 +08:00
|
|
|
/* defined in test_progs.h */
|
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 11:25:29 +08:00
|
|
|
struct test_env env;
|
2019-07-28 11:25:28 +08:00
|
|
|
|
|
|
|
struct prog_test_def {
|
|
|
|
const char *test_name;
|
|
|
|
int test_num;
|
|
|
|
void (*run_test)(void);
|
|
|
|
bool force_log;
|
|
|
|
int error_cnt;
|
2019-08-22 07:44:24 +08:00
|
|
|
int skip_cnt;
|
2019-07-28 11:25:28 +08:00
|
|
|
bool tested;
|
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 11:25:29 +08:00
|
|
|
|
|
|
|
const char *subtest_name;
|
|
|
|
int subtest_num;
|
|
|
|
|
|
|
|
/* store counts before subtest started */
|
|
|
|
int old_error_cnt;
|
2019-07-28 11:25:28 +08: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 11:25:29 +08:00
|
|
|
static bool should_run(struct test_selector *sel, int num, const char *name)
|
|
|
|
{
|
|
|
|
if (sel->name && sel->name[0] && !strstr(name, sel->name))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!sel->num_set)
|
|
|
|
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-07 01:45:27 +08:00
|
|
|
if (stdout == env.stdout)
|
|
|
|
return;
|
|
|
|
|
|
|
|
fflush(stdout); /* exports env.log_buf & env.log_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 11:25:29 +08:00
|
|
|
if (env.verbose || test->force_log || failed) {
|
|
|
|
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 10:34:26 +08:00
|
|
|
env.log_buf[env.log_cnt] = '\0';
|
2019-08-07 01:45:27 +08: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 11:25:29 +08:00
|
|
|
if (env.log_buf[env.log_cnt - 1] != '\n')
|
2019-08-07 01:45:27 +08: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 11:25:29 +08:00
|
|
|
}
|
|
|
|
}
|
2019-08-07 01:45:27 +08: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 11:25:29 +08:00
|
|
|
}
|
|
|
|
|
2019-08-22 07:44:24 +08:00
|
|
|
static void skip_account(void)
|
|
|
|
{
|
|
|
|
if (env.test->skip_cnt) {
|
|
|
|
env.skip_cnt++;
|
|
|
|
env.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 11:25:29 +08:00
|
|
|
void test__end_subtest()
|
|
|
|
{
|
|
|
|
struct prog_test_def *test = env.test;
|
2019-08-22 07:44:25 +08: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 11:25:29 +08:00
|
|
|
|
|
|
|
if (sub_error_cnt)
|
|
|
|
env.fail_cnt++;
|
|
|
|
else
|
|
|
|
env.sub_succ_cnt++;
|
2019-08-22 07:44:24 +08: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 11:25:29 +08:00
|
|
|
|
|
|
|
dump_test_log(test, sub_error_cnt);
|
|
|
|
|
2019-08-07 01:45:27 +08:00
|
|
|
fprintf(env.stdout, "#%d/%d %s:%s\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 11:25:29 +08:00
|
|
|
test->test_num, test->subtest_num,
|
|
|
|
test->subtest_name, sub_error_cnt ? "FAIL" : "OK");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool test__start_subtest(const char *name)
|
|
|
|
{
|
|
|
|
struct prog_test_def *test = env.test;
|
|
|
|
|
|
|
|
if (test->subtest_name) {
|
|
|
|
test__end_subtest();
|
|
|
|
test->subtest_name = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
test->subtest_num++;
|
|
|
|
|
|
|
|
if (!name || !name[0]) {
|
2019-08-07 01:45:27 +08: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 11:25:29 +08:00
|
|
|
test->subtest_num);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!should_run(&env.subtest_selector, test->subtest_num, name))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
test->subtest_name = name;
|
2019-08-22 07:44:25 +08: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 11:25:29 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-07-28 11:25:28 +08:00
|
|
|
void test__force_log() {
|
|
|
|
env.test->force_log = true;
|
|
|
|
}
|
|
|
|
|
2019-08-22 07:44:24 +08:00
|
|
|
void test__skip(void)
|
|
|
|
{
|
|
|
|
env.test->skip_cnt++;
|
|
|
|
}
|
|
|
|
|
2019-08-22 07:44:25 +08:00
|
|
|
void test__fail(void)
|
|
|
|
{
|
|
|
|
env.test->error_cnt++;
|
|
|
|
}
|
|
|
|
|
2019-03-02 11:42:13 +08:00
|
|
|
struct ipv4_packet pkt_v4 = {
|
2018-12-12 11:20:52 +08:00
|
|
|
.eth.h_proto = __bpf_constant_htons(ETH_P_IP),
|
2017-03-31 12:45:41 +08:00
|
|
|
.iph.ihl = 5,
|
2019-01-29 00:53:55 +08:00
|
|
|
.iph.protocol = IPPROTO_TCP,
|
2018-12-12 11:20:52 +08:00
|
|
|
.iph.tot_len = __bpf_constant_htons(MAGIC_BYTES),
|
2017-03-31 12:45:41 +08:00
|
|
|
.tcp.urg_ptr = 123,
|
2019-01-29 00:53:55 +08:00
|
|
|
.tcp.doff = 5,
|
2017-03-31 12:45:41 +08:00
|
|
|
};
|
|
|
|
|
2019-03-02 11:42:13 +08:00
|
|
|
struct ipv6_packet pkt_v6 = {
|
2018-12-12 11:20:52 +08:00
|
|
|
.eth.h_proto = __bpf_constant_htons(ETH_P_IPV6),
|
2019-01-29 00:53:55 +08:00
|
|
|
.iph.nexthdr = IPPROTO_TCP,
|
2018-12-12 11:20:52 +08:00
|
|
|
.iph.payload_len = __bpf_constant_htons(MAGIC_BYTES),
|
2017-03-31 12:45:41 +08:00
|
|
|
.tcp.urg_ptr = 123,
|
2019-01-29 00:53:55 +08:00
|
|
|
.tcp.doff = 5,
|
2017-03-31 12:45:41 +08:00
|
|
|
};
|
|
|
|
|
2019-03-02 11:42:13 +08:00
|
|
|
int bpf_find_map(const char *test, struct bpf_object *obj, const char *name)
|
2017-03-31 12:45:42 +08:00
|
|
|
{
|
|
|
|
struct bpf_map *map;
|
|
|
|
|
|
|
|
map = bpf_object__find_map_by_name(obj, name);
|
|
|
|
if (!map) {
|
|
|
|
printf("%s:FAIL:map '%s' not found\n", test, name);
|
2019-08-22 07:44:25 +08:00
|
|
|
test__fail();
|
2017-03-31 12:45:42 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return bpf_map__fd(map);
|
|
|
|
}
|
|
|
|
|
2018-04-29 13:28:15 +08: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 11:42:16 +08:00
|
|
|
int compare_map_keys(int map1_fd, int map2_fd)
|
2018-01-05 05:55:04 +08:00
|
|
|
{
|
|
|
|
__u32 key, next_key;
|
2018-03-15 01:23:22 +08:00
|
|
|
char val_buf[PERF_MAX_STACK_DEPTH *
|
|
|
|
sizeof(struct bpf_stack_build_id)];
|
2018-01-05 05:55:04 +08: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 11:42:16 +08:00
|
|
|
int compare_stack_ips(int smap_fd, int amap_fd, int stack_trace_len)
|
2018-04-29 13:28:16 +08: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 11:42:16 +08:00
|
|
|
int extract_build_id(char *build_id, size_t size)
|
2018-03-15 01:23:22 +08: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';
|
|
|
|
return 0;
|
|
|
|
err:
|
|
|
|
fclose(fp);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-03-02 11:42:18 +08:00
|
|
|
void *spin_lock_thread(void *arg)
|
2019-02-01 07:40:08 +08:00
|
|
|
{
|
|
|
|
__u32 duration, retval;
|
|
|
|
int err, prog_fd = *(u32 *) arg;
|
|
|
|
|
|
|
|
err = bpf_prog_test_run(prog_fd, 10000, &pkt_v4, sizeof(pkt_v4),
|
|
|
|
NULL, NULL, &retval, &duration);
|
|
|
|
CHECK(err || retval, "",
|
|
|
|
"err %d errno %d retval %d duration %d\n",
|
|
|
|
err, errno, retval, duration);
|
|
|
|
pthread_exit(arg);
|
|
|
|
}
|
|
|
|
|
2019-07-28 11:25:24 +08:00
|
|
|
/* extern declarations for test funcs */
|
|
|
|
#define DEFINE_TEST(name) extern void test_##name();
|
2019-03-02 11:42:13 +08:00
|
|
|
#include <prog_tests/tests.h>
|
2019-07-28 11:25:24 +08:00
|
|
|
#undef DEFINE_TEST
|
2019-03-02 11:42:13 +08:00
|
|
|
|
2019-07-28 11:25:24 +08:00
|
|
|
static struct prog_test_def prog_test_defs[] = {
|
2019-07-28 11:25:28 +08:00
|
|
|
#define DEFINE_TEST(name) { \
|
|
|
|
.test_name = #name, \
|
|
|
|
.run_test = &test_##name, \
|
2019-07-28 11:25:24 +08:00
|
|
|
},
|
|
|
|
#include <prog_tests/tests.h>
|
|
|
|
#undef DEFINE_TEST
|
|
|
|
};
|
2019-07-28 11:25:28 +08:00
|
|
|
const int prog_test_cnt = ARRAY_SIZE(prog_test_defs);
|
2019-07-28 11:25:24 +08: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 11:25:25 +08:00
|
|
|
ARG_TEST_NUM = 'n',
|
|
|
|
ARG_TEST_NAME = 't',
|
2019-07-28 11:25:24 +08:00
|
|
|
ARG_VERIFIER_STATS = 's',
|
2019-07-28 11:25:27 +08:00
|
|
|
ARG_VERBOSE = 'v',
|
2019-07-28 11:25:24 +08:00
|
|
|
};
|
2019-08-07 01:45:29 +08:00
|
|
|
|
2019-07-28 11:25:24 +08:00
|
|
|
static const struct argp_option opts[] = {
|
2019-07-28 11:25:25 +08:00
|
|
|
{ "num", ARG_TEST_NUM, "NUM", 0,
|
|
|
|
"Run test number NUM only " },
|
|
|
|
{ "name", ARG_TEST_NAME, "NAME", 0,
|
|
|
|
"Run tests with names containing NAME" },
|
2019-07-28 11:25:24 +08:00
|
|
|
{ "verifier-stats", ARG_VERIFIER_STATS, NULL, 0,
|
|
|
|
"Output verifier statistics", },
|
2019-07-28 11:25:27 +08:00
|
|
|
{ "verbose", ARG_VERBOSE, "LEVEL", OPTION_ARG_OPTIONAL,
|
|
|
|
"Verbose output (use -vv for extra verbose output)" },
|
2019-07-28 11:25:24 +08:00
|
|
|
{},
|
|
|
|
};
|
|
|
|
|
2019-07-28 11:25:27 +08:00
|
|
|
static int libbpf_print_fn(enum libbpf_print_level level,
|
|
|
|
const char *format, va_list args)
|
|
|
|
{
|
|
|
|
if (!env.very_verbose && level == LIBBPF_DEBUG)
|
|
|
|
return 0;
|
2019-08-07 01:45:28 +08:00
|
|
|
vprintf(format, args);
|
2019-07-28 11:25:28 +08:00
|
|
|
return 0;
|
2019-07-28 11:25:27 +08: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 11:25:29 +08:00
|
|
|
int parse_num_list(const char *s, struct test_selector *sel)
|
|
|
|
{
|
|
|
|
int i, set_len = 0, num, start = 0, end = -1;
|
|
|
|
bool *set = NULL, *tmp, parsing_end = false;
|
|
|
|
char *next;
|
|
|
|
|
|
|
|
while (s[0]) {
|
|
|
|
errno = 0;
|
|
|
|
num = strtol(s, &next, 10);
|
|
|
|
if (errno)
|
|
|
|
return -errno;
|
|
|
|
|
|
|
|
if (parsing_end)
|
|
|
|
end = num;
|
|
|
|
else
|
|
|
|
start = num;
|
|
|
|
|
|
|
|
if (!parsing_end && *next == '-') {
|
|
|
|
s = next + 1;
|
|
|
|
parsing_end = true;
|
|
|
|
continue;
|
|
|
|
} else if (*next == ',') {
|
|
|
|
parsing_end = false;
|
|
|
|
s = next + 1;
|
|
|
|
end = num;
|
|
|
|
} else if (*next == '\0') {
|
|
|
|
parsing_end = false;
|
|
|
|
s = next;
|
|
|
|
end = num;
|
|
|
|
} else {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (start > end)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (end + 1 > set_len) {
|
|
|
|
set_len = end + 1;
|
|
|
|
tmp = realloc(set, set_len);
|
|
|
|
if (!tmp) {
|
|
|
|
free(set);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
set = tmp;
|
|
|
|
}
|
|
|
|
for (i = start; i <= end; i++) {
|
|
|
|
set[i] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!set)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
sel->num_set = set;
|
|
|
|
sel->num_set_len = set_len;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-07-28 11:25:24 +08:00
|
|
|
static error_t parse_arg(int key, char *arg, struct argp_state *state)
|
2017-03-31 12:45:41 +08:00
|
|
|
{
|
2019-07-28 11:25:24 +08:00
|
|
|
struct test_env *env = state->input;
|
|
|
|
|
|
|
|
switch (key) {
|
2019-07-28 11:25:25 +08: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 11:25:29 +08:00
|
|
|
char *subtest_str = strchr(arg, '/');
|
2019-07-28 11:25:25 +08: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 11:25:29 +08:00
|
|
|
if (subtest_str) {
|
|
|
|
*subtest_str = '\0';
|
|
|
|
if (parse_num_list(subtest_str + 1,
|
|
|
|
&env->subtest_selector)) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Failed to parse subtest numbers.\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (parse_num_list(arg, &env->test_selector)) {
|
|
|
|
fprintf(stderr, "Failed to parse test numbers.\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2019-07-28 11:25:25 +08: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 11:25:29 +08:00
|
|
|
case ARG_TEST_NAME: {
|
|
|
|
char *subtest_str = strchr(arg, '/');
|
|
|
|
|
|
|
|
if (subtest_str) {
|
|
|
|
*subtest_str = '\0';
|
|
|
|
env->subtest_selector.name = strdup(subtest_str + 1);
|
|
|
|
if (!env->subtest_selector.name)
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
env->test_selector.name = strdup(arg);
|
|
|
|
if (!env->test_selector.name)
|
|
|
|
return -ENOMEM;
|
2019-07-28 11:25:25 +08: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 11:25:29 +08:00
|
|
|
}
|
2019-07-28 11:25:24 +08:00
|
|
|
case ARG_VERIFIER_STATS:
|
|
|
|
env->verifier_stats = true;
|
|
|
|
break;
|
2019-07-28 11:25:27 +08:00
|
|
|
case ARG_VERBOSE:
|
|
|
|
if (arg) {
|
|
|
|
if (strcmp(arg, "v") == 0) {
|
|
|
|
env->very_verbose = true;
|
|
|
|
} else {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Unrecognized verbosity setting ('%s'), only -v and -vv are supported\n",
|
|
|
|
arg);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
env->verbose = true;
|
|
|
|
break;
|
2019-07-28 11:25:24 +08:00
|
|
|
case ARGP_KEY_ARG:
|
|
|
|
argp_usage(state);
|
|
|
|
break;
|
|
|
|
case ARGP_KEY_END:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return ARGP_ERR_UNKNOWN;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-08-07 01:45:27 +08:00
|
|
|
static void stdio_hijack(void)
|
|
|
|
{
|
|
|
|
#ifdef __GLIBC__
|
|
|
|
env.stdout = stdout;
|
|
|
|
env.stderr = stderr;
|
|
|
|
|
|
|
|
if (env.verbose) {
|
|
|
|
/* 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-07-28 11:25:24 +08:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
static const struct argp argp = {
|
|
|
|
.options = opts,
|
|
|
|
.parser = parse_arg,
|
|
|
|
.doc = argp_program_doc,
|
|
|
|
};
|
|
|
|
int err, i;
|
|
|
|
|
|
|
|
err = argp_parse(&argp, argc, argv, 0, NULL, &env);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2019-07-28 11:25:27 +08:00
|
|
|
libbpf_set_print(libbpf_print_fn);
|
|
|
|
|
2018-10-18 21:16:41 +08:00
|
|
|
srand(time(NULL));
|
|
|
|
|
2019-07-28 11:25:28 +08:00
|
|
|
env.jit_enabled = is_jit_enabled();
|
2018-04-29 13:28:15 +08:00
|
|
|
|
2019-08-07 01:45:27 +08:00
|
|
|
stdio_hijack();
|
2019-07-28 11:25:28 +08:00
|
|
|
for (i = 0; i < prog_test_cnt; i++) {
|
|
|
|
struct prog_test_def *test = &prog_test_defs[i];
|
2019-07-28 11:25:25 +08:00
|
|
|
|
2019-07-28 11:25:28 +08:00
|
|
|
env.test = test;
|
2019-07-28 11:25:25 +08: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 11:25:29 +08:00
|
|
|
if (!should_run(&env.test_selector,
|
|
|
|
test->test_num, test->test_name))
|
2019-07-28 11:25:25 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
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 11:25:29 +08:00
|
|
|
/* ensure last sub-test is finalized properly */
|
|
|
|
if (test->subtest_name)
|
|
|
|
test__end_subtest();
|
|
|
|
|
2019-07-28 11:25:28 +08:00
|
|
|
test->tested = true;
|
|
|
|
if (test->error_cnt)
|
|
|
|
env.fail_cnt++;
|
|
|
|
else
|
|
|
|
env.succ_cnt++;
|
2019-08-22 07:44:24 +08:00
|
|
|
skip_account();
|
2019-07-28 11:25:28 +08: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 11:25:29 +08:00
|
|
|
dump_test_log(test, test->error_cnt);
|
2019-07-28 11:25:28 +08:00
|
|
|
|
2019-08-07 01:45:27 +08:00
|
|
|
fprintf(env.stdout, "#%d %s:%s\n",
|
|
|
|
test->test_num, test->test_name,
|
|
|
|
test->error_cnt ? "FAIL" : "OK");
|
2019-07-28 11:25:24 +08:00
|
|
|
}
|
2019-08-07 01:45:27 +08:00
|
|
|
stdio_restore();
|
2019-08-22 07:44:24 +08:00
|
|
|
printf("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 11:25:28 +08: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 11:25:29 +08:00
|
|
|
free(env.test_selector.num_set);
|
|
|
|
free(env.subtest_selector.num_set);
|
2017-03-31 12:45:41 +08:00
|
|
|
|
2019-08-22 07:44:25 +08:00
|
|
|
return env.fail_cnt ? EXIT_FAILURE : EXIT_SUCCESS;
|
2017-03-31 12:45:41 +08:00
|
|
|
}
|