/* SPDX-License-Identifier: GPL-2.0 */ #include #include #include #include #include #include #include #include #include #include typedef __u16 __sum16; #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "test_iptunnel_common.h" #include "bpf_util.h" #include "bpf_endian.h" #include "trace_helpers.h" #include "flow_dissector_load.h" struct prog_test_def; struct test_selector { const char *name; bool *num_set; int num_set_len; }; struct test_env { struct test_selector test_selector; struct test_selector subtest_selector; bool verifier_stats; bool verbose; bool very_verbose; bool jit_enabled; struct prog_test_def *test; char *log_buf; size_t log_cnt; size_t log_cap; int succ_cnt; /* successful tests */ int sub_succ_cnt; /* successful sub-tests */ int fail_cnt; /* total failed tests + sub-tests */ }; extern int error_cnt; extern int pass_cnt; extern struct test_env env; extern void test__printf(const char *fmt, ...); extern void test__vprintf(const char *fmt, va_list args); extern void test__force_log(); extern bool test__start_subtest(const char *name); #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); \ if (__ret) { \ error_cnt++; \ test__printf("%s:FAIL:%s ", __func__, tag); \ test__printf(format); \ } else { \ pass_cnt++; \ test__printf("%s:PASS:%s %d nsec\n", \ __func__, tag, duration); \ } \ __ret; \ }) #define CHECK(condition, tag, format...) \ _CHECK(condition, tag, duration, format) #define CHECK_ATTR(condition, tag, format...) \ _CHECK(condition, tag, tattr.duration, format) #define MAGIC_VAL 0x1234 #define NUM_ITER 100000 #define VIP_NUM 5 static inline __u64 ptr_to_u64(const void *ptr) { return (__u64) (unsigned long) ptr; } int bpf_find_map(const char *test, struct bpf_object *obj, const char *name); 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); void *spin_lock_thread(void *arg); #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