0001
0002 #include <test_progs.h>
0003
0004 void test_reference_tracking(void)
0005 {
0006 const char *file = "test_sk_lookup_kern.o";
0007 const char *obj_name = "ref_track";
0008 DECLARE_LIBBPF_OPTS(bpf_object_open_opts, open_opts,
0009 .object_name = obj_name,
0010 .relaxed_maps = true,
0011 );
0012 struct bpf_object *obj_iter, *obj = NULL;
0013 struct bpf_program *prog;
0014 __u32 duration = 0;
0015 int err = 0;
0016
0017 obj_iter = bpf_object__open_file(file, &open_opts);
0018 if (!ASSERT_OK_PTR(obj_iter, "obj_iter_open_file"))
0019 return;
0020
0021 if (CHECK(strcmp(bpf_object__name(obj_iter), obj_name), "obj_name",
0022 "wrong obj name '%s', expected '%s'\n",
0023 bpf_object__name(obj_iter), obj_name))
0024 goto cleanup;
0025
0026 bpf_object__for_each_program(prog, obj_iter) {
0027 struct bpf_program *p;
0028 const char *name;
0029
0030 name = bpf_program__name(prog);
0031 if (!test__start_subtest(name))
0032 continue;
0033
0034 obj = bpf_object__open_file(file, &open_opts);
0035 if (!ASSERT_OK_PTR(obj, "obj_open_file"))
0036 goto cleanup;
0037
0038
0039
0040
0041 p = bpf_object__find_program_by_name(obj, name);
0042 bpf_program__set_autoload(p, true);
0043
0044
0045 if (strncmp(name, "err_", sizeof("err_") - 1) == 0) {
0046 libbpf_print_fn_t old_print_fn;
0047
0048 old_print_fn = libbpf_set_print(NULL);
0049 err = !bpf_object__load(obj);
0050 libbpf_set_print(old_print_fn);
0051 } else {
0052 err = bpf_object__load(obj);
0053 }
0054 ASSERT_OK(err, name);
0055
0056 bpf_object__close(obj);
0057 obj = NULL;
0058 }
0059
0060 cleanup:
0061 bpf_object__close(obj);
0062 bpf_object__close(obj_iter);
0063 }