On Wed, Jul 7, 2021 at 2:54 PM Jiri Olsa [off-list ref] wrote:
Adding test for bpf_get_func_ip helper for fentry, fexit,
kprobe, kretprobe and fmod_ret programs.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
.../bpf/prog_tests/get_func_ip_test.c | 42 +++++++++++++
.../selftests/bpf/progs/get_func_ip_test.c | 62 +++++++++++++++++++
2 files changed, 104 insertions(+)
create mode 100644 tools/testing/selftests/bpf/prog_tests/get_func_ip_test.c
create mode 100644 tools/testing/selftests/bpf/progs/get_func_ip_test.c
[...]
+ ASSERT_OK(err, "test_run");
+
+ result = (__u64 *)skel->bss;
+ for (i = 0; i < sizeof(*skel->bss) / sizeof(__u64); i++) {
+ if (!ASSERT_EQ(result[i], 1, "fentry_result"))
+ break;
+ }
I dislike such generic loop over results. It's super error prone and
takes the same 5 lines of code that you'd write for explicit
ASSERT_EQ(testX_result, 1, "testX_result"); /* 5 times */
+
+ get_func_ip_test__detach(skel);
no need to explicitly detach, __destroy does that automatically
+
+cleanup:
+ get_func_ip_test__destroy(skel);
+}
[...]