From: Jiri Olsa <jolsa@kernel.org>
To: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andriin@fb.com>
Cc: netdev@vger.kernel.org, bpf@vger.kernel.org,
"Martin KaFai Lau" <kafai@fb.com>,
"Song Liu" <songliubraving@fb.com>, "Yonghong Song" <yhs@fb.com>,
"John Fastabend" <john.fastabend@gmail.com>,
"KP Singh" <kpsingh@chromium.org>, "Daniel Xu" <dxu@dxuuu.xyz>,
"Steven Rostedt" <rostedt@goodmis.org>,
"Jesper Brouer" <jbrouer@redhat.com>,
"Toke Høiland-Jørgensen" <toke@redhat.com>,
"Viktor Malik" <vmalik@redhat.com>
Subject: [PATCHv2 RFC bpf-next 7/7] selftests/bpf: Add ftrace probe test
Date: Tue, 13 Apr 2021 14:15:16 +0200 [thread overview]
Message-ID: <20210413121516.1467989-8-jolsa@kernel.org> (raw)
In-Reply-To: <20210413121516.1467989-1-jolsa@kernel.org>
Adding simple ftrace probe test that configures ftrace
probe and verifies the 'ip' argument matches the probed
functions addresses.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
.../selftests/bpf/prog_tests/ftrace_test.c | 48 +++++++++++++++++++
.../testing/selftests/bpf/progs/ftrace_test.c | 17 +++++++
2 files changed, 65 insertions(+)
create mode 100644 tools/testing/selftests/bpf/prog_tests/ftrace_test.c
create mode 100644 tools/testing/selftests/bpf/progs/ftrace_test.c
diff --git a/tools/testing/selftests/bpf/prog_tests/ftrace_test.c b/tools/testing/selftests/bpf/prog_tests/ftrace_test.c
new file mode 100644
index 000000000000..34d6dbe88251
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/ftrace_test.c
@@ -0,0 +1,48 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <test_progs.h>
+#include "ftrace_test.skel.h"
+
+void test_ftrace_test(void)
+{
+ struct ftrace_test *ftrace_skel = NULL;
+ __u32 duration = 0, retval;
+ int err, prog_fd;
+ __u64 *ips;
+ int idx, i;
+
+ ftrace_skel = ftrace_test__open_and_load();
+ if (!ASSERT_OK_PTR(ftrace_skel, "ftrace_skel_load"))
+ goto cleanup;
+
+ err = ftrace_test__attach(ftrace_skel);
+ if (!ASSERT_OK(err, "ftrace_attach"))
+ goto cleanup;
+
+ prog_fd = bpf_program__fd(ftrace_skel->progs.test);
+ err = bpf_prog_test_run(prog_fd, 1, NULL, 0,
+ NULL, NULL, &retval, &duration);
+ ASSERT_OK(err || retval, "test_run");
+
+ ips = ftrace_skel->bss->ips;
+ idx = ftrace_skel->bss->idx;
+
+ if (!ASSERT_EQ(idx, 8, "idx"))
+ goto cleanup;
+
+ for (i = 0; i < 8; i++) {
+ unsigned long long addr;
+ char func[50];
+
+ snprintf(func, sizeof(func), "bpf_fentry_test%d", i + 1);
+
+ err = kallsyms_find(func, &addr);
+ if (!ASSERT_OK(err, "kallsyms_find"))
+ goto cleanup;
+
+ if (!ASSERT_EQ(ips[i], addr, "ips_addr"))
+ goto cleanup;
+ }
+
+cleanup:
+ ftrace_test__destroy(ftrace_skel);
+}
diff --git a/tools/testing/selftests/bpf/progs/ftrace_test.c b/tools/testing/selftests/bpf/progs/ftrace_test.c
new file mode 100644
index 000000000000..b2a55aa10318
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/ftrace_test.c
@@ -0,0 +1,17 @@
+// 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";
+
+__u64 ips[9] = { };
+unsigned int idx = 0;
+
+SEC("fentry.ftrace/bpf_fentry_test*")
+int BPF_PROG(test, __u64 ip, __u64 parent_ip)
+{
+ if (idx >= 0 && idx < 8)
+ ips[idx++] = ip;
+ return 0;
+}
--
2.30.2
next prev parent reply other threads:[~2021-04-13 12:16 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-13 12:15 [PATCHv2 RFC bpf-next 0/7] bpf: Add support for ftrace probe Jiri Olsa
2021-04-13 12:15 ` [PATCHv2 RFC bpf-next 1/7] bpf: Move bpf_prog_start/end functions to generic place Jiri Olsa
2021-04-13 12:15 ` [PATCHv2 RFC bpf-next 2/7] bpf: Add bpf_functions object Jiri Olsa
2021-04-13 12:15 ` [PATCHv2 RFC bpf-next 3/7] bpf: Add support to attach program to ftrace probe Jiri Olsa
2021-04-13 12:15 ` [PATCHv2 RFC bpf-next 4/7] libbpf: Add btf__find_by_pattern_kind function Jiri Olsa
2021-04-13 12:15 ` [PATCHv2 RFC bpf-next 5/7] libbpf: Add support to load and attach ftrace probe Jiri Olsa
2021-04-13 12:15 ` [PATCHv2 RFC bpf-next 6/7] selftests/bpf: Add ftrace probe to fentry test Jiri Olsa
2021-04-13 12:15 ` Jiri Olsa [this message]
2021-04-14 1:04 ` [PATCHv2 RFC bpf-next 0/7] bpf: Add support for ftrace probe Andrii Nakryiko
2021-04-14 12:19 ` Jiri Olsa
2021-04-14 22:46 ` Andrii Nakryiko
2021-04-15 14:00 ` Jiri Olsa
2021-04-15 15:10 ` Steven Rostedt
2021-04-15 17:39 ` Jiri Olsa
2021-04-15 18:18 ` Steven Rostedt
2021-04-15 18:21 ` Steven Rostedt
2021-04-15 21:49 ` Jiri Olsa
2021-04-15 23:30 ` Steven Rostedt
2021-04-19 20:51 ` Jiri Olsa
2021-04-19 22:00 ` Steven Rostedt
2021-04-15 18:31 ` Yonghong Song
2021-04-15 20:45 ` Andrii Nakryiko
2021-04-15 21:00 ` Steven Rostedt
2021-04-16 15:03 ` Masami Hiramatsu
2021-04-16 16:48 ` Steven Rostedt
2021-04-19 14:29 ` Masami Hiramatsu
2021-04-20 12:51 ` Jiri Olsa
2021-04-20 15:33 ` Alexei Starovoitov
2021-04-20 16:33 ` Steven Rostedt
2021-04-20 16:52 ` Jiri Olsa
2021-04-20 23:38 ` Alexei Starovoitov
2021-04-21 13:40 ` Jiri Olsa
2021-04-21 14:05 ` Steven Rostedt
2021-04-21 18:52 ` Andrii Nakryiko
2021-04-21 19:18 ` Jiri Olsa
2021-04-22 14:24 ` Steven Rostedt
2021-04-21 21:37 ` Jiri Olsa
2021-04-22 1:17 ` Steven Rostedt
2021-04-20 4:51 ` Andrii Nakryiko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210413121516.1467989-8-jolsa@kernel.org \
--to=jolsa@kernel.org \
--cc=andriin@fb.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=dxu@dxuuu.xyz \
--cc=jbrouer@redhat.com \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@chromium.org \
--cc=netdev@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=songliubraving@fb.com \
--cc=toke@redhat.com \
--cc=vmalik@redhat.com \
--cc=yhs@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).