/* verify getting this data directly via the ring object yields the same * results
*/
avail_data = ring__avail_data_size(ring);
ASSERT_EQ(avail_data, 3 * rec_sz, "ring_avail_size");
ring_size = ring__size(ring);
ASSERT_EQ(ring_size, page_size, "ring_ring_size");
cons_pos = ring__consumer_pos(ring);
ASSERT_EQ(cons_pos, 0, "ring_cons_pos");
prod_pos = ring__producer_pos(ring);
ASSERT_EQ(prod_pos, 3 * rec_sz, "ring_prod_pos");
/* poll for samples */
err = ring_buffer__poll(ringbuf, -1);
/* -EDONE is used as an indicator that we are done */ if (CHECK(err != -EDONE, "err_done", "done err: %d\n", err)) goto cleanup;
cnt = atomic_xchg(&sample_cnt, 0);
CHECK(cnt != 2, "cnt", "exp %d samples, got %d\n", 2, cnt);
/* we expect extra polling to return nothing */
err = ring_buffer__poll(ringbuf, 0); if (CHECK(err != 0, "extra_samples", "poll result: %d\n", err)) goto cleanup;
cnt = atomic_xchg(&sample_cnt, 0);
CHECK(cnt != 0, "cnt", "exp %d samples, got %d\n", 0, cnt);
/* start poll in background w/ long timeout */
err = pthread_create(&thread, NULL, poll_thread, (void *)(long)10000); if (CHECK(err, "bg_poll", "pthread_create failed: %d\n", err)) goto cleanup;
/* turn off notifications now */
skel->bss->flags = BPF_RB_NO_WAKEUP;
/* give background thread a bit of a time */
usleep(50000);
trigger_samples(); /* sleeping arbitrarily is bad, but no better way to know that * epoll_wait() **DID NOT** unblock in background thread
*/
usleep(50000); /* background poll should still be blocked */
err = pthread_tryjoin_np(thread, (void **)&bg_ret); if (CHECK(err != EBUSY, "try_join", "err %d\n", err)) goto cleanup;
skel->bss->value = 333;
syscall(__NR_getpgid); /* now force notifications */
skel->bss->flags = BPF_RB_FORCE_WAKEUP;
skel->bss->value = 777;
syscall(__NR_getpgid);
/* now we should get a pending notification */
usleep(50000);
err = pthread_tryjoin_np(thread, (void **)&bg_ret); if (CHECK(err, "join_bg", "err %d\n", err)) 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);
/* also consume using ring__consume to make sure it works the same */
err = ring__consume(ring);
ASSERT_GE(err, 0, "ring_consume");
/* * Test ring_buffer__consume_n() by producing N_TOT_SAMPLES samples in the ring * buffer, via getpid(), and consuming them in chunks of N_SAMPLES.
*/ #define N_TOT_SAMPLES 32 #define N_SAMPLES 4
/* Sample value to verify the callback validity */ #define SAMPLE_VALUE 42L
err = test_ringbuf_n_lskel__attach(skel_n); if (!ASSERT_OK(err, "test_ringbuf_n_lskel__attach")) goto cleanup_ringbuf;
/* Produce N_TOT_SAMPLES samples in the ring buffer by calling getpid() */
skel_n->bss->value = SAMPLE_VALUE; for (i = 0; i < N_TOT_SAMPLES; i++)
syscall(__NR_getpgid);
/* Consume all samples from the ring buffer in batches of N_SAMPLES */ for (i = 0; i < N_TOT_SAMPLES; i += err) {
err = ring_buffer__consume_n(ringbuf, N_SAMPLES); if (!ASSERT_EQ(err, N_SAMPLES, "rb_consume")) goto cleanup_ringbuf;
}
void test_ringbuf(void)
{ if (test__start_subtest("ringbuf"))
ringbuf_subtest(); if (test__start_subtest("ringbuf_n"))
ringbuf_n_subtest(); if (test__start_subtest("ringbuf_map_key"))
ringbuf_map_key_subtest(); if (test__start_subtest("ringbuf_write"))
ringbuf_write_subtest();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.