xref: /openbmc/linux/tools/testing/selftests/bpf/test_progs.h (revision 2324257dbd6889638c6cba1ade9eeac3224e2043)
13f306588SStanislav Fomichev /* SPDX-License-Identifier: GPL-2.0 */
23f306588SStanislav Fomichev #include <stdio.h>
33f306588SStanislav Fomichev #include <unistd.h>
43f306588SStanislav Fomichev #include <errno.h>
53f306588SStanislav Fomichev #include <string.h>
63f306588SStanislav Fomichev #include <assert.h>
73f306588SStanislav Fomichev #include <stdlib.h>
83f306588SStanislav Fomichev #include <stdarg.h>
93f306588SStanislav Fomichev #include <time.h>
103f306588SStanislav Fomichev #include <signal.h>
113f306588SStanislav Fomichev 
123f306588SStanislav Fomichev #include <linux/types.h>
133f306588SStanislav Fomichev typedef __u16 __sum16;
143f306588SStanislav Fomichev #include <arpa/inet.h>
153f306588SStanislav Fomichev #include <linux/if_ether.h>
163f306588SStanislav Fomichev #include <linux/if_packet.h>
173f306588SStanislav Fomichev #include <linux/ip.h>
183f306588SStanislav Fomichev #include <linux/ipv6.h>
193f306588SStanislav Fomichev #include <linux/filter.h>
203f306588SStanislav Fomichev #include <linux/perf_event.h>
219a365e67SStanislav Fomichev #include <linux/socket.h>
223f306588SStanislav Fomichev #include <linux/unistd.h>
233f306588SStanislav Fomichev 
243f306588SStanislav Fomichev #include <sys/ioctl.h>
253f306588SStanislav Fomichev #include <sys/wait.h>
263f306588SStanislav Fomichev #include <sys/types.h>
273f306588SStanislav Fomichev #include <sys/time.h>
28f4fd706fSGeliang Tang #include <sys/param.h>
293f306588SStanislav Fomichev #include <fcntl.h>
303f306588SStanislav Fomichev #include <pthread.h>
313f306588SStanislav Fomichev #include <linux/bpf.h>
323f306588SStanislav Fomichev #include <linux/err.h>
333f306588SStanislav Fomichev #include <bpf/bpf.h>
343f306588SStanislav Fomichev #include <bpf/libbpf.h>
353f306588SStanislav Fomichev 
363f306588SStanislav Fomichev #include "test_iptunnel_common.h"
373f306588SStanislav Fomichev #include "bpf_util.h"
383e689141SToke Høiland-Jørgensen #include <bpf/bpf_endian.h>
393f306588SStanislav Fomichev #include "trace_helpers.h"
40cd49291cSAndrii Nakryiko #include "testing_helpers.h"
413f306588SStanislav Fomichev 
42a8fdaad5SAndrii Nakryiko enum verbosity {
43a8fdaad5SAndrii Nakryiko 	VERBOSE_NONE,
44a8fdaad5SAndrii Nakryiko 	VERBOSE_NORMAL,
45a8fdaad5SAndrii Nakryiko 	VERBOSE_VERY,
46a8fdaad5SAndrii Nakryiko 	VERBOSE_SUPER,
47a8fdaad5SAndrii Nakryiko };
48a8fdaad5SAndrii Nakryiko 
4961ddff37SMykola Lysenko struct test_filter {
5061ddff37SMykola Lysenko 	char *name;
5161ddff37SMykola Lysenko 	char **subtests;
5261ddff37SMykola Lysenko 	int subtest_cnt;
5361ddff37SMykola Lysenko };
5461ddff37SMykola Lysenko 
5561ddff37SMykola Lysenko struct test_filter_set {
5661ddff37SMykola Lysenko 	struct test_filter *tests;
57b65053cdSAndrii Nakryiko 	int cnt;
58b65053cdSAndrii Nakryiko };
59b65053cdSAndrii Nakryiko 
603a516a0aSAndrii Nakryiko struct test_selector {
6161ddff37SMykola Lysenko 	struct test_filter_set whitelist;
6261ddff37SMykola Lysenko 	struct test_filter_set blacklist;
633a516a0aSAndrii Nakryiko 	bool *num_set;
643a516a0aSAndrii Nakryiko 	int num_set_len;
653a516a0aSAndrii Nakryiko };
663a516a0aSAndrii Nakryiko 
67*2324257dSMykola Lysenko struct test_state {
68*2324257dSMykola Lysenko 	bool tested;
69*2324257dSMykola Lysenko 	bool force_log;
70*2324257dSMykola Lysenko 
71*2324257dSMykola Lysenko 	int error_cnt;
72*2324257dSMykola Lysenko 	int skip_cnt;
73*2324257dSMykola Lysenko 	int subtest_skip_cnt;
74*2324257dSMykola Lysenko 	int sub_succ_cnt;
75*2324257dSMykola Lysenko 
76*2324257dSMykola Lysenko 	char *subtest_name;
77*2324257dSMykola Lysenko 	int subtest_num;
78*2324257dSMykola Lysenko 
79*2324257dSMykola Lysenko 	/* store counts before subtest started */
80*2324257dSMykola Lysenko 	int old_error_cnt;
81*2324257dSMykola Lysenko 
82*2324257dSMykola Lysenko 	size_t log_cnt;
83*2324257dSMykola Lysenko 	char *log_buf;
84*2324257dSMykola Lysenko };
85*2324257dSMykola Lysenko 
860ff97e56SAndrii Nakryiko struct test_env {
873a516a0aSAndrii Nakryiko 	struct test_selector test_selector;
883a516a0aSAndrii Nakryiko 	struct test_selector subtest_selector;
890ff97e56SAndrii Nakryiko 	bool verifier_stats;
9091b2c0afSYucong Sun 	bool debug;
91a8fdaad5SAndrii Nakryiko 	enum verbosity verbosity;
920ff97e56SAndrii Nakryiko 
930ff97e56SAndrii Nakryiko 	bool jit_enabled;
949f7fa225SAndrii Nakryiko 	bool has_testmod;
95643e7233SJesper Dangaard Brouer 	bool get_test_cnt;
96c1f1f365SJesper Dangaard Brouer 	bool list_test_names;
970ff97e56SAndrii Nakryiko 
98*2324257dSMykola Lysenko 	struct prog_test_def *test; /* current running test */
99*2324257dSMykola Lysenko 	struct test_state *test_state; /* current running test result */
10091b2c0afSYucong Sun 
101946152b3SStanislav Fomichev 	FILE *stdout;
102946152b3SStanislav Fomichev 	FILE *stderr;
103fd27b183SAndrii Nakryiko 	int nr_cpus;
1040ff97e56SAndrii Nakryiko 
1053a516a0aSAndrii Nakryiko 	int succ_cnt; /* successful tests */
1063a516a0aSAndrii Nakryiko 	int sub_succ_cnt; /* successful sub-tests */
1073a516a0aSAndrii Nakryiko 	int fail_cnt; /* total failed tests + sub-tests */
108cd9c21d7SStanislav Fomichev 	int skip_cnt; /* skipped tests */
109811d7e37SMartin KaFai Lau 
110811d7e37SMartin KaFai Lau 	int saved_netns_fd;
11191b2c0afSYucong Sun 	int workers; /* number of worker process */
11291b2c0afSYucong Sun 	int worker_id; /* id number of current worker, main process is -1 */
11391b2c0afSYucong Sun 	pid_t *worker_pids; /* array of worker pids */
11491b2c0afSYucong Sun 	int *worker_socks; /* array of worker socks */
11591b2c0afSYucong Sun 	int *worker_current_test; /* array of current running test for each worker */
11691b2c0afSYucong Sun };
11791b2c0afSYucong Sun 
11891b2c0afSYucong Sun #define MAX_LOG_TRUNK_SIZE 8192
11991b2c0afSYucong Sun enum msg_type {
12091b2c0afSYucong Sun 	MSG_DO_TEST = 0,
12191b2c0afSYucong Sun 	MSG_TEST_DONE = 1,
12291b2c0afSYucong Sun 	MSG_TEST_LOG = 2,
12391b2c0afSYucong Sun 	MSG_EXIT = 255,
12491b2c0afSYucong Sun };
12591b2c0afSYucong Sun struct msg {
12691b2c0afSYucong Sun 	enum msg_type type;
12791b2c0afSYucong Sun 	union {
12891b2c0afSYucong Sun 		struct {
12991b2c0afSYucong Sun 			int test_num;
13091b2c0afSYucong Sun 		} do_test;
13191b2c0afSYucong Sun 		struct {
13291b2c0afSYucong Sun 			int test_num;
13391b2c0afSYucong Sun 			int sub_succ_cnt;
13491b2c0afSYucong Sun 			int error_cnt;
13591b2c0afSYucong Sun 			int skip_cnt;
13691b2c0afSYucong Sun 			bool have_log;
13791b2c0afSYucong Sun 		} test_done;
13891b2c0afSYucong Sun 		struct {
13991b2c0afSYucong Sun 			char log_buf[MAX_LOG_TRUNK_SIZE + 1];
14091b2c0afSYucong Sun 			bool is_last;
14191b2c0afSYucong Sun 		} test_log;
14291b2c0afSYucong Sun 	};
1430ff97e56SAndrii Nakryiko };
1440ff97e56SAndrii Nakryiko 
1450ff97e56SAndrii Nakryiko extern struct test_env env;
1460ff97e56SAndrii Nakryiko 
147*2324257dSMykola Lysenko void test__force_log(void);
148*2324257dSMykola Lysenko bool test__start_subtest(const char *name);
149*2324257dSMykola Lysenko void test__end_subtest(void);
150*2324257dSMykola Lysenko void test__skip(void);
151*2324257dSMykola Lysenko void test__fail(void);
152*2324257dSMykola Lysenko int test__join_cgroup(const char *path);
1533f306588SStanislav Fomichev 
15423458901SLorenz Bauer #define PRINT_FAIL(format...)                                                  \
15523458901SLorenz Bauer 	({                                                                     \
15623458901SLorenz Bauer 		test__fail();                                                  \
15723458901SLorenz Bauer 		fprintf(stdout, "%s:FAIL:%d ", __func__, __LINE__);            \
15823458901SLorenz Bauer 		fprintf(stdout, ##format);                                     \
15923458901SLorenz Bauer 	})
16023458901SLorenz Bauer 
1613f306588SStanislav Fomichev #define _CHECK(condition, tag, duration, format...) ({			\
1623f306588SStanislav Fomichev 	int __ret = !!(condition);					\
163478bee0dSAndrey Ignatov 	int __save_errno = errno;					\
1643f306588SStanislav Fomichev 	if (__ret) {							\
165d38835b7SStanislav Fomichev 		test__fail();						\
1663e2671fbSAndrii Nakryiko 		fprintf(stdout, "%s:FAIL:%s ", __func__, tag);		\
1673e2671fbSAndrii Nakryiko 		fprintf(stdout, ##format);				\
1683f306588SStanislav Fomichev 	} else {							\
1693e2671fbSAndrii Nakryiko 		fprintf(stdout, "%s:PASS:%s %d nsec\n",			\
1700ff97e56SAndrii Nakryiko 		       __func__, tag, duration);			\
1713f306588SStanislav Fomichev 	}								\
172478bee0dSAndrey Ignatov 	errno = __save_errno;						\
1733f306588SStanislav Fomichev 	__ret;								\
1743f306588SStanislav Fomichev })
1753f306588SStanislav Fomichev 
176d38835b7SStanislav Fomichev #define CHECK_FAIL(condition) ({					\
177d38835b7SStanislav Fomichev 	int __ret = !!(condition);					\
178478bee0dSAndrey Ignatov 	int __save_errno = errno;					\
179d38835b7SStanislav Fomichev 	if (__ret) {							\
180d38835b7SStanislav Fomichev 		test__fail();						\
1813e2671fbSAndrii Nakryiko 		fprintf(stdout, "%s:FAIL:%d\n", __func__, __LINE__);	\
182d38835b7SStanislav Fomichev 	}								\
183478bee0dSAndrey Ignatov 	errno = __save_errno;						\
184d38835b7SStanislav Fomichev 	__ret;								\
185d38835b7SStanislav Fomichev })
186d38835b7SStanislav Fomichev 
1873f306588SStanislav Fomichev #define CHECK(condition, tag, format...) \
1883f306588SStanislav Fomichev 	_CHECK(condition, tag, duration, format)
1893f306588SStanislav Fomichev #define CHECK_ATTR(condition, tag, format...) \
1903f306588SStanislav Fomichev 	_CHECK(condition, tag, tattr.duration, format)
1913f306588SStanislav Fomichev 
1927a2fa70aSAndrii Nakryiko #define ASSERT_TRUE(actual, name) ({					\
1937a2fa70aSAndrii Nakryiko 	static int duration = 0;					\
1947a2fa70aSAndrii Nakryiko 	bool ___ok = (actual);						\
1957a2fa70aSAndrii Nakryiko 	CHECK(!___ok, (name), "unexpected %s: got FALSE\n", (name));	\
1967a2fa70aSAndrii Nakryiko 	___ok;								\
1977a2fa70aSAndrii Nakryiko })
1987a2fa70aSAndrii Nakryiko 
1997a2fa70aSAndrii Nakryiko #define ASSERT_FALSE(actual, name) ({					\
2007a2fa70aSAndrii Nakryiko 	static int duration = 0;					\
2017a2fa70aSAndrii Nakryiko 	bool ___ok = !(actual);						\
2027a2fa70aSAndrii Nakryiko 	CHECK(!___ok, (name), "unexpected %s: got TRUE\n", (name));	\
2037a2fa70aSAndrii Nakryiko 	___ok;								\
2047a2fa70aSAndrii Nakryiko })
2057a2fa70aSAndrii Nakryiko 
20622ba3635SAndrii Nakryiko #define ASSERT_EQ(actual, expected, name) ({				\
20722ba3635SAndrii Nakryiko 	static int duration = 0;					\
20822ba3635SAndrii Nakryiko 	typeof(actual) ___act = (actual);				\
20922ba3635SAndrii Nakryiko 	typeof(expected) ___exp = (expected);				\
21022ba3635SAndrii Nakryiko 	bool ___ok = ___act == ___exp;					\
21122ba3635SAndrii Nakryiko 	CHECK(!___ok, (name),						\
21222ba3635SAndrii Nakryiko 	      "unexpected %s: actual %lld != expected %lld\n",		\
21322ba3635SAndrii Nakryiko 	      (name), (long long)(___act), (long long)(___exp));	\
21422ba3635SAndrii Nakryiko 	___ok;								\
21522ba3635SAndrii Nakryiko })
21622ba3635SAndrii Nakryiko 
217197389daSAndrii Nakryiko #define ASSERT_NEQ(actual, expected, name) ({				\
218197389daSAndrii Nakryiko 	static int duration = 0;					\
219197389daSAndrii Nakryiko 	typeof(actual) ___act = (actual);				\
220197389daSAndrii Nakryiko 	typeof(expected) ___exp = (expected);				\
221197389daSAndrii Nakryiko 	bool ___ok = ___act != ___exp;					\
222197389daSAndrii Nakryiko 	CHECK(!___ok, (name),						\
223197389daSAndrii Nakryiko 	      "unexpected %s: actual %lld == expected %lld\n",		\
224197389daSAndrii Nakryiko 	      (name), (long long)(___act), (long long)(___exp));	\
225197389daSAndrii Nakryiko 	___ok;								\
226197389daSAndrii Nakryiko })
227197389daSAndrii Nakryiko 
2289de7f0fdSYonghong Song #define ASSERT_LT(actual, expected, name) ({				\
2299de7f0fdSYonghong Song 	static int duration = 0;					\
2309de7f0fdSYonghong Song 	typeof(actual) ___act = (actual);				\
2319de7f0fdSYonghong Song 	typeof(expected) ___exp = (expected);				\
2329de7f0fdSYonghong Song 	bool ___ok = ___act < ___exp;					\
2339de7f0fdSYonghong Song 	CHECK(!___ok, (name),						\
2349de7f0fdSYonghong Song 	      "unexpected %s: actual %lld >= expected %lld\n",		\
2359de7f0fdSYonghong Song 	      (name), (long long)(___act), (long long)(___exp));	\
2369de7f0fdSYonghong Song 	___ok;								\
2379de7f0fdSYonghong Song })
2389de7f0fdSYonghong Song 
2397a2fa70aSAndrii Nakryiko #define ASSERT_LE(actual, expected, name) ({				\
2407a2fa70aSAndrii Nakryiko 	static int duration = 0;					\
2417a2fa70aSAndrii Nakryiko 	typeof(actual) ___act = (actual);				\
2427a2fa70aSAndrii Nakryiko 	typeof(expected) ___exp = (expected);				\
2437a2fa70aSAndrii Nakryiko 	bool ___ok = ___act <= ___exp;					\
2447a2fa70aSAndrii Nakryiko 	CHECK(!___ok, (name),						\
2457a2fa70aSAndrii Nakryiko 	      "unexpected %s: actual %lld > expected %lld\n",		\
2467a2fa70aSAndrii Nakryiko 	      (name), (long long)(___act), (long long)(___exp));	\
2477a2fa70aSAndrii Nakryiko 	___ok;								\
2487a2fa70aSAndrii Nakryiko })
2497a2fa70aSAndrii Nakryiko 
2507a2fa70aSAndrii Nakryiko #define ASSERT_GT(actual, expected, name) ({				\
2517a2fa70aSAndrii Nakryiko 	static int duration = 0;					\
2527a2fa70aSAndrii Nakryiko 	typeof(actual) ___act = (actual);				\
2537a2fa70aSAndrii Nakryiko 	typeof(expected) ___exp = (expected);				\
2547a2fa70aSAndrii Nakryiko 	bool ___ok = ___act > ___exp;					\
2557a2fa70aSAndrii Nakryiko 	CHECK(!___ok, (name),						\
2567a2fa70aSAndrii Nakryiko 	      "unexpected %s: actual %lld <= expected %lld\n",		\
2577a2fa70aSAndrii Nakryiko 	      (name), (long long)(___act), (long long)(___exp));	\
2587a2fa70aSAndrii Nakryiko 	___ok;								\
2597a2fa70aSAndrii Nakryiko })
2607a2fa70aSAndrii Nakryiko 
2617a2fa70aSAndrii Nakryiko #define ASSERT_GE(actual, expected, name) ({				\
2627a2fa70aSAndrii Nakryiko 	static int duration = 0;					\
2637a2fa70aSAndrii Nakryiko 	typeof(actual) ___act = (actual);				\
2647a2fa70aSAndrii Nakryiko 	typeof(expected) ___exp = (expected);				\
2657a2fa70aSAndrii Nakryiko 	bool ___ok = ___act >= ___exp;					\
2667a2fa70aSAndrii Nakryiko 	CHECK(!___ok, (name),						\
2677a2fa70aSAndrii Nakryiko 	      "unexpected %s: actual %lld < expected %lld\n",		\
2687a2fa70aSAndrii Nakryiko 	      (name), (long long)(___act), (long long)(___exp));	\
2697a2fa70aSAndrii Nakryiko 	___ok;								\
2707a2fa70aSAndrii Nakryiko })
2717a2fa70aSAndrii Nakryiko 
27222ba3635SAndrii Nakryiko #define ASSERT_STREQ(actual, expected, name) ({				\
27322ba3635SAndrii Nakryiko 	static int duration = 0;					\
27422ba3635SAndrii Nakryiko 	const char *___act = actual;					\
27522ba3635SAndrii Nakryiko 	const char *___exp = expected;					\
27622ba3635SAndrii Nakryiko 	bool ___ok = strcmp(___act, ___exp) == 0;			\
27722ba3635SAndrii Nakryiko 	CHECK(!___ok, (name),						\
27822ba3635SAndrii Nakryiko 	      "unexpected %s: actual '%s' != expected '%s'\n",		\
27922ba3635SAndrii Nakryiko 	      (name), ___act, ___exp);					\
28022ba3635SAndrii Nakryiko 	___ok;								\
28122ba3635SAndrii Nakryiko })
28222ba3635SAndrii Nakryiko 
28317283337SAlan Maguire #define ASSERT_STRNEQ(actual, expected, len, name) ({			\
28417283337SAlan Maguire 	static int duration = 0;					\
28517283337SAlan Maguire 	const char *___act = actual;					\
28617283337SAlan Maguire 	const char *___exp = expected;					\
28717283337SAlan Maguire 	int ___len = len;						\
28817283337SAlan Maguire 	bool ___ok = strncmp(___act, ___exp, ___len) == 0;		\
28917283337SAlan Maguire 	CHECK(!___ok, (name),						\
29017283337SAlan Maguire 	      "unexpected %s: actual '%.*s' != expected '%.*s'\n",	\
29117283337SAlan Maguire 	      (name), ___len, ___act, ___len, ___exp);			\
29217283337SAlan Maguire 	___ok;								\
29317283337SAlan Maguire })
29417283337SAlan Maguire 
29522ba3635SAndrii Nakryiko #define ASSERT_OK(res, name) ({						\
29622ba3635SAndrii Nakryiko 	static int duration = 0;					\
29722ba3635SAndrii Nakryiko 	long long ___res = (res);					\
29822ba3635SAndrii Nakryiko 	bool ___ok = ___res == 0;					\
2997a2fa70aSAndrii Nakryiko 	CHECK(!___ok, (name), "unexpected error: %lld (errno %d)\n",	\
3007a2fa70aSAndrii Nakryiko 	      ___res, errno);						\
30122ba3635SAndrii Nakryiko 	___ok;								\
30222ba3635SAndrii Nakryiko })
30322ba3635SAndrii Nakryiko 
30422ba3635SAndrii Nakryiko #define ASSERT_ERR(res, name) ({					\
30522ba3635SAndrii Nakryiko 	static int duration = 0;					\
30622ba3635SAndrii Nakryiko 	long long ___res = (res);					\
30722ba3635SAndrii Nakryiko 	bool ___ok = ___res < 0;					\
30822ba3635SAndrii Nakryiko 	CHECK(!___ok, (name), "unexpected success: %lld\n", ___res);	\
30922ba3635SAndrii Nakryiko 	___ok;								\
31022ba3635SAndrii Nakryiko })
31122ba3635SAndrii Nakryiko 
31222ba3635SAndrii Nakryiko #define ASSERT_NULL(ptr, name) ({					\
31322ba3635SAndrii Nakryiko 	static int duration = 0;					\
31422ba3635SAndrii Nakryiko 	const void *___res = (ptr);					\
31522ba3635SAndrii Nakryiko 	bool ___ok = !___res;						\
31622ba3635SAndrii Nakryiko 	CHECK(!___ok, (name), "unexpected pointer: %p\n", ___res);	\
31722ba3635SAndrii Nakryiko 	___ok;								\
31822ba3635SAndrii Nakryiko })
31922ba3635SAndrii Nakryiko 
32022ba3635SAndrii Nakryiko #define ASSERT_OK_PTR(ptr, name) ({					\
32122ba3635SAndrii Nakryiko 	static int duration = 0;					\
32222ba3635SAndrii Nakryiko 	const void *___res = (ptr);					\
323bad2e478SAndrii Nakryiko 	int ___err = libbpf_get_error(___res);				\
324bad2e478SAndrii Nakryiko 	bool ___ok = ___err == 0;					\
325bad2e478SAndrii Nakryiko 	CHECK(!___ok, (name), "unexpected error: %d\n", ___err);	\
32622ba3635SAndrii Nakryiko 	___ok;								\
32722ba3635SAndrii Nakryiko })
32822ba3635SAndrii Nakryiko 
32922ba3635SAndrii Nakryiko #define ASSERT_ERR_PTR(ptr, name) ({					\
33022ba3635SAndrii Nakryiko 	static int duration = 0;					\
33122ba3635SAndrii Nakryiko 	const void *___res = (ptr);					\
332bad2e478SAndrii Nakryiko 	int ___err = libbpf_get_error(___res);				\
333bad2e478SAndrii Nakryiko 	bool ___ok = ___err != 0;					\
33422ba3635SAndrii Nakryiko 	CHECK(!___ok, (name), "unexpected pointer: %p\n", ___res);	\
33522ba3635SAndrii Nakryiko 	___ok;								\
33622ba3635SAndrii Nakryiko })
33722ba3635SAndrii Nakryiko 
338886225bbSStanislav Fomichev static inline __u64 ptr_to_u64(const void *ptr)
339886225bbSStanislav Fomichev {
340886225bbSStanislav Fomichev 	return (__u64) (unsigned long) ptr;
341886225bbSStanislav Fomichev }
342886225bbSStanislav Fomichev 
3439028bbccSAndrii Nakryiko static inline void *u64_to_ptr(__u64 ptr)
3449028bbccSAndrii Nakryiko {
3459028bbccSAndrii Nakryiko 	return (void *) (unsigned long) ptr;
3469028bbccSAndrii Nakryiko }
3479028bbccSAndrii Nakryiko 
3483f306588SStanislav Fomichev int bpf_find_map(const char *test, struct bpf_object *obj, const char *name);
349615741d8SStanislav Fomichev int compare_map_keys(int map1_fd, int map2_fd);
350615741d8SStanislav Fomichev int compare_stack_ips(int smap_fd, int amap_fd, int stack_trace_len);
351615741d8SStanislav Fomichev int extract_build_id(char *build_id, size_t size);
352635599baSAndrii Nakryiko int kern_sync_rcu(void);
353025bd7c7SSong Liu int trigger_module_test_read(int read_sz);
354025bd7c7SSong Liu int trigger_module_test_write(int write_sz);
3551cb59a60SIlya Leoshkevich 
3561cb59a60SIlya Leoshkevich #ifdef __x86_64__
3571cb59a60SIlya Leoshkevich #define SYS_NANOSLEEP_KPROBE_NAME "__x64_sys_nanosleep"
3581cb59a60SIlya Leoshkevich #elif defined(__s390x__)
3591cb59a60SIlya Leoshkevich #define SYS_NANOSLEEP_KPROBE_NAME "__s390x_sys_nanosleep"
360d2987617SIlya Leoshkevich #elif defined(__aarch64__)
361d2987617SIlya Leoshkevich #define SYS_NANOSLEEP_KPROBE_NAME "__arm64_sys_nanosleep"
3621cb59a60SIlya Leoshkevich #else
3631cb59a60SIlya Leoshkevich #define SYS_NANOSLEEP_KPROBE_NAME "sys_nanosleep"
3641cb59a60SIlya Leoshkevich #endif
365fa7f17d0SHou Tao 
366fa7f17d0SHou Tao #define BPF_TESTMOD_TEST_FILE "/sys/kernel/bpf_testmod"
367