Loading...
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright (c) 2019 Facebook */
3
4#include <test_progs.h>
5#include "test_ksyms.skel.h"
6#include <sys/stat.h>
7
8void test_ksyms(void)
9{
10 const char *btf_path = "/sys/kernel/btf/vmlinux";
11 struct test_ksyms *skel;
12 struct test_ksyms__data *data;
13 __u64 link_fops_addr, per_cpu_start_addr;
14 struct stat st;
15 __u64 btf_size;
16 int err;
17
18 err = kallsyms_find("bpf_link_fops", &link_fops_addr);
19 if (!ASSERT_NEQ(err, -EINVAL, "bpf_link_fops: kallsyms_fopen"))
20 return;
21 if (!ASSERT_NEQ(err, -ENOENT, "bpf_link_fops: ksym_find"))
22 return;
23
24 err = kallsyms_find("__per_cpu_start", &per_cpu_start_addr);
25 if (!ASSERT_NEQ(err, -EINVAL, "__per_cpu_start: kallsyms_fopen"))
26 return;
27 if (!ASSERT_NEQ(err, -ENOENT, "__per_cpu_start: ksym_find"))
28 return;
29
30 if (!ASSERT_OK(stat(btf_path, &st), "stat_btf"))
31 return;
32 btf_size = st.st_size;
33
34 skel = test_ksyms__open_and_load();
35 if (!ASSERT_OK_PTR(skel, "test_ksyms__open_and_load"))
36 return;
37
38 err = test_ksyms__attach(skel);
39 if (!ASSERT_OK(err, "test_ksyms__attach"))
40 goto cleanup;
41
42 /* trigger tracepoint */
43 usleep(1);
44
45 data = skel->data;
46 ASSERT_EQ(data->out__bpf_link_fops, link_fops_addr, "bpf_link_fops");
47 ASSERT_EQ(data->out__bpf_link_fops1, 0, "bpf_link_fops1");
48 ASSERT_EQ(data->out__btf_size, btf_size, "btf_size");
49 ASSERT_EQ(data->out__per_cpu_start, per_cpu_start_addr, "__per_cpu_start");
50
51cleanup:
52 test_ksyms__destroy(skel);
53}
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright (c) 2019 Facebook */
3
4#include <test_progs.h>
5#include "test_ksyms.skel.h"
6#include <sys/stat.h>
7
8static int duration;
9
10void test_ksyms(void)
11{
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;
16 struct stat st;
17 __u64 btf_size;
18 int err;
19
20 err = kallsyms_find("bpf_link_fops", &link_fops_addr);
21 if (CHECK(err == -EINVAL, "kallsyms_fopen", "failed to open: %d\n", errno))
22 return;
23 if (CHECK(err == -ENOENT, "ksym_find", "symbol 'bpf_link_fops' not found\n"))
24 return;
25
26 err = kallsyms_find("__per_cpu_start", &per_cpu_start_addr);
27 if (CHECK(err == -EINVAL, "kallsyms_fopen", "failed to open: %d\n", errno))
28 return;
29 if (CHECK(err == -ENOENT, "ksym_find", "symbol 'per_cpu_start' not found\n"))
30 return;
31
32 if (CHECK(stat(btf_path, &st), "stat_btf", "err %d\n", errno))
33 return;
34 btf_size = st.st_size;
35
36 skel = test_ksyms__open_and_load();
37 if (CHECK(!skel, "skel_open", "failed to open and load skeleton\n"))
38 return;
39
40 err = test_ksyms__attach(skel);
41 if (CHECK(err, "skel_attach", "skeleton attach failed: %d\n", err))
42 goto cleanup;
43
44 /* trigger tracepoint */
45 usleep(1);
46
47 data = skel->data;
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,
57 per_cpu_start_addr);
58
59cleanup:
60 test_ksyms__destroy(skel);
61}