Skip to content

Commit 94c0f69

Browse files
anakryikoKernel Patches Daemon
authored andcommitted
selftests/bpf: test eager BPF ringbuf size adjustment logic
Add test validating that libbpf adjusts (and reflects adjusted) ringbuf size early, before bpf_object is loaded. Also make sure we can't successfully resize ringbuf map after bpf_object is loaded. Signed-off-by: Andrii Nakryiko <[email protected]> Acked-by: Yonghong Song <[email protected]>
1 parent 0b93c56 commit 94c0f69

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ void test_ringbuf_multi(void)
5050
if (CHECK(!skel, "skel_open", "skeleton open failed\n"))
5151
return;
5252

53+
/* validate ringbuf size adjustment logic */
54+
ASSERT_EQ(bpf_map__max_entries(skel->maps.ringbuf1), page_size, "rb1_size_before");
55+
ASSERT_OK(bpf_map__set_max_entries(skel->maps.ringbuf1, page_size + 1), "rb1_resize");
56+
ASSERT_EQ(bpf_map__max_entries(skel->maps.ringbuf1), 2 * page_size, "rb1_size_after");
57+
ASSERT_OK(bpf_map__set_max_entries(skel->maps.ringbuf1, page_size), "rb1_reset");
58+
ASSERT_EQ(bpf_map__max_entries(skel->maps.ringbuf1), page_size, "rb1_size_final");
59+
5360
proto_fd = bpf_map_create(BPF_MAP_TYPE_RINGBUF, NULL, 0, 0, page_size, NULL);
5461
if (CHECK(proto_fd < 0, "bpf_map_create", "bpf_map_create failed\n"))
5562
goto cleanup;
@@ -65,6 +72,10 @@ void test_ringbuf_multi(void)
6572
close(proto_fd);
6673
proto_fd = -1;
6774

75+
/* make sure we can't resize ringbuf after object load */
76+
if (!ASSERT_ERR(bpf_map__set_max_entries(skel->maps.ringbuf1, 3 * page_size), "rb1_resize_after_load"))
77+
goto cleanup;
78+
6879
/* only trigger BPF program for current process */
6980
skel->bss->pid = getpid();
7081

0 commit comments

Comments
 (0)