1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2019 Facebook */
4 #include <test_progs.h>
5 #include "test_ksyms.skel.h"
12 const char *btf_path
= "/sys/kernel/btf/vmlinux";
13 struct test_ksyms
*skel
;
14 struct test_ksyms__data
*data
;
15 __u64 link_fops_addr
, per_cpu_start_addr
;
20 err
= kallsyms_find("bpf_link_fops", &link_fops_addr
);
21 if (CHECK(err
== -EINVAL
, "kallsyms_fopen", "failed to open: %d\n", errno
))
23 if (CHECK(err
== -ENOENT
, "ksym_find", "symbol 'bpf_link_fops' not found\n"))
26 err
= kallsyms_find("__per_cpu_start", &per_cpu_start_addr
);
27 if (CHECK(err
== -EINVAL
, "kallsyms_fopen", "failed to open: %d\n", errno
))
29 if (CHECK(err
== -ENOENT
, "ksym_find", "symbol 'per_cpu_start' not found\n"))
32 if (CHECK(stat(btf_path
, &st
), "stat_btf", "err %d\n", errno
))
34 btf_size
= st
.st_size
;
36 skel
= test_ksyms__open_and_load();
37 if (CHECK(!skel
, "skel_open", "failed to open and load skeleton\n"))
40 err
= test_ksyms__attach(skel
);
41 if (CHECK(err
, "skel_attach", "skeleton attach failed: %d\n", err
))
44 /* trigger tracepoint */
48 CHECK(data
->out__bpf_link_fops
!= link_fops_addr
, "bpf_link_fops",
49 "got 0x%llx, exp 0x%llx\n",
50 data
->out__bpf_link_fops
, link_fops_addr
);
51 CHECK(data
->out__bpf_link_fops1
!= 0, "bpf_link_fops1",
52 "got %llu, exp %llu\n", data
->out__bpf_link_fops1
, (__u64
)0);
53 CHECK(data
->out__btf_size
!= btf_size
, "btf_size",
54 "got %llu, exp %llu\n", data
->out__btf_size
, btf_size
);
55 CHECK(data
->out__per_cpu_start
!= per_cpu_start_addr
, "__per_cpu_start",
56 "got %llu, exp %llu\n", data
->out__per_cpu_start
,
60 test_ksyms__destroy(skel
);