1cb1c9dddSAndrii Nakryiko// SPDX-License-Identifier: GPL-2.0
2cb1c9dddSAndrii Nakryiko#define _GNU_SOURCE
3cb1c9dddSAndrii Nakryiko#include <linux/compiler.h>
4cb1c9dddSAndrii Nakryiko#include <asm/barrier.h>
5cb1c9dddSAndrii Nakryiko#include <test_progs.h>
6cb1c9dddSAndrii Nakryiko#include <sys/mman.h>
7cb1c9dddSAndrii Nakryiko#include <sys/epoll.h>
8cb1c9dddSAndrii Nakryiko#include <time.h>
9cb1c9dddSAndrii Nakryiko#include <sched.h>
10cb1c9dddSAndrii Nakryiko#include <signal.h>
11cb1c9dddSAndrii Nakryiko#include <pthread.h>
12cb1c9dddSAndrii Nakryiko#include <sys/sysinfo.h>
13cb1c9dddSAndrii Nakryiko#include <linux/perf_event.h>
14cb1c9dddSAndrii Nakryiko#include <linux/ring_buffer.h>
154d1b6298SAlexei Starovoitov#include "test_ringbuf.lskel.h"
16cb1c9dddSAndrii Nakryiko
17cb1c9dddSAndrii Nakryiko#define EDONE 7777
18cb1c9dddSAndrii Nakryiko
19cb1c9dddSAndrii Nakryikostatic int duration = 0;
20cb1c9dddSAndrii Nakryiko
21cb1c9dddSAndrii Nakryikostruct sample {
22cb1c9dddSAndrii Nakryiko	int pid;
23cb1c9dddSAndrii Nakryiko	int seq;
24cb1c9dddSAndrii Nakryiko	long value;
25cb1c9dddSAndrii Nakryiko	char comm[16];
26cb1c9dddSAndrii Nakryiko};
27cb1c9dddSAndrii Nakryiko
281f243622SAndrii Nakryikostatic int sample_cnt;
291f243622SAndrii Nakryiko
301f243622SAndrii Nakryikostatic void atomic_inc(int *cnt)
311f243622SAndrii Nakryiko{
321f243622SAndrii Nakryiko	__atomic_add_fetch(cnt, 1, __ATOMIC_SEQ_CST);
331f243622SAndrii Nakryiko}
341f243622SAndrii Nakryiko
351f243622SAndrii Nakryikostatic int atomic_xchg(int *cnt, int val)
361f243622SAndrii Nakryiko{
371f243622SAndrii Nakryiko	return __atomic_exchange_n(cnt, val, __ATOMIC_SEQ_CST);
381f243622SAndrii Nakryiko}
39cb1c9dddSAndrii Nakryiko
40cb1c9dddSAndrii Nakryikostatic int process_sample(void *ctx, void *data, size_t len)
41cb1c9dddSAndrii Nakryiko{
42cb1c9dddSAndrii Nakryiko	struct sample *s = data;
43cb1c9dddSAndrii Nakryiko
441f243622SAndrii Nakryiko	atomic_inc(&sample_cnt);
45cb1c9dddSAndrii Nakryiko
46cb1c9dddSAndrii Nakryiko	switch (s->seq) {
47cb1c9dddSAndrii Nakryiko	case 0:
48cb1c9dddSAndrii Nakryiko		CHECK(s->value != 333, "sample1_value", "exp %ld, got %ld\n",
49cb1c9dddSAndrii Nakryiko		      333L, s->value);
50cb1c9dddSAndrii Nakryiko		return 0;
51cb1c9dddSAndrii Nakryiko	case 1:
52cb1c9dddSAndrii Nakryiko		CHECK(s->value != 777, "sample2_value", "exp %ld, got %ld\n",
53cb1c9dddSAndrii Nakryiko		      777L, s->value);
54cb1c9dddSAndrii Nakryiko		return -EDONE;
55cb1c9dddSAndrii Nakryiko	default:
56cb1c9dddSAndrii Nakryiko		/* we don't care about the rest */
57cb1c9dddSAndrii Nakryiko		return 0;
58cb1c9dddSAndrii Nakryiko	}
59cb1c9dddSAndrii Nakryiko}
60cb1c9dddSAndrii Nakryiko
61087cba79SKumar Kartikeya Dwivedistatic struct test_ringbuf_lskel *skel;
62cb1c9dddSAndrii Nakryikostatic struct ring_buffer *ringbuf;
63cb1c9dddSAndrii Nakryiko
64cb1c9dddSAndrii Nakryikostatic void trigger_samples()
65cb1c9dddSAndrii Nakryiko{
66cb1c9dddSAndrii Nakryiko	skel->bss->dropped = 0;
67cb1c9dddSAndrii Nakryiko	skel->bss->total = 0;
68cb1c9dddSAndrii Nakryiko	skel->bss->discarded = 0;
69cb1c9dddSAndrii Nakryiko
70cb1c9dddSAndrii Nakryiko	/* trigger exactly two samples */
71cb1c9dddSAndrii Nakryiko	skel->bss->value = 333;
72cb1c9dddSAndrii Nakryiko	syscall(__NR_getpgid);
73cb1c9dddSAndrii Nakryiko	skel->bss->value = 777;
74cb1c9dddSAndrii Nakryiko	syscall(__NR_getpgid);
75cb1c9dddSAndrii Nakryiko}
76cb1c9dddSAndrii Nakryiko
77cb1c9dddSAndrii Nakryikostatic void *poll_thread(void *input)
78cb1c9dddSAndrii Nakryiko{
79cb1c9dddSAndrii Nakryiko	long timeout = (long)input;
80cb1c9dddSAndrii Nakryiko
81cb1c9dddSAndrii Nakryiko	return (void *)(long)ring_buffer__poll(ringbuf, timeout);
82cb1c9dddSAndrii Nakryiko}
83cb1c9dddSAndrii Nakryiko
84cb1c9dddSAndrii Nakryikovoid test_ringbuf(void)
85cb1c9dddSAndrii Nakryiko{
86cb1c9dddSAndrii Nakryiko	const size_t rec_sz = BPF_RINGBUF_HDR_SZ + sizeof(struct sample);
87cb1c9dddSAndrii Nakryiko	pthread_t thread;
88cb1c9dddSAndrii Nakryiko	long bg_ret = -1;
89704e2bebSAndrii Nakryiko	int err, cnt, rb_fd;
9023a65766SYauheni Kaliuta	int page_size = getpagesize();
91704e2bebSAndrii Nakryiko	void *mmap_ptr, *tmp_ptr;
92cb1c9dddSAndrii Nakryiko
93087cba79SKumar Kartikeya Dwivedi	skel = test_ringbuf_lskel__open();
9423a65766SYauheni Kaliuta	if (CHECK(!skel, "skel_open", "skeleton open failed\n"))
95cb1c9dddSAndrii Nakryiko		return;
96cb1c9dddSAndrii Nakryiko
974d1b6298SAlexei Starovoitov	skel->maps.ringbuf.max_entries = page_size;
9823a65766SYauheni Kaliuta
99087cba79SKumar Kartikeya Dwivedi	err = test_ringbuf_lskel__load(skel);
10023a65766SYauheni Kaliuta	if (CHECK(err != 0, "skel_load", "skeleton load failed\n"))
10123a65766SYauheni Kaliuta		goto cleanup;
10223a65766SYauheni Kaliuta
1030c38740cSAndrii Nakryiko	rb_fd = skel->maps.ringbuf.map_fd;
104704e2bebSAndrii Nakryiko	/* good read/write cons_pos */
105704e2bebSAndrii Nakryiko	mmap_ptr = mmap(NULL, page_size, PROT_READ | PROT_WRITE, MAP_SHARED, rb_fd, 0);
106704e2bebSAndrii Nakryiko	ASSERT_OK_PTR(mmap_ptr, "rw_cons_pos");
107704e2bebSAndrii Nakryiko	tmp_ptr = mremap(mmap_ptr, page_size, 2 * page_size, MREMAP_MAYMOVE);
108704e2bebSAndrii Nakryiko	if (!ASSERT_ERR_PTR(tmp_ptr, "rw_extend"))
109704e2bebSAndrii Nakryiko		goto cleanup;
110704e2bebSAndrii Nakryiko	ASSERT_ERR(mprotect(mmap_ptr, page_size, PROT_EXEC), "exec_cons_pos_protect");
111704e2bebSAndrii Nakryiko	ASSERT_OK(munmap(mmap_ptr, page_size), "unmap_rw");
112704e2bebSAndrii Nakryiko
113704e2bebSAndrii Nakryiko	/* bad writeable prod_pos */
114704e2bebSAndrii Nakryiko	mmap_ptr = mmap(NULL, page_size, PROT_WRITE, MAP_SHARED, rb_fd, page_size);
115704e2bebSAndrii Nakryiko	err = -errno;
116704e2bebSAndrii Nakryiko	ASSERT_ERR_PTR(mmap_ptr, "wr_prod_pos");
117704e2bebSAndrii Nakryiko	ASSERT_EQ(err, -EPERM, "wr_prod_pos_err");
118704e2bebSAndrii Nakryiko
119704e2bebSAndrii Nakryiko	/* bad writeable data pages */
120704e2bebSAndrii Nakryiko	mmap_ptr = mmap(NULL, page_size, PROT_WRITE, MAP_SHARED, rb_fd, 2 * page_size);
121704e2bebSAndrii Nakryiko	err = -errno;
122704e2bebSAndrii Nakryiko	ASSERT_ERR_PTR(mmap_ptr, "wr_data_page_one");
123704e2bebSAndrii Nakryiko	ASSERT_EQ(err, -EPERM, "wr_data_page_one_err");
124704e2bebSAndrii Nakryiko	mmap_ptr = mmap(NULL, page_size, PROT_WRITE, MAP_SHARED, rb_fd, 3 * page_size);
125704e2bebSAndrii Nakryiko	ASSERT_ERR_PTR(mmap_ptr, "wr_data_page_two");
126704e2bebSAndrii Nakryiko	mmap_ptr = mmap(NULL, 2 * page_size, PROT_WRITE, MAP_SHARED, rb_fd, 2 * page_size);
127704e2bebSAndrii Nakryiko	ASSERT_ERR_PTR(mmap_ptr, "wr_data_page_all");
128704e2bebSAndrii Nakryiko
129704e2bebSAndrii Nakryiko	/* good read-only pages */
130704e2bebSAndrii Nakryiko	mmap_ptr = mmap(NULL, 4 * page_size, PROT_READ, MAP_SHARED, rb_fd, 0);
131704e2bebSAndrii Nakryiko	if (!ASSERT_OK_PTR(mmap_ptr, "ro_prod_pos"))
132704e2bebSAndrii Nakryiko		goto cleanup;
133704e2bebSAndrii Nakryiko
134704e2bebSAndrii Nakryiko	ASSERT_ERR(mprotect(mmap_ptr, 4 * page_size, PROT_WRITE), "write_protect");
135704e2bebSAndrii Nakryiko	ASSERT_ERR(mprotect(mmap_ptr, 4 * page_size, PROT_EXEC), "exec_protect");
136704e2bebSAndrii Nakryiko	ASSERT_ERR_PTR(mremap(mmap_ptr, 0, 4 * page_size, MREMAP_MAYMOVE), "ro_remap");
137704e2bebSAndrii Nakryiko	ASSERT_OK(munmap(mmap_ptr, 4 * page_size), "unmap_ro");
138704e2bebSAndrii Nakryiko
139704e2bebSAndrii Nakryiko	/* good read-only pages with initial offset */
140704e2bebSAndrii Nakryiko	mmap_ptr = mmap(NULL, page_size, PROT_READ, MAP_SHARED, rb_fd, page_size);
141704e2bebSAndrii Nakryiko	if (!ASSERT_OK_PTR(mmap_ptr, "ro_prod_pos"))
142704e2bebSAndrii Nakryiko		goto cleanup;
143704e2bebSAndrii Nakryiko
144704e2bebSAndrii Nakryiko	ASSERT_ERR(mprotect(mmap_ptr, page_size, PROT_WRITE), "write_protect");
145704e2bebSAndrii Nakryiko	ASSERT_ERR(mprotect(mmap_ptr, page_size, PROT_EXEC), "exec_protect");
146704e2bebSAndrii Nakryiko	ASSERT_ERR_PTR(mremap(mmap_ptr, 0, 3 * page_size, MREMAP_MAYMOVE), "ro_remap");
147704e2bebSAndrii Nakryiko	ASSERT_OK(munmap(mmap_ptr, page_size), "unmap_ro");
148704e2bebSAndrii Nakryiko
149cb1c9dddSAndrii Nakryiko	/* only trigger BPF program for current process */
150cb1c9dddSAndrii Nakryiko	skel->bss->pid = getpid();
151cb1c9dddSAndrii Nakryiko
1524d1b6298SAlexei Starovoitov	ringbuf = ring_buffer__new(skel->maps.ringbuf.map_fd,
153cb1c9dddSAndrii Nakryiko				   process_sample, NULL, NULL);
154cb1c9dddSAndrii Nakryiko	if (CHECK(!ringbuf, "ringbuf_create", "failed to create ringbuf\n"))
155cb1c9dddSAndrii Nakryiko		goto cleanup;
156cb1c9dddSAndrii Nakryiko
157087cba79SKumar Kartikeya Dwivedi	err = test_ringbuf_lskel__attach(skel);
158cb1c9dddSAndrii Nakryiko	if (CHECK(err, "skel_attach", "skeleton attachment failed: %d\n", err))
159cb1c9dddSAndrii Nakryiko		goto cleanup;
160cb1c9dddSAndrii Nakryiko
161cb1c9dddSAndrii Nakryiko	trigger_samples();
162cb1c9dddSAndrii Nakryiko
163cb1c9dddSAndrii Nakryiko	/* 2 submitted + 1 discarded records */
164cb1c9dddSAndrii Nakryiko	CHECK(skel->bss->avail_data != 3 * rec_sz,
165cb1c9dddSAndrii Nakryiko	      "err_avail_size", "exp %ld, got %ld\n",
166cb1c9dddSAndrii Nakryiko	      3L * rec_sz, skel->bss->avail_data);
16723a65766SYauheni Kaliuta	CHECK(skel->bss->ring_size != page_size,
168cb1c9dddSAndrii Nakryiko	      "err_ring_size", "exp %ld, got %ld\n",
16923a65766SYauheni Kaliuta	      (long)page_size, skel->bss->ring_size);
170cb1c9dddSAndrii Nakryiko	CHECK(skel->bss->cons_pos != 0,
171cb1c9dddSAndrii Nakryiko	      "err_cons_pos", "exp %ld, got %ld\n",
172cb1c9dddSAndrii Nakryiko	      0L, skel->bss->cons_pos);
173cb1c9dddSAndrii Nakryiko	CHECK(skel->bss->prod_pos != 3 * rec_sz,
174cb1c9dddSAndrii Nakryiko	      "err_prod_pos", "exp %ld, got %ld\n",
175cb1c9dddSAndrii Nakryiko	      3L * rec_sz, skel->bss->prod_pos);
176cb1c9dddSAndrii Nakryiko
177cb1c9dddSAndrii Nakryiko	/* poll for samples */
178cb1c9dddSAndrii Nakryiko	err = ring_buffer__poll(ringbuf, -1);
179cb1c9dddSAndrii Nakryiko
180cb1c9dddSAndrii Nakryiko	/* -EDONE is used as an indicator that we are done */
181cb1c9dddSAndrii Nakryiko	if (CHECK(err != -EDONE, "err_done", "done err: %d\n", err))
182cb1c9dddSAndrii Nakryiko		goto cleanup;
1831f243622SAndrii Nakryiko	cnt = atomic_xchg(&sample_cnt, 0);
1841f243622SAndrii Nakryiko	CHECK(cnt != 2, "cnt", "exp %d samples, got %d\n", 2, cnt);
185cb1c9dddSAndrii Nakryiko
186cb1c9dddSAndrii Nakryiko	/* we expect extra polling to return nothing */
187cb1c9dddSAndrii Nakryiko	err = ring_buffer__poll(ringbuf, 0);
188cb1c9dddSAndrii Nakryiko	if (CHECK(err != 0, "extra_samples", "poll result: %d\n", err))
189cb1c9dddSAndrii Nakryiko		goto cleanup;
1901f243622SAndrii Nakryiko	cnt = atomic_xchg(&sample_cnt, 0);
1911f243622SAndrii Nakryiko	CHECK(cnt != 0, "cnt", "exp %d samples, got %d\n", 0, cnt);
192cb1c9dddSAndrii Nakryiko
193cb1c9dddSAndrii Nakryiko	CHECK(skel->bss->dropped != 0, "err_dropped", "exp %ld, got %ld\n",
194cb1c9dddSAndrii Nakryiko	      0L, skel->bss->dropped);
195cb1c9dddSAndrii Nakryiko	CHECK(skel->bss->total != 2, "err_total", "exp %ld, got %ld\n",
196cb1c9dddSAndrii Nakryiko	      2L, skel->bss->total);
197cb1c9dddSAndrii Nakryiko	CHECK(skel->bss->discarded != 1, "err_discarded", "exp %ld, got %ld\n",
198cb1c9dddSAndrii Nakryiko	      1L, skel->bss->discarded);
199cb1c9dddSAndrii Nakryiko
200cb1c9dddSAndrii Nakryiko	/* now validate consumer position is updated and returned */
201cb1c9dddSAndrii Nakryiko	trigger_samples();
202cb1c9dddSAndrii Nakryiko	CHECK(skel->bss->cons_pos != 3 * rec_sz,
203cb1c9dddSAndrii Nakryiko	      "err_cons_pos", "exp %ld, got %ld\n",
204cb1c9dddSAndrii Nakryiko	      3L * rec_sz, skel->bss->cons_pos);
205cb1c9dddSAndrii Nakryiko	err = ring_buffer__poll(ringbuf, -1);
206cb1c9dddSAndrii Nakryiko	CHECK(err <= 0, "poll_err", "err %d\n", err);
2071f243622SAndrii Nakryiko	cnt = atomic_xchg(&sample_cnt, 0);
2081f243622SAndrii Nakryiko	CHECK(cnt != 2, "cnt", "exp %d samples, got %d\n", 2, cnt);
209cb1c9dddSAndrii Nakryiko
210cb1c9dddSAndrii Nakryiko	/* start poll in background w/ long timeout */
211cb1c9dddSAndrii Nakryiko	err = pthread_create(&thread, NULL, poll_thread, (void *)(long)10000);
212cb1c9dddSAndrii Nakryiko	if (CHECK(err, "bg_poll", "pthread_create failed: %d\n", err))
213cb1c9dddSAndrii Nakryiko		goto cleanup;
214cb1c9dddSAndrii Nakryiko
215cb1c9dddSAndrii Nakryiko	/* turn off notifications now */
216cb1c9dddSAndrii Nakryiko	skel->bss->flags = BPF_RB_NO_WAKEUP;
217cb1c9dddSAndrii Nakryiko
218cb1c9dddSAndrii Nakryiko	/* give background thread a bit of a time */
219cb1c9dddSAndrii Nakryiko	usleep(50000);
220cb1c9dddSAndrii Nakryiko	trigger_samples();
221cb1c9dddSAndrii Nakryiko	/* sleeping arbitrarily is bad, but no better way to know that
222cb1c9dddSAndrii Nakryiko	 * epoll_wait() **DID NOT** unblock in background thread
223cb1c9dddSAndrii Nakryiko	 */
224cb1c9dddSAndrii Nakryiko	usleep(50000);
225cb1c9dddSAndrii Nakryiko	/* background poll should still be blocked */
226cb1c9dddSAndrii Nakryiko	err = pthread_tryjoin_np(thread, (void **)&bg_ret);
227cb1c9dddSAndrii Nakryiko	if (CHECK(err != EBUSY, "try_join", "err %d\n", err))
228cb1c9dddSAndrii Nakryiko		goto cleanup;
229cb1c9dddSAndrii Nakryiko
230cb1c9dddSAndrii Nakryiko	/* BPF side did everything right */
231cb1c9dddSAndrii Nakryiko	CHECK(skel->bss->dropped != 0, "err_dropped", "exp %ld, got %ld\n",
232cb1c9dddSAndrii Nakryiko	      0L, skel->bss->dropped);
233cb1c9dddSAndrii Nakryiko	CHECK(skel->bss->total != 2, "err_total", "exp %ld, got %ld\n",
234cb1c9dddSAndrii Nakryiko	      2L, skel->bss->total);
235cb1c9dddSAndrii Nakryiko	CHECK(skel->bss->discarded != 1, "err_discarded", "exp %ld, got %ld\n",
236cb1c9dddSAndrii Nakryiko	      1L, skel->bss->discarded);
2371f243622SAndrii Nakryiko	cnt = atomic_xchg(&sample_cnt, 0);
2381f243622SAndrii Nakryiko	CHECK(cnt != 0, "cnt", "exp %d samples, got %d\n", 0, cnt);
239cb1c9dddSAndrii Nakryiko
240cb1c9dddSAndrii Nakryiko	/* clear flags to return to "adaptive" notification mode */
241cb1c9dddSAndrii Nakryiko	skel->bss->flags = 0;
242cb1c9dddSAndrii Nakryiko
243cb1c9dddSAndrii Nakryiko	/* produce new samples, no notification should be triggered, because
244cb1c9dddSAndrii Nakryiko	 * consumer is now behind
245cb1c9dddSAndrii Nakryiko	 */
246cb1c9dddSAndrii Nakryiko	trigger_samples();
247cb1c9dddSAndrii Nakryiko
248cb1c9dddSAndrii Nakryiko	/* background poll should still be blocked */
249cb1c9dddSAndrii Nakryiko	err = pthread_tryjoin_np(thread, (void **)&bg_ret);
250cb1c9dddSAndrii Nakryiko	if (CHECK(err != EBUSY, "try_join", "err %d\n", err))
251cb1c9dddSAndrii Nakryiko		goto cleanup;
252cb1c9dddSAndrii Nakryiko
2531f243622SAndrii Nakryiko	/* still no samples, because consumer is behind */
2541f243622SAndrii Nakryiko	cnt = atomic_xchg(&sample_cnt, 0);
2551f243622SAndrii Nakryiko	CHECK(cnt != 0, "cnt", "exp %d samples, got %d\n", 0, cnt);
2561f243622SAndrii Nakryiko
2571f243622SAndrii Nakryiko	skel->bss->dropped = 0;
2581f243622SAndrii Nakryiko	skel->bss->total = 0;
2591f243622SAndrii Nakryiko	skel->bss->discarded = 0;
2601f243622SAndrii Nakryiko
2611f243622SAndrii Nakryiko	skel->bss->value = 333;
2621f243622SAndrii Nakryiko	syscall(__NR_getpgid);
263cb1c9dddSAndrii Nakryiko	/* now force notifications */
264cb1c9dddSAndrii Nakryiko	skel->bss->flags = BPF_RB_FORCE_WAKEUP;
2651f243622SAndrii Nakryiko	skel->bss->value = 777;
2661f243622SAndrii Nakryiko	syscall(__NR_getpgid);
267cb1c9dddSAndrii Nakryiko
268cb1c9dddSAndrii Nakryiko	/* now we should get a pending notification */
269cb1c9dddSAndrii Nakryiko	usleep(50000);
270cb1c9dddSAndrii Nakryiko	err = pthread_tryjoin_np(thread, (void **)&bg_ret);
271cb1c9dddSAndrii Nakryiko	if (CHECK(err, "join_bg", "err %d\n", err))
272cb1c9dddSAndrii Nakryiko		goto cleanup;
273cb1c9dddSAndrii Nakryiko
274f6a8250eSAndrii Nakryiko	if (CHECK(bg_ret <= 0, "bg_ret", "epoll_wait result: %ld", bg_ret))
275cb1c9dddSAndrii Nakryiko		goto cleanup;
276cb1c9dddSAndrii Nakryiko
277156c9b70SAndrii Nakryiko	/* due to timing variations, there could still be non-notified
278156c9b70SAndrii Nakryiko	 * samples, so consume them here to collect all the samples
279156c9b70SAndrii Nakryiko	 */
280156c9b70SAndrii Nakryiko	err = ring_buffer__consume(ringbuf);
281156c9b70SAndrii Nakryiko	CHECK(err < 0, "rb_consume", "failed: %d\b", err);
282156c9b70SAndrii Nakryiko
283cb1c9dddSAndrii Nakryiko	/* 3 rounds, 2 samples each */
2841f243622SAndrii Nakryiko	cnt = atomic_xchg(&sample_cnt, 0);
2851f243622SAndrii Nakryiko	CHECK(cnt != 6, "cnt", "exp %d samples, got %d\n", 6, cnt);
286cb1c9dddSAndrii Nakryiko
287cb1c9dddSAndrii Nakryiko	/* BPF side did everything right */
288cb1c9dddSAndrii Nakryiko	CHECK(skel->bss->dropped != 0, "err_dropped", "exp %ld, got %ld\n",
289cb1c9dddSAndrii Nakryiko	      0L, skel->bss->dropped);
290cb1c9dddSAndrii Nakryiko	CHECK(skel->bss->total != 2, "err_total", "exp %ld, got %ld\n",
291cb1c9dddSAndrii Nakryiko	      2L, skel->bss->total);
292cb1c9dddSAndrii Nakryiko	CHECK(skel->bss->discarded != 1, "err_discarded", "exp %ld, got %ld\n",
293cb1c9dddSAndrii Nakryiko	      1L, skel->bss->discarded);
294cb1c9dddSAndrii Nakryiko
295087cba79SKumar Kartikeya Dwivedi	test_ringbuf_lskel__detach(skel);
296cb1c9dddSAndrii Nakryikocleanup:
297cb1c9dddSAndrii Nakryiko	ring_buffer__free(ringbuf);
298087cba79SKumar Kartikeya Dwivedi	test_ringbuf_lskel__destroy(skel);
299cb1c9dddSAndrii Nakryiko}