Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /* Copyright (c) 2019 Facebook */
0003 
0004 #include <test_progs.h>
0005 #include "test_ksyms.skel.h"
0006 #include <sys/stat.h>
0007 
0008 static int duration;
0009 
0010 void test_ksyms(void)
0011 {
0012     const char *btf_path = "/sys/kernel/btf/vmlinux";
0013     struct test_ksyms *skel;
0014     struct test_ksyms__data *data;
0015     __u64 link_fops_addr, per_cpu_start_addr;
0016     struct stat st;
0017     __u64 btf_size;
0018     int err;
0019 
0020     err = kallsyms_find("bpf_link_fops", &link_fops_addr);
0021     if (CHECK(err == -EINVAL, "kallsyms_fopen", "failed to open: %d\n", errno))
0022         return;
0023     if (CHECK(err == -ENOENT, "ksym_find", "symbol 'bpf_link_fops' not found\n"))
0024         return;
0025 
0026     err = kallsyms_find("__per_cpu_start", &per_cpu_start_addr);
0027     if (CHECK(err == -EINVAL, "kallsyms_fopen", "failed to open: %d\n", errno))
0028         return;
0029     if (CHECK(err == -ENOENT, "ksym_find", "symbol 'per_cpu_start' not found\n"))
0030         return;
0031 
0032     if (CHECK(stat(btf_path, &st), "stat_btf", "err %d\n", errno))
0033         return;
0034     btf_size = st.st_size;
0035 
0036     skel = test_ksyms__open_and_load();
0037     if (CHECK(!skel, "skel_open", "failed to open and load skeleton\n"))
0038         return;
0039 
0040     err = test_ksyms__attach(skel);
0041     if (CHECK(err, "skel_attach", "skeleton attach failed: %d\n", err))
0042         goto cleanup;
0043 
0044     /* trigger tracepoint */
0045     usleep(1);
0046 
0047     data = skel->data;
0048     CHECK(data->out__bpf_link_fops != link_fops_addr, "bpf_link_fops",
0049           "got 0x%llx, exp 0x%llx\n",
0050           data->out__bpf_link_fops, link_fops_addr);
0051     CHECK(data->out__bpf_link_fops1 != 0, "bpf_link_fops1",
0052           "got %llu, exp %llu\n", data->out__bpf_link_fops1, (__u64)0);
0053     CHECK(data->out__btf_size != btf_size, "btf_size",
0054           "got %llu, exp %llu\n", data->out__btf_size, btf_size);
0055     CHECK(data->out__per_cpu_start != per_cpu_start_addr, "__per_cpu_start",
0056           "got %llu, exp %llu\n", data->out__per_cpu_start,
0057           per_cpu_start_addr);
0058 
0059 cleanup:
0060     test_ksyms__destroy(skel);
0061 }