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

selftests/bpf: Add tests for ring__*_pos

Add tests for the new APIs ring__producer_pos and ring__consumer_pos.
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-7-martin.kelly@crowdstrike.com
parent 059a8c0c
......@@ -91,6 +91,8 @@ static void ringbuf_subtest(void)
int err, cnt, rb_fd;
int page_size = getpagesize();
void *mmap_ptr, *tmp_ptr;
struct ring *ring;
unsigned long cons_pos, prod_pos;
skel = test_ringbuf_lskel__open();
if (CHECK(!skel, "skel_open", "skeleton open failed\n"))
......@@ -162,6 +164,10 @@ static void ringbuf_subtest(void)
trigger_samples();
ring = ring_buffer__ring(ringbuf, 0);
if (!ASSERT_OK_PTR(ring, "ring_buffer__ring_idx_0"))
goto cleanup;
/* 2 submitted + 1 discarded records */
CHECK(skel->bss->avail_data != 3 * rec_sz,
"err_avail_size", "exp %ld, got %ld\n",
......@@ -176,6 +182,14 @@ static void ringbuf_subtest(void)
"err_prod_pos", "exp %ld, got %ld\n",
3L * rec_sz, skel->bss->prod_pos);
/* verify getting this data directly via the ring object yields the same
* results
*/
cons_pos = ring__consumer_pos(ring);
ASSERT_EQ(cons_pos, 0, "ring_cons_pos");
prod_pos = ring__producer_pos(ring);
ASSERT_EQ(prod_pos, 3 * rec_sz, "ring_prod_pos");
/* poll for samples */
err = ring_buffer__poll(ringbuf, -1);
......
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