1 // SPDX-License-Identifier: GPL-2.0 2 #include <test_progs.h> 3 4 static int libbpf_debug_print(enum libbpf_print_level level, 5 const char *format, va_list args) 6 { 7 if (level == LIBBPF_DEBUG) 8 return 0; 9 10 return vfprintf(stderr, format, args); 11 } 12 13 void test_reference_tracking(void) 14 { 15 const char *file = "./test_sk_lookup_kern.o"; 16 struct bpf_object *obj; 17 struct bpf_program *prog; 18 __u32 duration = 0; 19 int err = 0; 20 21 obj = bpf_object__open(file); 22 if (IS_ERR(obj)) { 23 error_cnt++; 24 return; 25 } 26 27 bpf_object__for_each_program(prog, obj) { 28 const char *title; 29 30 /* Ignore .text sections */ 31 title = bpf_program__title(prog, false); 32 if (strstr(title, ".text") != NULL) 33 continue; 34 35 bpf_program__set_type(prog, BPF_PROG_TYPE_SCHED_CLS); 36 37 /* Expect verifier failure if test name has 'fail' */ 38 if (strstr(title, "fail") != NULL) { 39 libbpf_set_print(NULL); 40 err = !bpf_program__load(prog, "GPL", 0); 41 libbpf_set_print(libbpf_debug_print); 42 } else { 43 err = bpf_program__load(prog, "GPL", 0); 44 } 45 CHECK(err, title, "\n"); 46 } 47 bpf_object__close(obj); 48 } 49