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 8/8] selftests/bpf: add arraymap test for bpf_for_each_map_elem() helper
Date: Mon, 8 Feb 2021 22:50:25 -0800 [thread overview]
Message-ID: <b2c9f636-c2c2-52fe-1e4c-127dd32084eb@fb.com> (raw)
In-Reply-To: <CAEf4BzZoLT1vtS--mfZ4XJQ-HRwhbY3pxzN-2xci9FUkPqRwqg@mail.gmail.com>
On 2/8/21 10:35 AM, Andrii Nakryiko wrote:
> On Thu, Feb 4, 2021 at 5:53 PM Yonghong Song <yhs@fb.com> wrote:
>>
>> A test is added for arraymap and percpu arraymap. The test also
>> exercises the early return for the helper which does not
>> traverse all elements.
>> $ ./test_progs -n 44
>> #44/1 hash_map:OK
>> #44/2 array_map:OK
>> #44 for_each:OK
>> Summary: 1/2 PASSED, 0 SKIPPED, 0 FAILED
>>
>> Signed-off-by: Yonghong Song <yhs@fb.com>
>> ---
>> .../selftests/bpf/prog_tests/for_each.c | 54 ++++++++++++++
>> .../bpf/progs/for_each_array_map_elem.c | 71 +++++++++++++++++++
>> 2 files changed, 125 insertions(+)
>> create mode 100644 tools/testing/selftests/bpf/progs/for_each_array_map_elem.c
>>
>
> [...]
>
>> +
>> + arraymap_fd = bpf_map__fd(skel->maps.arraymap);
>> + expected_total = 0;
>> + max_entries = bpf_map__max_entries(skel->maps.arraymap);
>> + for (i = 0; i < max_entries; i++) {
>> + key = i;
>> + val = i + 1;
>> + /* skip the last iteration for expected total */
>> + if (i != max_entries - 1)
>> + expected_total += val;
>> + err = bpf_map_update_elem(arraymap_fd, &key, &val, BPF_ANY);
>> + if (CHECK(err, "map_update", "map_update failed\n"))
>> + goto out;
>> + }
>> +
>> + num_cpus = bpf_num_possible_cpus();
>> + percpu_map_fd = bpf_map__fd(skel->maps.percpu_map);
>
> formatting is off, please check with checkfile.pl
Sure. will do.
>
>
>> + percpu_valbuf = malloc(sizeof(__u64) * num_cpus);
>> + if (CHECK_FAIL(!percpu_valbuf))
>
> please don't use CHECK_FAIL, ASSERT_PTR_OK would work nicely here
Okay.
>
>> + goto out;
>> +
>> + key = 0;
>> + for (i = 0; i < num_cpus; i++)
>> + percpu_valbuf[i] = i + 1;
>> + err = bpf_map_update_elem(percpu_map_fd, &key, percpu_valbuf, BPF_ANY);
>> + if (CHECK(err, "percpu_map_update", "map_update failed\n"))
>> + goto out;
>> +
>> + do_dummy_read(skel->progs.dump_task);
>
> see previous patch, iter/tasks seems like an overkill for these tests
Yes, will use bpf_prog_test_run() in v2.
>
>> +
>> + ASSERT_EQ(skel->bss->called, 1, "called");
>> + ASSERT_EQ(skel->bss->arraymap_output, expected_total, "array_output");
>> + ASSERT_EQ(skel->bss->cpu + 1, skel->bss->percpu_val, "percpu_val");
>> +
>> +out:
>> + free(percpu_valbuf);
>> + for_each_array_map_elem__destroy(skel);
>> +}
>> +
>
> [...]
>
>> +SEC("iter/task")
>> +int dump_task(struct bpf_iter__task *ctx)
>> +{
>> + struct seq_file *seq = ctx->meta->seq;
>> + struct task_struct *task = ctx->task;
>> + struct callback_ctx data;
>> +
>> + /* only call once */
>> + if (called > 0)
>> + return 0;
>> +
>> + called++;
>> +
>> + data.output = 0;
>> + bpf_for_each_map_elem(&arraymap, check_array_elem, &data, 0);
>> + arraymap_output = data.output;
>> +
>> + bpf_for_each_map_elem(&percpu_map, check_percpu_elem, 0, 0);
>
> nit: NULL, 0 ?
We do not NULL defined in vmlinux.h or bpf_helpers.h. Hence I am using
0, I should at least use (void *)0 here, I think.
>
>> +
>> + return 0;
>> +}
>> --
>> 2.24.1
>>
next prev parent reply other threads:[~2021-02-09 6:51 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-04 23:48 [PATCH bpf-next 0/8] bpf: add bpf_for_each_map_elem() helper Yonghong Song
2021-02-04 23:48 ` [PATCH bpf-next 1/8] bpf: refactor BPF_PSEUDO_CALL checking as a helper function Yonghong Song
2021-02-05 5:59 ` Alexei Starovoitov
2021-02-04 23:48 ` [PATCH bpf-next 2/8] bpf: add bpf_for_each_map_elem() helper Yonghong Song
2021-02-05 5:49 ` Alexei Starovoitov
2021-02-05 17:39 ` Yonghong Song
2021-02-08 18:16 ` Andrii Nakryiko
2021-02-09 6:41 ` Yonghong Song
2021-02-09 17:33 ` Andrii Nakryiko
2021-02-04 23:48 ` [PATCH bpf-next 3/8] bpf: add hashtab support for " Yonghong Song
2021-02-05 6:23 ` Alexei Starovoitov
2021-02-05 17:49 ` Yonghong Song
2021-02-04 23:48 ` [PATCH bpf-next 4/8] bpf: add arraymap " Yonghong Song
2021-02-04 23:48 ` [PATCH bpf-next 5/8] libbpf: support local function pointer relocation Yonghong Song
2021-02-08 18:52 ` Andrii Nakryiko
2021-02-09 6:56 ` Yonghong Song
2021-02-09 17:31 ` Andrii Nakryiko
2021-02-04 23:48 ` [PATCH bpf-next 6/8] bpftool: print local function pointer properly Yonghong Song
2021-02-08 18:22 ` Andrii Nakryiko
2021-02-09 6:42 ` Yonghong Song
2021-02-04 23:48 ` [PATCH bpf-next 7/8] selftests/bpf: add hashmap test for bpf_for_each_map_elem() helper Yonghong Song
2021-02-08 18:34 ` Andrii Nakryiko
2021-02-09 6:46 ` Yonghong Song
2021-02-09 17:36 ` Andrii Nakryiko
2021-02-04 23:48 ` [PATCH bpf-next 8/8] selftests/bpf: add arraymap " Yonghong Song
2021-02-08 18:35 ` Andrii Nakryiko
2021-02-09 6:50 ` Yonghong Song [this message]
2021-02-09 17:38 ` 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=b2c9f636-c2c2-52fe-1e4c-127dd32084eb@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