[PATCH bpf-next 2/2] selftests/bpf: add tests for ring_buffer__query

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Confirm we get the same results using ring_buffer__query from the
usermode side as from the corresponding BPF helper.

Signed-off-by: Martin Kelly <martin.kelly@xxxxxxxxxxxxxxx>
---
 .../selftests/bpf/prog_tests/ringbuf.c        | 22 +++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/tools/testing/selftests/bpf/prog_tests/ringbuf.c b/tools/testing/selftests/bpf/prog_tests/ringbuf.c
index ac104dc652e3..93dcb92fc0c5 100644
--- a/tools/testing/selftests/bpf/prog_tests/ringbuf.c
+++ b/tools/testing/selftests/bpf/prog_tests/ringbuf.c
@@ -91,6 +91,7 @@ static void ringbuf_subtest(void)
 	int err, cnt, rb_fd;
 	int page_size = getpagesize();
 	void *mmap_ptr, *tmp_ptr;
+	__u64 val;
 
 	skel = test_ringbuf_lskel__open();
 	if (CHECK(!skel, "skel_open", "skeleton open failed\n"))
@@ -176,6 +177,27 @@ static void ringbuf_subtest(void)
 	      "err_prod_pos", "exp %ld, got %ld\n",
 	      3L * rec_sz, skel->bss->prod_pos);
 
+	/* verify the same results from the usermode side */
+	val = ring_buffer__query(ringbuf, 0, BPF_RB_AVAIL_DATA);
+	CHECK(val != 3 * rec_sz,
+	      "err_query_avail_size", "exp %ld, got %llu\n",
+	      3L * rec_sz, val);
+
+	val = ring_buffer__query(ringbuf, 0, BPF_RB_RING_SIZE);
+	CHECK(val != page_size,
+	      "err_query_ring_size", "exp %ld, got %llu\n",
+	      (long)page_size, val);
+
+	val = ring_buffer__query(ringbuf, 0, BPF_RB_CONS_POS);
+	CHECK(val != 0,
+	      "err_query_cons_pos", "exp %ld, got %llu\n",
+	      0L, val);
+
+	val = ring_buffer__query(ringbuf, 0, BPF_RB_PROD_POS);
+	CHECK(val != 3 * rec_sz,
+	      "err_query_prod_pos", "exp %ld, got %llu\n",
+	      3L * rec_sz, val);
+
 	/* poll for samples */
 	err = ring_buffer__poll(ringbuf, -1);
 
-- 
2.34.1





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux