Loading...
Note: File does not exist in v3.5.6.
1// SPDX-License-Identifier: GPL-2.0
2#include <test_progs.h>
3#include "kprobe_multi.skel.h"
4#include "trace_helpers.h"
5#include "bpf/libbpf_internal.h"
6
7static void kprobe_multi_testmod_check(struct kprobe_multi *skel)
8{
9 ASSERT_EQ(skel->bss->kprobe_testmod_test1_result, 1, "kprobe_test1_result");
10 ASSERT_EQ(skel->bss->kprobe_testmod_test2_result, 1, "kprobe_test2_result");
11 ASSERT_EQ(skel->bss->kprobe_testmod_test3_result, 1, "kprobe_test3_result");
12
13 ASSERT_EQ(skel->bss->kretprobe_testmod_test1_result, 1, "kretprobe_test1_result");
14 ASSERT_EQ(skel->bss->kretprobe_testmod_test2_result, 1, "kretprobe_test2_result");
15 ASSERT_EQ(skel->bss->kretprobe_testmod_test3_result, 1, "kretprobe_test3_result");
16}
17
18static void test_testmod_attach_api(struct bpf_kprobe_multi_opts *opts)
19{
20 struct kprobe_multi *skel = NULL;
21
22 skel = kprobe_multi__open_and_load();
23 if (!ASSERT_OK_PTR(skel, "fentry_raw_skel_load"))
24 return;
25
26 skel->bss->pid = getpid();
27
28 skel->links.test_kprobe_testmod = bpf_program__attach_kprobe_multi_opts(
29 skel->progs.test_kprobe_testmod,
30 NULL, opts);
31 if (!skel->links.test_kprobe_testmod)
32 goto cleanup;
33
34 opts->retprobe = true;
35 skel->links.test_kretprobe_testmod = bpf_program__attach_kprobe_multi_opts(
36 skel->progs.test_kretprobe_testmod,
37 NULL, opts);
38 if (!skel->links.test_kretprobe_testmod)
39 goto cleanup;
40
41 ASSERT_OK(trigger_module_test_read(1), "trigger_read");
42 kprobe_multi_testmod_check(skel);
43
44cleanup:
45 kprobe_multi__destroy(skel);
46}
47
48static void test_testmod_attach_api_addrs(void)
49{
50 LIBBPF_OPTS(bpf_kprobe_multi_opts, opts);
51 unsigned long long addrs[3];
52
53 addrs[0] = ksym_get_addr("bpf_testmod_fentry_test1");
54 ASSERT_NEQ(addrs[0], 0, "ksym_get_addr");
55 addrs[1] = ksym_get_addr("bpf_testmod_fentry_test2");
56 ASSERT_NEQ(addrs[1], 0, "ksym_get_addr");
57 addrs[2] = ksym_get_addr("bpf_testmod_fentry_test3");
58 ASSERT_NEQ(addrs[2], 0, "ksym_get_addr");
59
60 opts.addrs = (const unsigned long *) addrs;
61 opts.cnt = ARRAY_SIZE(addrs);
62
63 test_testmod_attach_api(&opts);
64}
65
66static void test_testmod_attach_api_syms(void)
67{
68 LIBBPF_OPTS(bpf_kprobe_multi_opts, opts);
69 const char *syms[3] = {
70 "bpf_testmod_fentry_test1",
71 "bpf_testmod_fentry_test2",
72 "bpf_testmod_fentry_test3",
73 };
74
75 opts.syms = syms;
76 opts.cnt = ARRAY_SIZE(syms);
77 test_testmod_attach_api(&opts);
78}
79
80void serial_test_kprobe_multi_testmod_test(void)
81{
82 if (!ASSERT_OK(load_kallsyms_refresh(), "load_kallsyms_refresh"))
83 return;
84
85 if (test__start_subtest("testmod_attach_api_syms"))
86 test_testmod_attach_api_syms();
87 if (test__start_subtest("testmod_attach_api_addrs"))
88 test_testmod_attach_api_addrs();
89}