Loading...
Note: File does not exist in v3.5.6.
1// SPDX-License-Identifier: GPL-2.0
2#include <test_progs.h>
3#include "get_func_ip_test.skel.h"
4
5static void test_function_entry(void)
6{
7 struct get_func_ip_test *skel = NULL;
8 int err, prog_fd;
9 LIBBPF_OPTS(bpf_test_run_opts, topts);
10
11 skel = get_func_ip_test__open();
12 if (!ASSERT_OK_PTR(skel, "get_func_ip_test__open"))
13 return;
14
15 err = get_func_ip_test__load(skel);
16 if (!ASSERT_OK(err, "get_func_ip_test__load"))
17 goto cleanup;
18
19 err = get_func_ip_test__attach(skel);
20 if (!ASSERT_OK(err, "get_func_ip_test__attach"))
21 goto cleanup;
22
23 prog_fd = bpf_program__fd(skel->progs.test1);
24 err = bpf_prog_test_run_opts(prog_fd, &topts);
25 ASSERT_OK(err, "test_run");
26 ASSERT_EQ(topts.retval, 0, "test_run");
27
28 prog_fd = bpf_program__fd(skel->progs.test5);
29 err = bpf_prog_test_run_opts(prog_fd, &topts);
30
31 ASSERT_OK(err, "test_run");
32
33 ASSERT_EQ(skel->bss->test1_result, 1, "test1_result");
34 ASSERT_EQ(skel->bss->test2_result, 1, "test2_result");
35 ASSERT_EQ(skel->bss->test3_result, 1, "test3_result");
36 ASSERT_EQ(skel->bss->test4_result, 1, "test4_result");
37 ASSERT_EQ(skel->bss->test5_result, 1, "test5_result");
38
39cleanup:
40 get_func_ip_test__destroy(skel);
41}
42
43/* test6 is x86_64 specific because of the instruction
44 * offset, disabling it for all other archs
45 */
46#ifdef __x86_64__
47static void test_function_body(void)
48{
49 struct get_func_ip_test *skel = NULL;
50 LIBBPF_OPTS(bpf_test_run_opts, topts);
51 LIBBPF_OPTS(bpf_kprobe_opts, kopts);
52 struct bpf_link *link6 = NULL;
53 int err, prog_fd;
54
55 skel = get_func_ip_test__open();
56 if (!ASSERT_OK_PTR(skel, "get_func_ip_test__open"))
57 return;
58
59 bpf_program__set_autoload(skel->progs.test6, true);
60
61 err = get_func_ip_test__load(skel);
62 if (!ASSERT_OK(err, "get_func_ip_test__load"))
63 goto cleanup;
64
65 kopts.offset = skel->kconfig->CONFIG_X86_KERNEL_IBT ? 9 : 5;
66
67 link6 = bpf_program__attach_kprobe_opts(skel->progs.test6, "bpf_fentry_test6", &kopts);
68 if (!ASSERT_OK_PTR(link6, "link6"))
69 goto cleanup;
70
71 prog_fd = bpf_program__fd(skel->progs.test1);
72 err = bpf_prog_test_run_opts(prog_fd, &topts);
73 ASSERT_OK(err, "test_run");
74 ASSERT_EQ(topts.retval, 0, "test_run");
75
76 ASSERT_EQ(skel->bss->test6_result, 1, "test6_result");
77
78cleanup:
79 bpf_link__destroy(link6);
80 get_func_ip_test__destroy(skel);
81}
82#else
83#define test_function_body()
84#endif
85
86void test_get_func_ip_test(void)
87{
88 test_function_entry();
89 test_function_body();
90}