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>
|
|
|
|
#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"
|
2020-01-20 13:06:45 +00:00
|
|
|
#include <bpf/bpf_endian.h>
|
2019-03-02 03:42:13 +00:00
|
|
|
#include "trace_helpers.h"
|
2020-05-12 19:24:42 +00:00
|
|
|
#include "testing_helpers.h"
|
2019-03-02 03:42:13 +00:00
|
|
|
#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;
|
2020-12-03 20:46:26 +00:00
|
|
|
bool has_testmod;
|
2020-07-01 21:44:12 +00:00
|
|
|
bool get_test_cnt;
|
2020-07-01 21:44:17 +00:00
|
|
|
bool list_test_names;
|
2019-07-28 03:25:28 +00:00
|
|
|
|
|
|
|
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;
|
2020-03-14 01:39:32 +00:00
|
|
|
int nr_cpus;
|
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
|
|
|
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 */
|
2020-07-02 00:48:58 +00:00
|
|
|
|
|
|
|
int saved_netns_fd;
|
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
|
|
|
|
selftests/bpf: Add cls_redirect classifier
cls_redirect is a TC clsact based replacement for the glb-redirect iptables
module available at [1]. It enables what GitHub calls "second chance"
flows [2], similarly proposed by the Beamer paper [3]. In contrast to
glb-redirect, it also supports migrating UDP flows as long as connected
sockets are used. cls_redirect is in production at Cloudflare, as part of
our own L4 load balancer.
We have modified the encapsulation format slightly from glb-redirect:
glbgue_chained_routing.private_data_type has been repurposed to form a
version field and several flags. Both have been arranged in a way that
a private_data_type value of zero matches the current glb-redirect
behaviour. This means that cls_redirect will understand packets in
glb-redirect format, but not vice versa.
The test suite only covers basic features. For example, cls_redirect will
correctly forward path MTU discovery packets, but this is not exercised.
It is also possible to switch the encapsulation format to GRE on the last
hop, which is also not tested.
There are two major distinctions from glb-redirect: first, cls_redirect
relies on receiving encapsulated packets directly from a router. This is
because we don't have access to the neighbour tables from BPF, yet. See
forward_to_next_hop for details. Second, cls_redirect performs decapsulation
instead of using separate ipip and sit tunnel devices. This
avoids issues with the sit tunnel [4] and makes deploying the classifier
easier: decapsulated packets appear on the same interface, so existing
firewall rules continue to work as expected.
The code base started it's life on v4.19, so there are most likely still
hold overs from old workarounds. In no particular order:
- The function buf_off is required to defeat a clang optimization
that leads to the verifier rejecting the program due to pointer
arithmetic in the wrong order.
- The function pkt_parse_ipv6 is force inlined, because it would
otherwise be rejected due to returning a pointer to stack memory.
- The functions fill_tuple and classify_tcp contain kludges, because
we've run out of function arguments.
- The logic in general is rather nested, due to verifier restrictions.
I think this is either because the verifier loses track of constants
on the stack, or because it can't track enum like variables.
1: https://github.com/github/glb-director/tree/master/src/glb-redirect
2: https://github.com/github/glb-director/blob/master/docs/development/second-chance-design.md
3: https://www.usenix.org/conference/nsdi18/presentation/olteanu
4: https://github.com/github/glb-director/issues/64
Signed-off-by: Lorenz Bauer <lmb@cloudflare.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200424185556.7358-2-lmb@cloudflare.com
2020-04-24 18:55:55 +00:00
|
|
|
#define PRINT_FAIL(format...) \
|
|
|
|
({ \
|
|
|
|
test__fail(); \
|
|
|
|
fprintf(stdout, "%s:FAIL:%d ", __func__, __LINE__); \
|
|
|
|
fprintf(stdout, ##format); \
|
|
|
|
})
|
|
|
|
|
2019-03-02 03:42:13 +00:00
|
|
|
#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(); \
|
2020-03-13 17:23:33 +00:00
|
|
|
fprintf(stdout, "%s:FAIL:%s ", __func__, tag); \
|
|
|
|
fprintf(stdout, ##format); \
|
2019-03-02 03:42:13 +00:00
|
|
|
} else { \
|
2020-03-13 17:23:33 +00:00
|
|
|
fprintf(stdout, "%s:PASS:%s %d nsec\n", \
|
2019-08-06 17:45:28 +00:00
|
|
|
__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(); \
|
2020-03-13 17:23:33 +00:00
|
|
|
fprintf(stdout, "%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)
|
|
|
|
|
2021-04-26 19:29:45 +00:00
|
|
|
#define ASSERT_TRUE(actual, name) ({ \
|
|
|
|
static int duration = 0; \
|
|
|
|
bool ___ok = (actual); \
|
|
|
|
CHECK(!___ok, (name), "unexpected %s: got FALSE\n", (name)); \
|
|
|
|
___ok; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define ASSERT_FALSE(actual, name) ({ \
|
|
|
|
static int duration = 0; \
|
|
|
|
bool ___ok = !(actual); \
|
|
|
|
CHECK(!___ok, (name), "unexpected %s: got TRUE\n", (name)); \
|
|
|
|
___ok; \
|
|
|
|
})
|
|
|
|
|
2020-09-29 04:30:44 +00:00
|
|
|
#define ASSERT_EQ(actual, expected, name) ({ \
|
|
|
|
static int duration = 0; \
|
|
|
|
typeof(actual) ___act = (actual); \
|
|
|
|
typeof(expected) ___exp = (expected); \
|
|
|
|
bool ___ok = ___act == ___exp; \
|
|
|
|
CHECK(!___ok, (name), \
|
|
|
|
"unexpected %s: actual %lld != expected %lld\n", \
|
|
|
|
(name), (long long)(___act), (long long)(___exp)); \
|
|
|
|
___ok; \
|
|
|
|
})
|
|
|
|
|
2020-11-05 04:33:55 +00:00
|
|
|
#define ASSERT_NEQ(actual, expected, name) ({ \
|
|
|
|
static int duration = 0; \
|
|
|
|
typeof(actual) ___act = (actual); \
|
|
|
|
typeof(expected) ___exp = (expected); \
|
|
|
|
bool ___ok = ___act != ___exp; \
|
|
|
|
CHECK(!___ok, (name), \
|
|
|
|
"unexpected %s: actual %lld == expected %lld\n", \
|
|
|
|
(name), (long long)(___act), (long long)(___exp)); \
|
|
|
|
___ok; \
|
|
|
|
})
|
|
|
|
|
2021-02-26 20:49:33 +00:00
|
|
|
#define ASSERT_LT(actual, expected, name) ({ \
|
|
|
|
static int duration = 0; \
|
|
|
|
typeof(actual) ___act = (actual); \
|
|
|
|
typeof(expected) ___exp = (expected); \
|
|
|
|
bool ___ok = ___act < ___exp; \
|
|
|
|
CHECK(!___ok, (name), \
|
|
|
|
"unexpected %s: actual %lld >= expected %lld\n", \
|
|
|
|
(name), (long long)(___act), (long long)(___exp)); \
|
|
|
|
___ok; \
|
|
|
|
})
|
|
|
|
|
2021-04-26 19:29:45 +00:00
|
|
|
#define ASSERT_LE(actual, expected, name) ({ \
|
|
|
|
static int duration = 0; \
|
|
|
|
typeof(actual) ___act = (actual); \
|
|
|
|
typeof(expected) ___exp = (expected); \
|
|
|
|
bool ___ok = ___act <= ___exp; \
|
|
|
|
CHECK(!___ok, (name), \
|
|
|
|
"unexpected %s: actual %lld > expected %lld\n", \
|
|
|
|
(name), (long long)(___act), (long long)(___exp)); \
|
|
|
|
___ok; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define ASSERT_GT(actual, expected, name) ({ \
|
|
|
|
static int duration = 0; \
|
|
|
|
typeof(actual) ___act = (actual); \
|
|
|
|
typeof(expected) ___exp = (expected); \
|
|
|
|
bool ___ok = ___act > ___exp; \
|
|
|
|
CHECK(!___ok, (name), \
|
|
|
|
"unexpected %s: actual %lld <= expected %lld\n", \
|
|
|
|
(name), (long long)(___act), (long long)(___exp)); \
|
|
|
|
___ok; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define ASSERT_GE(actual, expected, name) ({ \
|
|
|
|
static int duration = 0; \
|
|
|
|
typeof(actual) ___act = (actual); \
|
|
|
|
typeof(expected) ___exp = (expected); \
|
|
|
|
bool ___ok = ___act >= ___exp; \
|
|
|
|
CHECK(!___ok, (name), \
|
|
|
|
"unexpected %s: actual %lld < expected %lld\n", \
|
|
|
|
(name), (long long)(___act), (long long)(___exp)); \
|
|
|
|
___ok; \
|
|
|
|
})
|
|
|
|
|
2020-09-29 04:30:44 +00:00
|
|
|
#define ASSERT_STREQ(actual, expected, name) ({ \
|
|
|
|
static int duration = 0; \
|
|
|
|
const char *___act = actual; \
|
|
|
|
const char *___exp = expected; \
|
|
|
|
bool ___ok = strcmp(___act, ___exp) == 0; \
|
|
|
|
CHECK(!___ok, (name), \
|
|
|
|
"unexpected %s: actual '%s' != expected '%s'\n", \
|
|
|
|
(name), ___act, ___exp); \
|
|
|
|
___ok; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define ASSERT_OK(res, name) ({ \
|
|
|
|
static int duration = 0; \
|
|
|
|
long long ___res = (res); \
|
|
|
|
bool ___ok = ___res == 0; \
|
2021-04-26 19:29:45 +00:00
|
|
|
CHECK(!___ok, (name), "unexpected error: %lld (errno %d)\n", \
|
|
|
|
___res, errno); \
|
2020-09-29 04:30:44 +00:00
|
|
|
___ok; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define ASSERT_ERR(res, name) ({ \
|
|
|
|
static int duration = 0; \
|
|
|
|
long long ___res = (res); \
|
|
|
|
bool ___ok = ___res < 0; \
|
|
|
|
CHECK(!___ok, (name), "unexpected success: %lld\n", ___res); \
|
|
|
|
___ok; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define ASSERT_NULL(ptr, name) ({ \
|
|
|
|
static int duration = 0; \
|
|
|
|
const void *___res = (ptr); \
|
|
|
|
bool ___ok = !___res; \
|
|
|
|
CHECK(!___ok, (name), "unexpected pointer: %p\n", ___res); \
|
|
|
|
___ok; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define ASSERT_OK_PTR(ptr, name) ({ \
|
|
|
|
static int duration = 0; \
|
|
|
|
const void *___res = (ptr); \
|
|
|
|
bool ___ok = !IS_ERR_OR_NULL(___res); \
|
|
|
|
CHECK(!___ok, (name), \
|
|
|
|
"unexpected error: %ld\n", PTR_ERR(___res)); \
|
|
|
|
___ok; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define ASSERT_ERR_PTR(ptr, name) ({ \
|
|
|
|
static int duration = 0; \
|
|
|
|
const void *___res = (ptr); \
|
2021-04-14 15:56:32 +00:00
|
|
|
bool ___ok = IS_ERR(___res); \
|
2020-09-29 04:30:44 +00:00
|
|
|
CHECK(!___ok, (name), "unexpected pointer: %p\n", ___res); \
|
|
|
|
___ok; \
|
|
|
|
})
|
|
|
|
|
2019-03-02 03:42:19 +00:00
|
|
|
static inline __u64 ptr_to_u64(const void *ptr)
|
|
|
|
{
|
|
|
|
return (__u64) (unsigned long) ptr;
|
|
|
|
}
|
|
|
|
|
2020-08-13 20:49:38 +00:00
|
|
|
static inline void *u64_to_ptr(__u64 ptr)
|
|
|
|
{
|
|
|
|
return (void *) (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);
|
2021-01-12 07:55:17 +00:00
|
|
|
int kern_sync_rcu(void);
|
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
|