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