From: Daniel Xu <dxu@dxuuu.xyz>
To: bpf@vger.kernel.org, songliubraving@fb.com, yhs@fb.com,
andriin@fb.com, peterz@infradead.org, mingo@redhat.com,
acme@kernel.org
Cc: Daniel Xu <dxu@dxuuu.xyz>,
ast@fb.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com,
namhyung@kernel.org, linux-kernel@vger.kernel.org,
netdev@vger.kernel.org, kernel-team@fb.com
Subject: [PATCH bpf-next 5/5] libbpf: Add selftest for PERF_FORMAT_LOST perf read_format
Date: Tue, 17 Sep 2019 06:30:56 -0700 [thread overview]
Message-ID: <20190917133056.5545-6-dxu@dxuuu.xyz> (raw)
In-Reply-To: <20190917133056.5545-1-dxu@dxuuu.xyz>
Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
---
.../selftests/bpf/prog_tests/attach_probe.c | 32 ++++++++++++++++++-
1 file changed, 31 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/attach_probe.c b/tools/testing/selftests/bpf/prog_tests/attach_probe.c
index 5ecc267d98b0..3d636cccb6dc 100644
--- a/tools/testing/selftests/bpf/prog_tests/attach_probe.c
+++ b/tools/testing/selftests/bpf/prog_tests/attach_probe.c
@@ -1,6 +1,11 @@
// SPDX-License-Identifier: GPL-2.0
#include <test_progs.h>
+struct perf_read_output {
+ u64 count;
+ u64 lost;
+};
+
ssize_t get_base_addr() {
size_t start;
char buf[256];
@@ -32,6 +37,8 @@ void test_attach_probe(void)
const char *file = "./test_attach_probe.o";
struct bpf_program *kprobe_prog, *kretprobe_prog;
struct bpf_program *uprobe_prog, *uretprobe_prog;
+ struct perf_read_output kprobe_read_output;
+ const struct bpf_link_fd *kprobe_fd_link;
struct bpf_object *obj;
int err, prog_fd, duration = 0, res;
struct bpf_link *kprobe_link = NULL;
@@ -40,7 +47,8 @@ void test_attach_probe(void)
struct bpf_link *uretprobe_link = NULL;
int results_map_fd;
size_t uprobe_offset;
- ssize_t base_addr;
+ ssize_t base_addr, nread;
+ int kprobe_fd;
base_addr = get_base_addr();
if (CHECK(base_addr < 0, "get_base_addr",
@@ -116,6 +124,28 @@ void test_attach_probe(void)
/* trigger & validate kprobe && kretprobe */
usleep(1);
+ kprobe_fd_link = bpf_link__as_fd(kprobe_link);
+ if (CHECK(!kprobe_fd_link, "kprobe_link_as_fd",
+ "failed to cast link to fd link\n"))
+ goto cleanup;
+
+ kprobe_fd = bpf_link_fd__fd(kprobe_fd_link);
+ if (CHECK(kprobe_fd < 0, "kprobe_get_perf_fd",
+ "failed to get perf fd from kprobe link\n"))
+ goto cleanup;
+
+ /* Set to unexpected value so we can check the read(2) did stuff */
+ kprobe_read_output.lost = 1;
+ nread = read(kprobe_fd, &kprobe_read_output,
+ sizeof(kprobe_read_output));
+ if (CHECK(nread != sizeof(kprobe_read_output), "kprobe_perf_read",
+ "failed to read from perf fd\n"))
+ goto cleanup;
+ if (CHECK(kprobe_read_output.lost != 0, "kprobe_lost",
+ "read wrong value from perf fd: %lu\n",
+ kprobe_read_output.lost))
+ goto cleanup;
+
err = bpf_map_lookup_elem(results_map_fd, &kprobe_idx, &res);
if (CHECK(err, "get_kprobe_res",
"failed to get kprobe res: %d\n", err))
--
2.21.0
prev parent reply other threads:[~2019-09-17 13:31 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-17 13:30 [PATCH bpf-next 0/5] Add PERF_FORMAT_LOST read_format Daniel Xu
2019-09-17 13:30 ` [PATCH bpf-next 1/5] perf/core: " Daniel Xu
2019-09-17 14:32 ` kbuild test robot
2019-09-17 15:22 ` kbuild test robot
2019-09-24 8:33 ` Jiri Olsa
2019-09-27 21:28 ` Daniel Xu
2019-10-25 18:19 ` Daniel Xu
2019-10-28 9:12 ` Peter Zijlstra
2023-03-08 12:20 ` Lorenz Bauer
2019-09-17 13:30 ` [PATCH bpf-next 2/5] perf/core: Sync perf_event.h to tools Daniel Xu
2019-09-17 13:30 ` [PATCH bpf-next 3/5] libbpf: Add helpers to extract perf fd from bpf_link Daniel Xu
2019-09-17 13:30 ` [PATCH bpf-next 4/5] libbpf: Set read_format PERF_FORMAT_LOST on kprobe perf fds Daniel Xu
2019-09-17 13:30 ` Daniel Xu [this message]
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=20190917133056.5545-6-dxu@dxuuu.xyz \
--to=dxu@dxuuu.xyz \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=andriin@fb.com \
--cc=ast@fb.com \
--cc=bpf@vger.kernel.org \
--cc=jolsa@redhat.com \
--cc=kernel-team@fb.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=songliubraving@fb.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).