selftests/bpf: ringbuf_multi: Use runtime page size
authorYauheni Kaliuta <yauheni.kaliuta@redhat.com>
Thu, 8 Apr 2021 06:13:09 +0000 (09:13 +0300)
committerAndrii Nakryiko <andrii@kernel.org>
Fri, 9 Apr 2021 06:54:48 +0000 (23:54 -0700)
Set bpf table sizes dynamically according to the runtime page size
value.

Do not switch to ASSERT macros, keep CHECK, for consistency with the
rest of the test. Can be a separate cleanup patch.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20210408061310.95877-8-yauheni.kaliuta@redhat.com
tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c
tools/testing/selftests/bpf/progs/test_ringbuf_multi.c

index d37161e..159de99 100644 (file)
@@ -41,13 +41,30 @@ static int process_sample(void *ctx, void *data, size_t len)
 void test_ringbuf_multi(void)
 {
        struct test_ringbuf_multi *skel;
-       struct ring_buffer *ringbuf;
+       struct ring_buffer *ringbuf = NULL;
        int err;
+       int page_size = getpagesize();
 
-       skel = test_ringbuf_multi__open_and_load();
-       if (CHECK(!skel, "skel_open_load", "skeleton open&load failed\n"))
+       skel = test_ringbuf_multi__open();
+       if (CHECK(!skel, "skel_open", "skeleton open failed\n"))
                return;
 
+       err = bpf_map__set_max_entries(skel->maps.ringbuf1, page_size);
+       if (CHECK(err != 0, "bpf_map__set_max_entries", "bpf_map__set_max_entries failed\n"))
+               goto cleanup;
+
+       err = bpf_map__set_max_entries(skel->maps.ringbuf2, page_size);
+       if (CHECK(err != 0, "bpf_map__set_max_entries", "bpf_map__set_max_entries failed\n"))
+               goto cleanup;
+
+       err = bpf_map__set_max_entries(bpf_map__inner_map(skel->maps.ringbuf_arr), page_size);
+       if (CHECK(err != 0, "bpf_map__set_max_entries", "bpf_map__set_max_entries failed\n"))
+               goto cleanup;
+
+       err = test_ringbuf_multi__load(skel);
+       if (CHECK(err != 0, "skel_load", "skeleton load failed\n"))
+               goto cleanup;
+
        /* only trigger BPF program for current process */
        skel->bss->pid = getpid();
 
index edf3b69..055c10b 100644 (file)
@@ -15,7 +15,6 @@ struct sample {
 
 struct ringbuf_map {
        __uint(type, BPF_MAP_TYPE_RINGBUF);
-       __uint(max_entries, 1 << 12);
 } ringbuf1 SEC(".maps"),
   ringbuf2 SEC(".maps");