]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
selftests/bpf: Drain ringbuf samples at the end of test
authorAndrii Nakryiko <andrii@kernel.org>
Mon, 30 Nov 2020 22:33:36 +0000 (14:33 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 2 Dec 2020 04:21:45 +0000 (20:21 -0800)
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: cb1c9ddd5525 ("selftests/bpf: Add BPF ringbuf selftests")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20201130223336.904192-2-andrii@kernel.org
tools/testing/selftests/bpf/prog_tests/ringbuf.c

index 1a48c6f7f54e42ee15fed279d3289b1237a15c9d..fddbc5db5d6aefc7c53c1d037998130fdba950f2 100644 (file)
@@ -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);