Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Stanislav Fomichev <sdf@google.com>
Cc: Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>
Subject: Re: [PATCH bpf-next] selftests/bpf: move netcnt test under test_progs
Date: Thu, 29 Jul 2021 16:08:22 -0700	[thread overview]
Message-ID: <CAEf4BzZBcG=CDVrMVb4i6x90MvpPDOXhkoZ3rHUpx3+FMUE6NQ@mail.gmail.com> (raw)
In-Reply-To: <20210728151419.501183-1-sdf@google.com>

On Wed, Jul 28, 2021 at 8:14 AM Stanislav Fomichev <sdf@google.com> wrote:
>
> Rewrite to skel and ASSERT macros as well while we are at it.
>
> Signed-off-by: Stanislav Fomichev <sdf@google.com>
> ---

Thanks! Bonus points for skeleton and ASSERT_XXX! ;)

In addition to Yonghong's comments, a few more below. Missed assert()s
require a new revision, unfortunately.

>  tools/testing/selftests/bpf/Makefile          |   3 +-
>  .../testing/selftests/bpf/prog_tests/netcnt.c |  93 +++++++++++
>  tools/testing/selftests/bpf/test_netcnt.c     | 148 ------------------

Usually there is .gitignore clean up as well.

>  3 files changed, 94 insertions(+), 150 deletions(-)
>  create mode 100644 tools/testing/selftests/bpf/prog_tests/netcnt.c
>  delete mode 100644 tools/testing/selftests/bpf/test_netcnt.c
>

[...]

> +
> +       skel->links.bpf_nextcnt =
> +               bpf_program__attach_cgroup(skel->progs.bpf_nextcnt, cg_fd);
> +       if (!ASSERT_OK_PTR(skel->links.bpf_nextcnt,
> +                          "attach_cgroup(bpf_nextcnt)"))
> +               goto err;
> +
> +       if (system("which ping6 &>/dev/null") == 0)

see 4cda0c82a34b ("selftests/bpf: Use ping6 only if available in
tc_redirect"), we should probably add some system() + ping -6/ping6
wrapper into network_helpers.c and use that in at least all
test_progs' tests.

> +               assert(!system("ping6 ::1 -c 10000 -f -q > /dev/null"));
> +       else
> +               assert(!system("ping -6 ::1 -c 10000 -f -q > /dev/null"));

no assert() please

> +
> +       map_fd = bpf_map__fd(skel->maps.netcnt);
> +       if (!ASSERT_GE(map_fd, 0, "bpf_map__fd(netcnt)"))
> +               goto err;
> +
> +       percpu_map_fd = bpf_map__fd(skel->maps.percpu_netcnt);
> +       if (!ASSERT_GE(percpu_map_fd, 0, "bpf_map__fd(percpu_netcnt)"))
> +               goto err;
> +
> +       if (!ASSERT_OK(bpf_map_get_next_key(map_fd, NULL, &key),
> +                      "bpf_map_get_next_key"))

it's ok to use all 100 characters if that helps keeps simple function
invocations on the single line, so don't hesitate to do that

> +               goto err;
> +
> +       if (!ASSERT_OK(bpf_map_lookup_elem(map_fd, &key, &netcnt),
> +                      "bpf_map_lookup_elem(netcnt)"))
> +               goto err;
> +
> +       if (!ASSERT_OK(bpf_map_lookup_elem(percpu_map_fd, &key,
> +                                          &percpu_netcnt[0]),
> +                      "bpf_map_lookup_elem(percpu_netcnt)"))
> +               goto err;
> +

[...]

      parent reply	other threads:[~2021-07-29 23:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-28 15:14 Stanislav Fomichev
2021-07-29  6:15 ` Yonghong Song
2021-07-29 23:08 ` Andrii Nakryiko [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='CAEf4BzZBcG=CDVrMVb4i6x90MvpPDOXhkoZ3rHUpx3+FMUE6NQ@mail.gmail.com' \
    --to=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=netdev@vger.kernel.org \
    --cc=sdf@google.com \
    --subject='Re: [PATCH bpf-next] selftests/bpf: move netcnt test under test_progs' \
    /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

This is a public inbox, see mirroring instructions
on how to clone and mirror all data and code used for this inbox