Skip to content

Commit

Permalink
selftests/bpf: Drain ringbuf samples at the end of test
Browse files Browse the repository at this point in the history
Avoid occasional test failures due to the last sample being delayed to
another ring_buffer__poll() call. Instead, drain samples completely with
ring_buffer__consume(). This is supposed to fix a rare and non-deterministic
test failure in libbpf CI.

Fixes: cb1c9dd ("selftests/bpf: Add BPF ringbuf selftests")
Signed-off-by: Andrii Nakryiko <[email protected]>
Signed-off-by: Alexei Starovoitov <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
  • Loading branch information
anakryiko authored and Alexei Starovoitov committed Dec 2, 2020
1 parent f6a8250 commit 156c9b7
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tools/testing/selftests/bpf/prog_tests/ringbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,12 @@ void test_ringbuf(void)
if (CHECK(bg_ret <= 0, "bg_ret", "epoll_wait result: %ld", bg_ret))
goto cleanup;

/* due to timing variations, there could still be non-notified
* samples, so consume them here to collect all the samples
*/
err = ring_buffer__consume(ringbuf);
CHECK(err < 0, "rb_consume", "failed: %d\b", err);

/* 3 rounds, 2 samples each */
cnt = atomic_xchg(&sample_cnt, 0);
CHECK(cnt != 6, "cnt", "exp %d samples, got %d\n", 6, cnt);
Expand Down

0 comments on commit 156c9b7

Please sign in to comment.