[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAEf4Bzb+XRK3AX2s=Sg_4sxT0aVHKa2FAeGk9JMvXtunGBo3vg@mail.gmail.com>
Date: Tue, 15 Mar 2022 21:33:26 -0700
From: Andrii Nakryiko <andrii.nakryiko@...il.com>
To: Alan Maguire <alan.maguire@...cle.com>
Cc: Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andrii@...nel.org>, Martin Lau <kafai@...com>,
Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
john fastabend <john.fastabend@...il.com>,
KP Singh <kpsingh@...nel.org>,
Toke Høiland-Jørgensen <toke@...hat.com>,
Yucong Sun <sunyucong@...il.com>,
Networking <netdev@...r.kernel.org>, bpf <bpf@...r.kernel.org>
Subject: Re: [PATCH v4 bpf-next 5/5] selftests/bpf: add tests for uprobe
auto-attach via skeleton
On Fri, Mar 11, 2022 at 4:11 AM Alan Maguire <alan.maguire@...cle.com> wrote:
>
> tests that verify auto-attach works for function entry/return for
> local functions in program, library functions in program and library
> functions in library.
>
> Signed-off-by: Alan Maguire <alan.maguire@...cle.com>
> ---
> .../selftests/bpf/prog_tests/uprobe_autoattach.c | 48 +++++++++++++++
> .../selftests/bpf/progs/test_uprobe_autoattach.c | 69 ++++++++++++++++++++++
> 2 files changed, 117 insertions(+)
> create mode 100644 tools/testing/selftests/bpf/prog_tests/uprobe_autoattach.c
> create mode 100644 tools/testing/selftests/bpf/progs/test_uprobe_autoattach.c
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/uprobe_autoattach.c b/tools/testing/selftests/bpf/prog_tests/uprobe_autoattach.c
> new file mode 100644
> index 0000000..57ed636
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/uprobe_autoattach.c
> @@ -0,0 +1,48 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/* Copyright (c) 2022, Oracle and/or its affiliates. */
> +
> +#include <test_progs.h>
> +#include "test_uprobe_autoattach.skel.h"
> +
> +/* uprobe attach point */
> +static void autoattach_trigger_func(void)
> +{
> + asm volatile ("");
> +}
> +
> +void test_uprobe_autoattach(void)
> +{
> + struct test_uprobe_autoattach *skel;
> + char *mem;
> +
> + skel = test_uprobe_autoattach__open_and_load();
> + if (!ASSERT_OK_PTR(skel, "skel_open"))
> + return;
> + if (!ASSERT_OK_PTR(skel->bss, "check_bss"))
> + goto cleanup;
no need to check skel->bss, a lot of tests will be broken if that doesn't work
> +
> + if (!ASSERT_OK(test_uprobe_autoattach__attach(skel), "skel_attach"))
> + goto cleanup;
> +
> + /* trigger & validate uprobe & uretprobe */
> + autoattach_trigger_func();
> +
> + /* trigger & validate shared library u[ret]probes attached by name */
> + mem = malloc(1);
> + free(mem);
> +
> + if (!ASSERT_EQ(skel->bss->uprobe_byname_res, 1, "check_uprobe_byname_res"))
> + goto cleanup;
> + if (!ASSERT_EQ(skel->bss->uretprobe_byname_res, 2, "check_uretprobe_byname_res"))
> + goto cleanup;
> + if (!ASSERT_EQ(skel->bss->uprobe_byname2_res, 3, "check_uprobe_byname2_res"))
> + goto cleanup;
> + if (!ASSERT_EQ(skel->bss->uretprobe_byname2_res, 4, "check_uretprobe_byname2_res"))
> + goto cleanup;
> + if (!ASSERT_EQ(skel->bss->uprobe_byname3_res, 5, "check_uprobe_byname3_res"))
> + goto cleanup;
> + if (!ASSERT_EQ(skel->bss->uretprobe_byname3_res, 6, "check_uretprobe_byname3_res"))
> + goto cleanup;
same about goto cleanup, for such sequences of value checks it's nice
and succinct to just use unconditional sequence of ASSERT_EQ()s
> +cleanup:
> + test_uprobe_autoattach__destroy(skel);
> +}
[...]
Powered by blists - more mailing lists