linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Daniel Xu <dxu@dxuuu.xyz>
Cc: Song Liu <songliubraving@fb.com>, Yonghong Song <yhs@fb.com>,
	Andrii Nakryiko <andriin@fb.com>,
	peterz@infraded.org, Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Alexei Starovoitov <ast@fb.com>,
	alexander.shishkin@linux.intel.com, Jiri Olsa <jolsa@redhat.com>,
	Namhyung Kim <namhyung@kernel.org>,
	open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 bpf-next 4/4] tracing/probe: Add self test for PERF_EVENT_IOC_QUERY_PROBE
Date: Mon, 12 Aug 2019 10:46:09 -0700	[thread overview]
Message-ID: <CAEf4Bza3tz+3N6UyL2e9xM9yyf6=C+s0qa46bYyptuAioFtWuQ@mail.gmail.com> (raw)
In-Reply-To: <20190809214642.12078-5-dxu@dxuuu.xyz>

On Fri, Aug 9, 2019 at 2:49 PM Daniel Xu <dxu@dxuuu.xyz> wrote:
>
> Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
> ---

Getting verbose, we might want to rethink this test checks at some
point, but I think it's fine for now.

Please fix typos below, but overall:

Acked-by: Andrii Nakryiko <andriin@fb.com>

>  .../selftests/bpf/prog_tests/attach_probe.c   | 102 ++++++++++++++++++
>  1 file changed, 102 insertions(+)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/attach_probe.c b/tools/testing/selftests/bpf/prog_tests/attach_probe.c
> index 5ecc267d98b0..bb53103ddb66 100644
> --- a/tools/testing/selftests/bpf/prog_tests/attach_probe.c
> +++ b/tools/testing/selftests/bpf/prog_tests/attach_probe.c
> @@ -27,17 +27,27 @@ void test_attach_probe(void)
>         const char *kretprobe_name = "kretprobe/sys_nanosleep";
>         const char *uprobe_name = "uprobe/trigger_func";
>         const char *uretprobe_name = "uretprobe/trigger_func";
> +       struct perf_event_query_probe kprobe_query = {};
> +       struct perf_event_query_probe kretprobe_query = {};
> +       struct perf_event_query_probe uprobe_query = {};
> +       struct perf_event_query_probe uretprobe_query = {};
>         const int kprobe_idx = 0, kretprobe_idx = 1;
>         const int uprobe_idx = 2, uretprobe_idx = 3;
>         const char *file = "./test_attach_probe.o";
>         struct bpf_program *kprobe_prog, *kretprobe_prog;
>         struct bpf_program *uprobe_prog, *uretprobe_prog;
>         struct bpf_object *obj;
> +       const struct bpf_link_fd *kprobe_fd_link;
> +       const struct bpf_link_fd *kretprobe_fd_link;
> +       const struct bpf_link_fd *uprobe_fd_link;
> +       const struct bpf_link_fd *uretprobe_fd_link;
>         int err, prog_fd, duration = 0, res;
>         struct bpf_link *kprobe_link = NULL;
>         struct bpf_link *kretprobe_link = NULL;
>         struct bpf_link *uprobe_link = NULL;
>         struct bpf_link *uretprobe_link = NULL;
> +       int kprobe_fd, kretprobe_fd;
> +       int uprobe_fd, uretprobe_fd;
>         int results_map_fd;
>         size_t uprobe_offset;
>         ssize_t base_addr;
> @@ -116,6 +126,52 @@ 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;
> +
> +       kretprobe_fd_link = bpf_link__as_fd(kretprobe_link);
> +       if (CHECK(!kretprobe_fd_link, "kretprobe_link_as_fd",
> +                 "failed to cast link to fd link\n"))
> +               goto cleanup;
> +
> +       kretprobe_fd = bpf_link_fd__fd(kretprobe_fd_link);
> +       if (CHECK(kretprobe_fd < 0, "kretprobe_get_perf_fd",
> +           "failed to get perf fd from kretprobe link\n"))
> +               goto cleanup;
> +
> +       err = ioctl(kprobe_fd, PERF_EVENT_IOC_QUERY_PROBE, &kprobe_query);
> +       if (CHECK(err, "get_kprobe_ioctl",
> +                 "failed to issue kprobe query ioctl\n"))
> +               goto cleanup;
> +       if (CHECK(kprobe_query.nmissed > 0, "get_kprobe_ioctl",
> +                 "read incorect nmissed from kprobe_ioctl: %llu\n",

typo: incorrect

> +                 kprobe_query.nmissed))
> +               goto cleanup;
> +       if (CHECK(kprobe_query.nhit == 0, "get_kprobe_ioctl",
> +                 "read incorect nhit from kprobe_ioctl: %llu\n",

typo: incorrect

> +                 kprobe_query.nhit))
> +               goto cleanup;
> +
> +       err = ioctl(kretprobe_fd, PERF_EVENT_IOC_QUERY_PROBE, &kretprobe_query);
> +       if (CHECK(err, "get_kretprobe_ioctl",
> +                 "failed to issue kretprobe query ioctl\n"))
> +               goto cleanup;
> +       if (CHECK(kretprobe_query.nmissed > 0, "get_kretprobe_ioctl",
> +                 "read incorect nmissed from kretprobe_ioctl: %llu\n",

same typo :)

> +                 kretprobe_query.nmissed))
> +               goto cleanup;
> +       if (CHECK(kretprobe_query.nhit <= 0, "get_kretprobe_ioctl",
> +                 "read incorect nhit from kretprobe_ioctl: %llu\n",

the power of copy/paste! :)

> +                 kretprobe_query.nhit))
> +               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))
> @@ -135,6 +191,52 @@ void test_attach_probe(void)
>         /* trigger & validate uprobe & uretprobe */
>         get_base_addr();
>
> +       uprobe_fd_link = bpf_link__as_fd(uprobe_link);
> +       if (CHECK(!uprobe_fd_link, "uprobe_link_as_fd",
> +                 "failed to cast link to fd link\n"))
> +               goto cleanup;
> +
> +       uprobe_fd = bpf_link_fd__fd(uprobe_fd_link);
> +       if (CHECK(uprobe_fd < 0, "uprobe_get_perf_fd",
> +           "failed to get perf fd from uprobe link\n"))
> +               goto cleanup;
> +
> +       uretprobe_fd_link = bpf_link__as_fd(uretprobe_link);
> +       if (CHECK(!uretprobe_fd_link, "uretprobe_link_as_fd",
> +                 "failed to cast link to fd link\n"))
> +               goto cleanup;
> +
> +       uretprobe_fd = bpf_link_fd__fd(uretprobe_fd_link);
> +       if (CHECK(uretprobe_fd < 0, "uretprobe_get_perf_fd",
> +           "failed to get perf fd from uretprobe link\n"))
> +               goto cleanup;
> +
> +       err = ioctl(uprobe_fd, PERF_EVENT_IOC_QUERY_PROBE, &uprobe_query);
> +       if (CHECK(err, "get_uprobe_ioctl",
> +                 "failed to issue uprobe query ioctl\n"))
> +               goto cleanup;
> +       if (CHECK(uprobe_query.nmissed > 0, "get_uprobe_ioctl",
> +                 "read incorect nmissed from uprobe_ioctl: %llu\n",
> +                 uprobe_query.nmissed))
> +               goto cleanup;
> +       if (CHECK(uprobe_query.nhit == 0, "get_uprobe_ioctl",
> +                 "read incorect nhit from uprobe_ioctl: %llu\n",
> +                 uprobe_query.nhit))
> +               goto cleanup;
> +
> +       err = ioctl(uretprobe_fd, PERF_EVENT_IOC_QUERY_PROBE, &uretprobe_query);
> +       if (CHECK(err, "get_uretprobe_ioctl",
> +                 "failed to issue uretprobe query ioctl\n"))
> +               goto cleanup;
> +       if (CHECK(uretprobe_query.nmissed > 0, "get_uretprobe_ioctl",
> +                 "read incorect nmissed from uretprobe_ioctl: %llu\n",
> +                 uretprobe_query.nmissed))
> +               goto cleanup;
> +       if (CHECK(uretprobe_query.nhit <= 0, "get_uretprobe_ioctl",
> +                 "read incorect nhit from uretprobe_ioctl: %llu\n",
> +                 uretprobe_query.nhit))
> +               goto cleanup;
> +

