1 /* SPDX-License-Identifier: GPL-2.0 */
12 #include <linux/types.h>
13 typedef __u16 __sum16;
14 #include <arpa/inet.h>
15 #include <linux/if_ether.h>
16 #include <linux/if_packet.h>
18 #include <linux/ipv6.h>
19 #include <netinet/tcp.h>
20 #include <linux/filter.h>
21 #include <linux/perf_event.h>
22 #include <linux/socket.h>
23 #include <linux/unistd.h>
25 #include <sys/ioctl.h>
27 #include <sys/types.h>
31 #include <linux/bpf.h>
32 #include <linux/err.h>
34 #include <bpf/libbpf.h>
36 #include "test_iptunnel_common.h"
38 #include <bpf/bpf_endian.h>
39 #include "trace_helpers.h"
40 #include "testing_helpers.h"
41 #include "flow_dissector_load.h"
55 struct test_selector {
56 struct str_set whitelist;
57 struct str_set blacklist;
63 struct test_selector test_selector;
64 struct test_selector subtest_selector;
66 enum verbosity verbosity;
72 struct prog_test_def *test;
79 int succ_cnt; /* successful tests */
80 int sub_succ_cnt; /* successful sub-tests */
81 int fail_cnt; /* total failed tests + sub-tests */
82 int skip_cnt; /* skipped tests */
87 extern struct test_env env;
89 extern void test__force_log();
90 extern bool test__start_subtest(const char *name);
91 extern void test__skip(void);
92 extern void test__fail(void);
93 extern int test__join_cgroup(const char *path);
95 #define PRINT_FAIL(format...) \
98 fprintf(stdout, "%s:FAIL:%d ", __func__, __LINE__); \
99 fprintf(stdout, ##format); \
102 #define _CHECK(condition, tag, duration, format...) ({ \
103 int __ret = !!(condition); \
104 int __save_errno = errno; \
107 fprintf(stdout, "%s:FAIL:%s ", __func__, tag); \
108 fprintf(stdout, ##format); \
110 fprintf(stdout, "%s:PASS:%s %d nsec\n", \
111 __func__, tag, duration); \
113 errno = __save_errno; \
117 #define CHECK_FAIL(condition) ({ \
118 int __ret = !!(condition); \
119 int __save_errno = errno; \
122 fprintf(stdout, "%s:FAIL:%d\n", __func__, __LINE__); \
124 errno = __save_errno; \
128 #define CHECK(condition, tag, format...) \
129 _CHECK(condition, tag, duration, format)
130 #define CHECK_ATTR(condition, tag, format...) \
131 _CHECK(condition, tag, tattr.duration, format)
133 static inline __u64 ptr_to_u64(const void *ptr)
135 return (__u64) (unsigned long) ptr;
138 static inline void *u64_to_ptr(__u64 ptr)
140 return (void *) (unsigned long) ptr;
143 int bpf_find_map(const char *test, struct bpf_object *obj, const char *name);
144 int compare_map_keys(int map1_fd, int map2_fd);
145 int compare_stack_ips(int smap_fd, int amap_fd, int stack_trace_len);
146 int extract_build_id(char *build_id, size_t size);
149 #define SYS_NANOSLEEP_KPROBE_NAME "__x64_sys_nanosleep"
150 #elif defined(__s390x__)
151 #define SYS_NANOSLEEP_KPROBE_NAME "__s390x_sys_nanosleep"
153 #define SYS_NANOSLEEP_KPROBE_NAME "sys_nanosleep"