2019-03-02 03:42:13 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
typedef __u16 __sum16;
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <linux/if_ether.h>
|
|
|
|
#include <linux/if_packet.h>
|
|
|
|
#include <linux/ip.h>
|
|
|
|
#include <linux/ipv6.h>
|
2019-09-04 16:25:06 +00:00
|
|
|
#include <netinet/tcp.h>
|
2019-03-02 03:42:13 +00:00
|
|
|
#include <linux/filter.h>
|
|
|
|
#include <linux/perf_event.h>
|
2019-09-04 16:25:06 +00:00
|
|
|
#include <linux/socket.h>
|
2019-03-02 03:42:13 +00:00
|
|
|
#include <linux/unistd.h>
|
|
|
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <linux/bpf.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <bpf/bpf.h>
|
|
|
|
#include <bpf/libbpf.h>
|
|
|
|
|
|
|
|
#include "test_iptunnel_common.h"
|
|
|
|
#include "bpf_util.h"
|
|
|
|
#include "bpf_endian.h"
|
|
|
|
#include "trace_helpers.h"
|
|
|
|
#include "flow_dissector_load.h"
|
|
|
|
|
2019-11-20 00:35:48 +00:00
|
|
|
enum verbosity {
|
|
|
|
VERBOSE_NONE,
|
|
|
|
VERBOSE_NORMAL,
|
|
|
|
VERBOSE_VERY,
|
|
|
|
VERBOSE_SUPER,
|
|
|
|
};
|
|
|
|
|
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 str_set {
|
|
|
|
const char **strs;
|
|
|
|
int 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
|
|
|
struct test_selector {
|
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 str_set whitelist;
|
|
|
|
struct str_set 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
|
|
|
bool *num_set;
|
|
|
|
int num_set_len;
|
|
|
|
};
|
|
|
|
|
2019-07-28 03:25:28 +00:00
|
|
|
struct test_env {
|
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
|
|
|
struct test_selector test_selector;
|
|
|
|
struct test_selector subtest_selector;
|
2019-07-28 03:25:28 +00:00
|
|
|
bool verifier_stats;
|
2019-11-20 00:35:48 +00:00
|
|
|
enum verbosity verbosity;
|
2019-07-28 03:25:28 +00:00
|
|
|
|
|
|
|
bool jit_enabled;
|
|
|
|
|
|
|
|
struct prog_test_def *test;
|
2019-08-06 17:45:27 +00:00
|
|
|
FILE *stdout;
|
|
|
|
FILE *stderr;
|
2019-07-28 03:25:28 +00:00
|
|
|
char *log_buf;
|
|
|
|
size_t 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 03:25:29 +00:00
|
|
|
int succ_cnt; /* successful tests */
|
|
|
|
int sub_succ_cnt; /* successful sub-tests */
|
|
|
|
int fail_cnt; /* total failed tests + sub-tests */
|
2019-08-21 23:44:24 +00:00
|
|
|
int skip_cnt; /* skipped tests */
|
2019-07-28 03:25:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern struct test_env env;
|
|
|
|
|
|
|
|
extern void test__force_log();
|
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
|
|
|
extern bool test__start_subtest(const char *name);
|
2019-08-21 23:44:24 +00:00
|
|
|
extern void test__skip(void);
|
2019-08-21 23:44:25 +00:00
|
|
|
extern void test__fail(void);
|
2019-09-04 16:25:04 +00:00
|
|
|
extern int test__join_cgroup(const char *path);
|
2019-03-02 03:42:13 +00:00
|
|
|
|
|
|
|
#define MAGIC_BYTES 123
|
|
|
|
|
|
|
|
/* ipv4 test vector */
|
|
|
|
struct ipv4_packet {
|
|
|
|
struct ethhdr eth;
|
|
|
|
struct iphdr iph;
|
|
|
|
struct tcphdr tcp;
|
|
|
|
} __packed;
|
|
|
|
extern struct ipv4_packet pkt_v4;
|
|
|
|
|
|
|
|
/* ipv6 test vector */
|
|
|
|
struct ipv6_packet {
|
|
|
|
struct ethhdr eth;
|
|
|
|
struct ipv6hdr iph;
|
|
|
|
struct tcphdr tcp;
|
|
|
|
} __packed;
|
|
|
|
extern struct ipv6_packet pkt_v6;
|
|
|
|
|
|
|
|
#define _CHECK(condition, tag, duration, format...) ({ \
|
|
|
|
int __ret = !!(condition); \
|
2019-12-20 00:05:11 +00:00
|
|
|
int __save_errno = errno; \
|
2019-03-02 03:42:13 +00:00
|
|
|
if (__ret) { \
|
2019-08-21 23:44:25 +00:00
|
|
|
test__fail(); \
|
2019-08-06 17:45:28 +00:00
|
|
|
printf("%s:FAIL:%s ", __func__, tag); \
|
|
|
|
printf(format); \
|
2019-03-02 03:42:13 +00:00
|
|
|
} else { \
|
2019-08-06 17:45:28 +00:00
|
|
|
printf("%s:PASS:%s %d nsec\n", \
|
|
|
|
__func__, tag, duration); \
|
2019-03-02 03:42:13 +00:00
|
|
|
} \
|
2019-12-20 00:05:11 +00:00
|
|
|
errno = __save_errno; \
|
2019-03-02 03:42:13 +00:00
|
|
|
__ret; \
|
|
|
|
})
|
|
|
|
|
2019-08-21 23:44:25 +00:00
|
|
|
#define CHECK_FAIL(condition) ({ \
|
|
|
|
int __ret = !!(condition); \
|
2019-12-20 00:05:11 +00:00
|
|
|
int __save_errno = errno; \
|
2019-08-21 23:44:25 +00:00
|
|
|
if (__ret) { \
|
|
|
|
test__fail(); \
|
2019-08-31 02:34:27 +00:00
|
|
|
printf("%s:FAIL:%d\n", __func__, __LINE__); \
|
2019-08-21 23:44:25 +00:00
|
|
|
} \
|
2019-12-20 00:05:11 +00:00
|
|
|
errno = __save_errno; \
|
2019-08-21 23:44:25 +00:00
|
|
|
__ret; \
|
|
|
|
})
|
|
|
|
|
2019-03-02 03:42:13 +00:00
|
|
|
#define CHECK(condition, tag, format...) \
|
|
|
|
_CHECK(condition, tag, duration, format)
|
|
|
|
#define CHECK_ATTR(condition, tag, format...) \
|
|
|
|
_CHECK(condition, tag, tattr.duration, format)
|
|
|
|
|
2019-03-02 03:42:15 +00:00
|
|
|
#define MAGIC_VAL 0x1234
|
|
|
|
#define NUM_ITER 100000
|
|
|
|
#define VIP_NUM 5
|
|
|
|
|
2019-03-02 03:42:19 +00:00
|
|
|
static inline __u64 ptr_to_u64(const void *ptr)
|
|
|
|
{
|
|
|
|
return (__u64) (unsigned long) ptr;
|
|
|
|
}
|
|
|
|
|
2019-03-02 03:42:13 +00:00
|
|
|
int bpf_find_map(const char *test, struct bpf_object *obj, const char *name);
|
2019-03-02 03:42:16 +00:00
|
|
|
int compare_map_keys(int map1_fd, int map2_fd);
|
|
|
|
int compare_stack_ips(int smap_fd, int amap_fd, int stack_trace_len);
|
|
|
|
int extract_build_id(char *build_id, size_t size);
|
2019-03-02 03:42:18 +00:00
|
|
|
void *spin_lock_thread(void *arg);
|
2019-07-16 12:58:27 +00:00
|
|
|
|
|
|
|
#ifdef __x86_64__
|
|
|
|
#define SYS_NANOSLEEP_KPROBE_NAME "__x64_sys_nanosleep"
|
|
|
|
#elif defined(__s390x__)
|
|
|
|
#define SYS_NANOSLEEP_KPROBE_NAME "__s390x_sys_nanosleep"
|
|
|
|
#else
|
|
|
|
#define SYS_NANOSLEEP_KPROBE_NAME "sys_nanosleep"
|
|
|
|
#endif
|