From: Yonghong Song <yhs@fb.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: bpf <bpf@vger.kernel.org>, Alexei Starovoitov <ast@kernel.org>,
Cong Wang <xiyou.wangcong@gmail.com>,
Daniel Borkmann <daniel@iogearbox.net>,
Kernel Team <kernel-team@fb.com>
Subject: Re: [PATCH bpf-next v3 10/11] selftests/bpf: add hashmap test for bpf_for_each_map_elem() helper
Date: Thu, 25 Feb 2021 19:24:15 -0800 [thread overview]
Message-ID: <75afef04-efaf-a39b-97ce-3cd8d334bfbb@fb.com> (raw)
In-Reply-To: <CAEf4BzY6ih+UKzjhqyTe9JtgO2wSFjt=kOFC6r1r1hYXdBTNtQ@mail.gmail.com>
On 2/25/21 3:25 PM, Andrii Nakryiko wrote:
> On Thu, Feb 25, 2021 at 1:35 AM Yonghong Song <yhs@fb.com> wrote:
>>
>> A test case is added for hashmap and percpu hashmap. The test
>> also exercises nested bpf_for_each_map_elem() calls like
>> bpf_prog:
>> bpf_for_each_map_elem(func1)
>> func1:
>> bpf_for_each_map_elem(func2)
>> func2:
>>
>> $ ./test_progs -n 45
>> #45/1 hash_map:OK
>> #45 for_each:OK
>> Summary: 1/1 PASSED, 0 SKIPPED, 0 FAILED
>>
>> Signed-off-by: Yonghong Song <yhs@fb.com>
>> ---
>
> I think I'll just add all the variants of ASSERT_XXX and will enforce
> their use :)
>
> For now:
>
> Acked-by: Andrii Nakryiko <andrii@kernel.org>
>
>> .../selftests/bpf/prog_tests/for_each.c | 74 +++++++++++++++
>> .../bpf/progs/for_each_hash_map_elem.c | 95 +++++++++++++++++++
>> 2 files changed, 169 insertions(+)
>> create mode 100644 tools/testing/selftests/bpf/prog_tests/for_each.c
>> create mode 100644 tools/testing/selftests/bpf/progs/for_each_hash_map_elem.c
>>
>
> [...]
>
>> +
>> + ASSERT_EQ(skel->bss->hashmap_output, 4, "hashmap_output");
>> + ASSERT_EQ(skel->bss->hashmap_elems, max_entries, "hashmap_elems");
>> +
>> + key = 1;
>> + err = bpf_map_lookup_elem(hashmap_fd, &key, &val);
>> + ASSERT_ERR(err, "hashmap_lookup");
>> +
>> + ASSERT_EQ(skel->bss->percpu_called, 1, "percpu_called");
>> + ASSERT_EQ(skel->bss->cpu < num_cpus, 1, "num_cpus");
>
> well, this is cheating (it will print something like "0 != 1" on
> error) :) why didn't you just add ASSERT_LT?
>
>> + ASSERT_EQ(skel->bss->percpu_map_elems, 1, "percpu_map_elems");
>> + ASSERT_EQ(skel->bss->percpu_key, 1, "percpu_key");
>> + ASSERT_EQ(skel->bss->percpu_val, skel->bss->cpu + 1, "percpu_val");
>> + ASSERT_EQ(skel->bss->percpu_output, 100, "percpu_output");
>> +out:
>> + free(percpu_valbuf);
>> + for_each_hash_map_elem__destroy(skel);
>> +}
>> +
>> +void test_for_each(void)
>> +{
>> + if (test__start_subtest("hash_map"))
>> + test_hash_map();
>> +}
>
> [...]
>
>> +int hashmap_output = 0;
>> +int hashmap_elems = 0;
>> +int percpu_map_elems = 0;
>> +
>> +SEC("classifier/")
>
> nit: just "classifier" didn't work?
from libbpf.c, I think it should work. Will remove "/"
if it does work!
>
>> +int test_pkt_access(struct __sk_buff *skb)
>> +{
>> + struct callback_ctx data;
>> +
>> + data.ctx = skb;
>> + data.input = 10;
>> + data.output = 0;
>> + hashmap_elems = bpf_for_each_map_elem(&hashmap, check_hash_elem, &data, 0);
>> + hashmap_output = data.output;
>> +
>> + percpu_map_elems = bpf_for_each_map_elem(&percpu_map, check_percpu_elem,
>> + (void *)0, 0);
>> + return 0;
>> +}
>> --
>> 2.24.1
>>
next prev parent reply other threads:[~2021-02-26 3:25 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-25 7:33 [PATCH bpf-next v3 00/11] bpf: add bpf_for_each_map_elem() helper Yonghong Song
2021-02-25 7:33 ` [PATCH bpf-next v3 01/11] bpf: factor out visit_func_call_insn() in check_cfg() Yonghong Song
2021-02-25 21:54 ` Andrii Nakryiko
2021-02-25 22:01 ` Alexei Starovoitov
2021-02-25 7:33 ` [PATCH bpf-next v3 02/11] bpf: factor out verbose_invalid_scalar() Yonghong Song
2021-02-25 21:56 ` Andrii Nakryiko
2021-02-25 7:33 ` [PATCH bpf-next v3 03/11] bpf: refactor check_func_call() to allow callback function Yonghong Song
2021-02-25 22:05 ` Andrii Nakryiko
2021-02-25 22:31 ` Andrii Nakryiko
2021-02-26 0:08 ` Yonghong Song
2021-02-26 1:18 ` Andrii Nakryiko
2021-02-26 0:05 ` Yonghong Song
2021-02-25 7:33 ` [PATCH bpf-next v3 04/11] bpf: add bpf_for_each_map_elem() helper Yonghong Song
2021-02-25 22:41 ` Andrii Nakryiko
2021-02-26 2:16 ` Yonghong Song
2021-02-26 3:22 ` Yonghong Song
2021-02-26 2:27 ` Cong Wang
2021-02-26 3:27 ` Yonghong Song
2021-02-25 7:33 ` [PATCH bpf-next v3 05/11] bpf: add hashtab support for " Yonghong Song
2021-02-25 22:44 ` Andrii Nakryiko
2021-02-25 7:33 ` [PATCH bpf-next v3 06/11] bpf: add arraymap " Yonghong Song
2021-02-25 22:48 ` Andrii Nakryiko
2021-02-25 7:33 ` [PATCH bpf-next v3 07/11] libbpf: move function is_ldimm64() earlier in libbpf.c Yonghong Song
2021-02-25 7:33 ` [PATCH bpf-next v3 08/11] libbpf: support subprog address relocation Yonghong Song
2021-02-25 23:04 ` Andrii Nakryiko
2021-02-25 7:33 ` [PATCH bpf-next v3 09/11] bpftool: print subprog address properly Yonghong Song
2021-02-25 23:04 ` Andrii Nakryiko
2021-02-25 7:33 ` [PATCH bpf-next v3 10/11] selftests/bpf: add hashmap test for bpf_for_each_map_elem() helper Yonghong Song
2021-02-25 23:25 ` Andrii Nakryiko
2021-02-26 3:24 ` Yonghong Song [this message]
2021-02-25 7:33 ` [PATCH bpf-next v3 11/11] selftests/bpf: add arraymap " Yonghong Song
2021-02-25 23:26 ` 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=75afef04-efaf-a39b-97ce-3cd8d334bfbb@fb.com \
--to=yhs@fb.com \
--cc=andrii.nakryiko@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=xiyou.wangcong@gmail.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).