Commit f6a8250e authored by Andrii Nakryiko's avatar Andrii Nakryiko Committed by Alexei Starovoitov

libbpf: Fix ring_buffer__poll() to return number of consumed samples

Fix ring_buffer__poll() to return the number of non-discarded records
consumed, just like its documentation states. It's also consistent with
ring_buffer__consume() return. Fix up selftests with wrong expected results.

Fixes: bf99c936 ("libbpf: Add BPF ring buffer support")
Fixes: cb1c9ddd ("selftests/bpf: Add BPF ringbuf selftests")
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20201130223336.904192-1-andrii@kernel.org
parent ed1182dc
...@@ -278,7 +278,7 @@ int ring_buffer__poll(struct ring_buffer *rb, int timeout_ms) ...@@ -278,7 +278,7 @@ int ring_buffer__poll(struct ring_buffer *rb, int timeout_ms)
err = ringbuf_process_ring(ring); err = ringbuf_process_ring(ring);
if (err < 0) if (err < 0)
return err; return err;
res += cnt; res += err;
} }
return cnt < 0 ? -errno : res; return cnt < 0 ? -errno : res;
} }
...@@ -217,7 +217,7 @@ void test_ringbuf(void) ...@@ -217,7 +217,7 @@ void test_ringbuf(void)
if (CHECK(err, "join_bg", "err %d\n", err)) if (CHECK(err, "join_bg", "err %d\n", err))
goto cleanup; goto cleanup;
if (CHECK(bg_ret != 1, "bg_ret", "epoll_wait result: %ld", bg_ret)) if (CHECK(bg_ret <= 0, "bg_ret", "epoll_wait result: %ld", bg_ret))
goto cleanup; goto cleanup;
/* 3 rounds, 2 samples each */ /* 3 rounds, 2 samples each */
......
...@@ -81,7 +81,7 @@ void test_ringbuf_multi(void) ...@@ -81,7 +81,7 @@ void test_ringbuf_multi(void)
/* poll for samples, should get 2 ringbufs back */ /* poll for samples, should get 2 ringbufs back */
err = ring_buffer__poll(ringbuf, -1); err = ring_buffer__poll(ringbuf, -1);
if (CHECK(err != 4, "poll_res", "expected 4 records, got %d\n", err)) if (CHECK(err != 2, "poll_res", "expected 2 records, got %d\n", err))
goto cleanup; goto cleanup;
/* expect extra polling to return nothing */ /* expect extra polling to return nothing */
......
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