Commit c1ad2e47 authored by Martin Kelly's avatar Martin Kelly Committed by Andrii Nakryiko

selftests/bpf: Add tests for ring_buffer__ring

Add tests for the new API ring_buffer__ring.
Signed-off-by: default avatarMartin Kelly <martin.kelly@crowdstrike.com>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20230925215045.2375758-5-martin.kelly@crowdstrike.com
parent 1c97f6af
...@@ -42,6 +42,8 @@ void test_ringbuf_multi(void) ...@@ -42,6 +42,8 @@ void test_ringbuf_multi(void)
{ {
struct test_ringbuf_multi *skel; struct test_ringbuf_multi *skel;
struct ring_buffer *ringbuf = NULL; struct ring_buffer *ringbuf = NULL;
struct ring *ring_old;
struct ring *ring;
int err; int err;
int page_size = getpagesize(); int page_size = getpagesize();
int proto_fd = -1; int proto_fd = -1;
...@@ -84,11 +86,24 @@ void test_ringbuf_multi(void) ...@@ -84,11 +86,24 @@ void test_ringbuf_multi(void)
if (CHECK(!ringbuf, "ringbuf_create", "failed to create ringbuf\n")) if (CHECK(!ringbuf, "ringbuf_create", "failed to create ringbuf\n"))
goto cleanup; goto cleanup;
/* verify ring_buffer__ring returns expected results */
ring = ring_buffer__ring(ringbuf, 0);
if (!ASSERT_OK_PTR(ring, "ring_buffer__ring_idx_0"))
goto cleanup;
ring_old = ring;
ring = ring_buffer__ring(ringbuf, 1);
ASSERT_ERR_PTR(ring, "ring_buffer__ring_idx_1");
err = ring_buffer__add(ringbuf, bpf_map__fd(skel->maps.ringbuf2), err = ring_buffer__add(ringbuf, bpf_map__fd(skel->maps.ringbuf2),
process_sample, (void *)(long)2); process_sample, (void *)(long)2);
if (CHECK(err, "ringbuf_add", "failed to add another ring\n")) if (CHECK(err, "ringbuf_add", "failed to add another ring\n"))
goto cleanup; goto cleanup;
/* verify adding a new ring didn't invalidate our older pointer */
ring = ring_buffer__ring(ringbuf, 0);
if (!ASSERT_EQ(ring, ring_old, "ring_buffer__ring_again"))
goto cleanup;
err = test_ringbuf_multi__attach(skel); err = test_ringbuf_multi__attach(skel);
if (CHECK(err, "skel_attach", "skeleton attachment failed: %d\n", err)) if (CHECK(err, "skel_attach", "skeleton attachment failed: %d\n", err))
goto cleanup; goto cleanup;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment