1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2019 Facebook */
4 #include <test_progs.h>
5 #include "test_ksyms.skel.h"
10 static __u64 kallsyms_find(const char *sym)
16 f = fopen("/proc/kallsyms", "r");
17 if (CHECK(!f, "kallsyms_fopen", "failed to open: %d\n", errno))
20 while (fscanf(f, "%llx %c %499s%*[^\n]\n", &addr, &type, name) > 0) {
21 if (strcmp(name, sym) == 0) {
27 CHECK(false, "not_found", "symbol %s not found\n", sym);
35 __u64 per_cpu_start_addr = kallsyms_find("__per_cpu_start");
36 __u64 link_fops_addr = kallsyms_find("bpf_link_fops");
37 const char *btf_path = "/sys/kernel/btf/vmlinux";
38 struct test_ksyms *skel;
39 struct test_ksyms__data *data;
44 if (CHECK(stat(btf_path, &st), "stat_btf", "err %d\n", errno))
46 btf_size = st.st_size;
48 skel = test_ksyms__open_and_load();
49 if (CHECK(!skel, "skel_open", "failed to open and load skeleton\n"))
52 err = test_ksyms__attach(skel);
53 if (CHECK(err, "skel_attach", "skeleton attach failed: %d\n", err))
56 /* trigger tracepoint */
60 CHECK(data->out__bpf_link_fops != link_fops_addr, "bpf_link_fops",
61 "got 0x%llx, exp 0x%llx\n",
62 data->out__bpf_link_fops, link_fops_addr);
63 CHECK(data->out__bpf_link_fops1 != 0, "bpf_link_fops1",
64 "got %llu, exp %llu\n", data->out__bpf_link_fops1, (__u64)0);
65 CHECK(data->out__btf_size != btf_size, "btf_size",
66 "got %llu, exp %llu\n", data->out__btf_size, btf_size);
67 CHECK(data->out__per_cpu_start != per_cpu_start_addr, "__per_cpu_start",
68 "got %llu, exp %llu\n", data->out__per_cpu_start,
72 test_ksyms__destroy(skel);