[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210605111034.1810858-18-jolsa@kernel.org>
Date: Sat, 5 Jun 2021 13:10:32 +0200
From: Jiri Olsa <jolsa@...nel.org>
To: Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andriin@...com>,
"Steven Rostedt (VMware)" <rostedt@...dmis.org>
Cc: netdev@...r.kernel.org, bpf@...r.kernel.org,
Martin KaFai Lau <kafai@...com>,
Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
John Fastabend <john.fastabend@...il.com>,
KP Singh <kpsingh@...omium.org>, Daniel Xu <dxu@...uu.xyz>,
Viktor Malik <vmalik@...hat.com>
Subject: [PATCH 17/19] selftests/bpf: Add fexit multi func test
Adding selftest for fexit multi func test that attaches
to bpf_fentry_test* functions and checks argument values
based on the processed function.
Signed-off-by: Jiri Olsa <jolsa@...nel.org>
---
.../bpf/prog_tests/fexit_multi_test.c | 44 +++++++++++++++++++
.../selftests/bpf/progs/fexit_multi_test.c | 20 +++++++++
2 files changed, 64 insertions(+)
create mode 100644 tools/testing/selftests/bpf/prog_tests/fexit_multi_test.c
create mode 100644 tools/testing/selftests/bpf/progs/fexit_multi_test.c
diff --git a/tools/testing/selftests/bpf/prog_tests/fexit_multi_test.c b/tools/testing/selftests/bpf/prog_tests/fexit_multi_test.c
new file mode 100644
index 000000000000..76408e1adba6
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/fexit_multi_test.c
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <test_progs.h>
+#include "fexit_multi_test.skel.h"
+#include "trace_helpers.h"
+
+void test_fexit_multi_test(void)
+{
+ struct fexit_multi_test *skel = NULL;
+ unsigned long long *bpf_fentry_test;
+ __u32 duration = 0, retval;
+ int err, prog_fd;
+
+ skel = fexit_multi_test__open_and_load();
+ if (!ASSERT_OK_PTR(skel, "fexit_multi_skel_load"))
+ goto cleanup;
+
+ bpf_fentry_test = &skel->bss->bpf_fentry_test[0];
+ ASSERT_OK(kallsyms_find("bpf_fentry_test1", &bpf_fentry_test[0]), "kallsyms_find");
+ ASSERT_OK(kallsyms_find("bpf_fentry_test2", &bpf_fentry_test[1]), "kallsyms_find");
+ ASSERT_OK(kallsyms_find("bpf_fentry_test3", &bpf_fentry_test[2]), "kallsyms_find");
+ ASSERT_OK(kallsyms_find("bpf_fentry_test4", &bpf_fentry_test[3]), "kallsyms_find");
+ ASSERT_OK(kallsyms_find("bpf_fentry_test5", &bpf_fentry_test[4]), "kallsyms_find");
+ ASSERT_OK(kallsyms_find("bpf_fentry_test6", &bpf_fentry_test[5]), "kallsyms_find");
+ ASSERT_OK(kallsyms_find("bpf_fentry_test7", &bpf_fentry_test[6]), "kallsyms_find");
+ ASSERT_OK(kallsyms_find("bpf_fentry_test8", &bpf_fentry_test[7]), "kallsyms_find");
+
+ err = fexit_multi_test__attach(skel);
+ if (!ASSERT_OK(err, "fexit_attach"))
+ goto cleanup;
+
+ prog_fd = bpf_program__fd(skel->progs.test);
+ 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");
+
+ ASSERT_EQ(skel->bss->test_arg_result, 8, "fexit_multi_arg_result");
+ ASSERT_EQ(skel->bss->test_ret_result, 8, "fexit_multi_ret_result");
+
+ fexit_multi_test__detach(skel);
+
+cleanup:
+ fexit_multi_test__destroy(skel);
+}
diff --git a/tools/testing/selftests/bpf/progs/fexit_multi_test.c b/tools/testing/selftests/bpf/progs/fexit_multi_test.c
new file mode 100644
index 000000000000..365575cf05a0
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/fexit_multi_test.c
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <linux/bpf.h>
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+#include "multi_check.h"
+
+char _license[] SEC("license") = "GPL";
+
+unsigned long long bpf_fentry_test[8];
+
+__u64 test_arg_result = 0;
+__u64 test_ret_result = 0;
+
+SEC("fexit.multi/bpf_fentry_test*")
+int BPF_PROG(test, unsigned long ip, __u64 a, __u64 b, __u64 c, __u64 d, __u64 e, __u64 f, int ret)
+{
+ multi_arg_check(ip, a, b, c, d, e, f, &test_arg_result);
+ multi_ret_check(ip, ret, &test_ret_result);
+ return 0;
+}
--
2.31.1
Powered by blists - more mailing lists