Netdev Archive on lore.kernel.org help / color / mirror / Atom feed
From: Yonghong Song <yhs@fb.com> To: Stanislav Fomichev <sdf@google.com>, <netdev@vger.kernel.org>, <bpf@vger.kernel.org> Cc: <ast@kernel.org>, <daniel@iogearbox.net>, <andrii@kernel.org> Subject: Re: [PATCH bpf-next] selftests/bpf: move netcnt test under test_progs Date: Wed, 28 Jul 2021 23:15:40 -0700 [thread overview] Message-ID: <eae5801e-8cef-436c-ade6-84f9eea00871@fb.com> (raw) In-Reply-To: <20210728151419.501183-1-sdf@google.com> On 7/28/21 8:14 AM, Stanislav Fomichev wrote: > Rewrite to skel and ASSERT macros as well while we are at it. > > Signed-off-by: Stanislav Fomichev <sdf@google.com> Thanks for converting test_netcnt to test_progs. The patch looks good to me except a couple of minor issues. Acked-by: Yonghong Song <yhs@fb.com> > --- > tools/testing/selftests/bpf/Makefile | 3 +- > .../testing/selftests/bpf/prog_tests/netcnt.c | 93 +++++++++++ > tools/testing/selftests/bpf/test_netcnt.c | 148 ------------------ > 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 > > diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile > index f405b20c1e6c..2a58b7b5aea4 100644 > --- a/tools/testing/selftests/bpf/Makefile > +++ b/tools/testing/selftests/bpf/Makefile > @@ -38,7 +38,7 @@ TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test > test_verifier_log test_dev_cgroup \ > test_sock test_sockmap get_cgroup_id_user \ > test_cgroup_storage \ > - test_netcnt test_tcpnotify_user test_sysctl \ > + test_tcpnotify_user test_sysctl \ > test_progs-no_alu32 > > # Also test bpf-gcc, if present > @@ -197,7 +197,6 @@ $(OUTPUT)/test_sockmap: cgroup_helpers.c > $(OUTPUT)/test_tcpnotify_user: cgroup_helpers.c trace_helpers.c > $(OUTPUT)/get_cgroup_id_user: cgroup_helpers.c > $(OUTPUT)/test_cgroup_storage: cgroup_helpers.c > -$(OUTPUT)/test_netcnt: cgroup_helpers.c > $(OUTPUT)/test_sock_fields: cgroup_helpers.c > $(OUTPUT)/test_sysctl: cgroup_helpers.c > > diff --git a/tools/testing/selftests/bpf/prog_tests/netcnt.c b/tools/testing/selftests/bpf/prog_tests/netcnt.c > new file mode 100644 > index 000000000000..063a40d228b6 > --- /dev/null > +++ b/tools/testing/selftests/bpf/prog_tests/netcnt.c > @@ -0,0 +1,93 @@ > +// SPDX-License-Identifier: GPL-2.0 > + > +#include <sys/sysinfo.h> > +#include <test_progs.h> > +#include "netcnt_prog.skel.h" > +#include "netcnt_common.h" > + > +#define CG_NAME "/netcnt" > + > +void test_netcnt(void) > +{ > + union percpu_net_cnt *percpu_netcnt = NULL; > + struct bpf_cgroup_storage_key key; > + int map_fd, percpu_map_fd; > + struct netcnt_prog *skel; > + unsigned long packets; > + union net_cnt netcnt; > + unsigned long bytes; > + int cpu, nproc; > + int cg_fd = -1; > + > + skel = netcnt_prog__open_and_load(); > + if (!ASSERT_OK_PTR(skel, "netcnt_prog__open_and_load")) > + return; > + > + nproc = get_nprocs_conf(); > + percpu_netcnt = malloc(sizeof(*percpu_netcnt) * nproc); > + if (!ASSERT_OK_PTR(percpu_netcnt, "malloc(percpu_netcnt)")) > + goto err; > + > + cg_fd = test__join_cgroup(CG_NAME); > + if (!ASSERT_GE(cg_fd, 0, "test__join_cgroup")) > + goto err; > + > + 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) > + assert(!system("ping6 ::1 -c 10000 -f -q > /dev/null")); > + else > + assert(!system("ping -6 ::1 -c 10000 -f -q > /dev/null")); > + > + map_fd = bpf_map__fd(skel->maps.netcnt); > + if (!ASSERT_GE(map_fd, 0, "bpf_map__fd(netcnt)")) > + goto err; For skeleton, map_fd is always valid and you do not need to check it. > + > + percpu_map_fd = bpf_map__fd(skel->maps.percpu_netcnt); > + if (!ASSERT_GE(percpu_map_fd, 0, "bpf_map__fd(percpu_netcnt)")) > + goto err; The same for percpu_map_fd, it is always valid and no need to check it. > + > + if (!ASSERT_OK(bpf_map_get_next_key(map_fd, NULL, &key), > + "bpf_map_get_next_key")) > + goto err; > + > + if (!ASSERT_OK(bpf_map_lookup_elem(map_fd, &key, &netcnt), > + "bpf_map_lookup_elem(netcnt)")) > + goto err; > + [...]
next prev parent reply other threads:[~2021-07-29 6:16 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-07-28 15:14 [PATCH bpf-next] selftests/bpf: move netcnt test under test_progs Stanislav Fomichev 2021-07-29 6:15 ` Yonghong Song [this message] 2021-07-29 23:08 ` 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=eae5801e-8cef-436c-ade6-84f9eea00871@fb.com \ --to=yhs@fb.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 \ /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: linkBe 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).