]> www.infradead.org Git - linux-platform-drivers-x86.git/commitdiff
selftests/bpf: ringbuf: Use runtime page size
authorYauheni Kaliuta <yauheni.kaliuta@redhat.com>
Thu, 8 Apr 2021 06:13:07 +0000 (09:13 +0300)
committerAndrii Nakryiko <andrii@kernel.org>
Fri, 9 Apr 2021 06:54:48 +0000 (23:54 -0700)
Replace hardcoded 4096 with runtime value in the userspace part of
the test and set bpf table sizes dynamically according to the 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-6-yauheni.kaliuta@redhat.com
tools/testing/selftests/bpf/prog_tests/ringbuf.c
tools/testing/selftests/bpf/progs/test_ringbuf.c

index fddbc5db5d6aefc7c53c1d037998130fdba950f2..de78617f65501f8b4cf7c9ca6c613dfb1f1cdd36 100644 (file)
@@ -87,11 +87,20 @@ void test_ringbuf(void)
        pthread_t thread;
        long bg_ret = -1;
        int err, cnt;
+       int page_size = getpagesize();
 
-       skel = test_ringbuf__open_and_load();
-       if (CHECK(!skel, "skel_open_load", "skeleton open&load failed\n"))
+       skel = test_ringbuf__open();
+       if (CHECK(!skel, "skel_open", "skeleton open failed\n"))
                return;
 
+       err = bpf_map__set_max_entries(skel->maps.ringbuf, page_size);
+       if (CHECK(err != 0, "bpf_map__set_max_entries", "bpf_map__set_max_entries failed\n"))
+               goto cleanup;
+
+       err = test_ringbuf__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();
 
@@ -110,9 +119,9 @@ void test_ringbuf(void)
        CHECK(skel->bss->avail_data != 3 * rec_sz,
              "err_avail_size", "exp %ld, got %ld\n",
              3L * rec_sz, skel->bss->avail_data);
-       CHECK(skel->bss->ring_size != 4096,
+       CHECK(skel->bss->ring_size != page_size,
              "err_ring_size", "exp %ld, got %ld\n",
-             4096L, skel->bss->ring_size);
+             (long)page_size, skel->bss->ring_size);
        CHECK(skel->bss->cons_pos != 0,
              "err_cons_pos", "exp %ld, got %ld\n",
              0L, skel->bss->cons_pos);
index 8ba9959b036b78609e0406d6633a04d3ca172498..6b3f288b7c63ca54bc714e1cbc98c4ca32afa8d4 100644 (file)
@@ -15,7 +15,6 @@ struct sample {
 
 struct {
        __uint(type, BPF_MAP_TYPE_RINGBUF);
-       __uint(max_entries, 1 << 12);
 } ringbuf SEC(".maps");
 
 /* inputs */