same typos

>         err = bpf_map_lookup_elem(results_map_fd, &uprobe_idx, &res);
>         if (CHECK(err, "get_uprobe_res",
>                   "failed to get uprobe res: %d\n", err))
> --
> 2.20.1
>

  reply	other threads:[~2019-08-12 17:46 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-09 21:46 [PATCH v2 bpf-next 0/4] tracing/probe: Add PERF_EVENT_IOC_QUERY_PROBE Daniel Xu
2019-08-09 21:46 ` [PATCH v2 bpf-next 1/4] tracing/probe: Add PERF_EVENT_IOC_QUERY_PROBE ioctl Daniel Xu
2019-08-12 15:56   ` Andrii Nakryiko
2019-08-13  0:38     ` Daniel Xu
2019-08-13 19:48       ` Andrii Nakryiko
2019-08-13 21:47   ` Song Liu
2019-08-13 23:07     ` Daniel Xu
2019-08-09 21:46 ` [PATCH v2 bpf-next 2/4] libbpf: Add helpers to extract perf fd from bpf_link Daniel Xu
2019-08-12 16:02   ` Andrii Nakryiko
2019-08-09 21:46 ` [PATCH v2 bpf-next 3/4] tracing/probe: Sync perf_event.h to tools Daniel Xu
2019-08-09 21:46 ` [PATCH v2 bpf-next 4/4] tracing/probe: Add self test for PERF_EVENT_IOC_QUERY_PROBE Daniel Xu
2019-08-12 17:46   ` Andrii Nakryiko [this message]
2019-08-09 21:50 ` [PATCH v2 bpf-next 0/4] tracing/probe: Add PERF_EVENT_IOC_QUERY_PROBE Daniel Xu

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='CAEf4Bza3tz+3N6UyL2e9xM9yyf6=C+s0qa46bYyptuAioFtWuQ@mail.gmail.com' \
    --to=andrii.nakryiko@gmail.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=andriin@fb.com \
    --cc=ast@fb.com \
    --cc=dxu@dxuuu.xyz \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infraded.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).