23#include <freeradius-devel/util/test/acutest_common_init.h>
24#include <freeradius-devel/util/test/acutest_helpers.h>
27#include <freeradius-devel/bio/bio_priv.h>
28#include <freeradius-devel/bio/mem.h>
29#include <freeradius-devel/bio/pipe.h>
59 if (!
head)
return NULL;
62 if (!sink)
return NULL;
66 if (sink_p) *sink_p = sink;
79 TEST_CASE(
"the head of the chain is the first bio");
83 TEST_CASE(
"next and prev are each other's inverse");
105 TEST_CASE(
"shutdown of an empty chain completes");
109 TEST_CASE(
"reads and writes report SHUTDOWN afterwards");
113 TEST_CASE(
"a second shutdown is a no-op");
136 TEST_CASE(
"the teardown waits while a bio still holds data");
141 TEST_CASE(
"writes stop at once even though reads do not");
144 TEST_CASE(
"the application still gets the data which had arrived");
147 if (slen == 11)
TEST_CHECK(memcmp(buf,
"hello world", 11) == 0);
149 TEST_CASE(
"draining the last byte completes the shutdown");
153 TEST_CASE(
"the chain reports SHUTDOWN once it is torn down");
174 TEST_CASE(
"discard tears the chain down immediately");
178 TEST_CASE(
"the buffered data is not handed over");
199 TEST_CASE(
"the teardown has not run yet");
202 TEST_CASE(
"freeing the chain finishes it");
212 TEST_CASE(
"every error code has a message");
223 TEST_MSG(
"summary.md records this as missing");
#define TEST_CHECK_RET(_got, _exp)
static fr_bio_t * fr_bio_prev(fr_bio_t *bio)
static ssize_t fr_bio_write(fr_bio_t *bio, void *packet_ctx, void const *buffer, size_t size)
Write raw data to a bio.
static fr_bio_t * fr_bio_next(fr_bio_t *bio)
static fr_bio_t * fr_bio_head(fr_bio_t *bio)
static ssize_t fr_bio_read(fr_bio_t *bio, void *packet_ctx, void *buffer, size_t size)
Read raw data from a bio.
fr_bio_io_t read_resume
"unblocked" is too similar to "blocked"
static void test_strerror(void)
static void cb_eof(fr_bio_t *bio)
static void test_chain(void)
static fr_bio_t * test_chain_alloc(TALLOC_CTX *ctx, fr_bio_t **sink_p)
A pipe in front of a sink, which is the smallest chain we can build without a socket.
static fr_bio_cb_funcs_t test_cb
static void test_shutdown_drains_reads(void)
A bio which still holds data defers the teardown until the application has drained it.
static void test_shutdown_immediate(void)
With nothing buffered, a shutdown tears the chain down at once.
static void test_shutdown_discard(void)
fr_bio_shutdown_discard() does not wait, and throws the buffered data away.
static int cb_shutdown(fr_bio_t *bio)
static int shutdown_count
static void test_shutdown_free_completes(void)
A free completes a shutdown which is still waiting for a drain.
static int cb_noop(fr_bio_t *bio)
static void fr_bio_chain(fr_bio_t *first, fr_bio_t *second)
Chain one bio after another.
char const * fr_bio_strerror(ssize_t error)
int fr_bio_shutdown_discard(fr_bio_t *bio)
Shut down the chain now, discarding anything which is still buffered.
int fr_bio_shutdown(fr_bio_t *bio)
Shut down a set of BIOs.
fr_bio_t * fr_bio_mem_sink_alloc(TALLOC_CTX *ctx, size_t read_size)
Allocate a memory buffer which sinks data from a bio system into the callers application.
fr_bio_t * fr_bio_pipe_alloc(TALLOC_CTX *ctx, fr_bio_cb_funcs_t *cb, size_t buffer_size)
Allocate a thread-safe pipe which can be used for both reads and writes.
static TALLOC_CTX * talloc_init_const(char const *name)
Allocate a top level chunk with a constant name.