-
Notifications
You must be signed in to change notification settings - Fork 54.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
selftests/bpf: Add test for bpf_get_func_ip helper
Adding test for bpf_get_func_ip helper for fentry, fexit, kprobe, kretprobe and fmod_ret programs. Signed-off-by: Jiri Olsa <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
- Loading branch information
Jiri Olsa
authored and
Alexei Starovoitov
committed
Jul 16, 2021
1 parent
9ffd9f3
commit 5d8b583
Showing
2 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
#include <test_progs.h> | ||
#include "get_func_ip_test.skel.h" | ||
|
||
void test_get_func_ip_test(void) | ||
{ | ||
struct get_func_ip_test *skel = NULL; | ||
__u32 duration = 0, retval; | ||
int err, prog_fd; | ||
|
||
skel = get_func_ip_test__open_and_load(); | ||
if (!ASSERT_OK_PTR(skel, "get_func_ip_test__open_and_load")) | ||
return; | ||
|
||
err = get_func_ip_test__attach(skel); | ||
if (!ASSERT_OK(err, "get_func_ip_test__attach")) | ||
goto cleanup; | ||
|
||
prog_fd = bpf_program__fd(skel->progs.test1); | ||
err = bpf_prog_test_run(prog_fd, 1, NULL, 0, | ||
NULL, NULL, &retval, &duration); | ||
ASSERT_OK(err, "test_run"); | ||
ASSERT_EQ(retval, 0, "test_run"); | ||
|
||
prog_fd = bpf_program__fd(skel->progs.test5); | ||
err = bpf_prog_test_run(prog_fd, 1, NULL, 0, | ||
NULL, NULL, &retval, &duration); | ||
|
||
ASSERT_OK(err, "test_run"); | ||
|
||
ASSERT_EQ(skel->bss->test1_result, 1, "test1_result"); | ||
ASSERT_EQ(skel->bss->test2_result, 1, "test2_result"); | ||
ASSERT_EQ(skel->bss->test3_result, 1, "test3_result"); | ||
ASSERT_EQ(skel->bss->test4_result, 1, "test4_result"); | ||
ASSERT_EQ(skel->bss->test5_result, 1, "test5_result"); | ||
|
||
cleanup: | ||
get_func_ip_test__destroy(skel); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
#include <linux/bpf.h> | ||
#include <bpf/bpf_helpers.h> | ||
#include <bpf/bpf_tracing.h> | ||
|
||
char _license[] SEC("license") = "GPL"; | ||
|
||
extern const void bpf_fentry_test1 __ksym; | ||
extern const void bpf_fentry_test2 __ksym; | ||
extern const void bpf_fentry_test3 __ksym; | ||
extern const void bpf_fentry_test4 __ksym; | ||
extern const void bpf_modify_return_test __ksym; | ||
|
||
__u64 test1_result = 0; | ||
SEC("fentry/bpf_fentry_test1") | ||
int BPF_PROG(test1, int a) | ||
{ | ||
__u64 addr = bpf_get_func_ip(ctx); | ||
|
||
test1_result = (const void *) addr == &bpf_fentry_test1; | ||
return 0; | ||
} | ||
|
||
__u64 test2_result = 0; | ||
SEC("fexit/bpf_fentry_test2") | ||
int BPF_PROG(test2, int a) | ||
{ | ||
__u64 addr = bpf_get_func_ip(ctx); | ||
|
||
test2_result = (const void *) addr == &bpf_fentry_test2; | ||
return 0; | ||
} | ||
|
||
__u64 test3_result = 0; | ||
SEC("kprobe/bpf_fentry_test3") | ||
int test3(struct pt_regs *ctx) | ||
{ | ||
__u64 addr = bpf_get_func_ip(ctx); | ||
|
||
test3_result = (const void *) addr == &bpf_fentry_test3; | ||
return 0; | ||
} | ||
|
||
__u64 test4_result = 0; | ||
SEC("kretprobe/bpf_fentry_test4") | ||
int BPF_KRETPROBE(test4) | ||
{ | ||
__u64 addr = bpf_get_func_ip(ctx); | ||
|
||
test4_result = (const void *) addr == &bpf_fentry_test4; | ||
return 0; | ||
} | ||
|
||
__u64 test5_result = 0; | ||
SEC("fmod_ret/bpf_modify_return_test") | ||
int BPF_PROG(test5, int a, int *b, int ret) | ||
{ | ||
__u64 addr = bpf_get_func_ip(ctx); | ||
|
||
test5_result = (const void *) addr == &bpf_modify_return_test; | ||
return ret; | ||
} |