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/null.h>
30#include <freeradius-devel/bio/pipe.h>
31#include <freeradius-devel/bio/queue.h>
100 stub = talloc_zero(ctx,
stub_t);
101 if (!stub)
return NULL;
131 if (!pipe)
goto done;
135 if (!queue)
goto done;
144 TEST_CASE(
"the saved packet is cancelled");
147 TEST_CASE(
"the application is told about the shutdown");
168 if (!pipe)
goto done;
172 if (!queue)
goto done;
188 TEST_CASE(
"the saved packet is cancelled");
191 TEST_CASE(
"the application is told about the shutdown");
207 if (!stub)
return NULL;
210 if (!queue)
return NULL;
232 if (!stub)
goto done;
236 if (!queue)
goto done;
240 TEST_CASE(
"the write gets the error from the stub");
243 TEST_CASE(
"the queue bio does not shut the chain down");
246 TEST_CASE(
"the next write reaches the stub again");
263 if (!queue)
goto done;
265 TEST_CASE(
"the flush gets the error from the stub");
269 TEST_CASE(
"the saved packet is not cancelled, and the chain is not shut down");
273 TEST_CASE(
"a later flush sends the saved packet");
291 if (!queue)
goto done;
293 TEST_CASE(
"the flush gets the error from the stub");
294 ((
stub_t *) stub)->fatal =
true;
298 TEST_CASE(
"fr_bio_queue_shutdown() cancels the saved packet, and the application is told");
302 TEST_CASE(
"later writes report SHUTDOWN");
static int const char char buffer[256]
#define TEST_CHECK_RET(_got, _exp)
fr_bio_write_t _CONST write
write to the underlying 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.
fr_bio_io_t read_resume
"unblocked" is too similar to "blocked"
fr_bio_t * fr_bio_queue_alloc(TALLOC_CTX *ctx, size_t max_saved, fr_bio_queue_saved_t saved, fr_bio_queue_callback_t sent, fr_bio_queue_callback_t cancel, fr_bio_t *next)
Allocate a packet-based bio.
static int packet_ctx
the tests pass only the address of packet_ctx
#define FR_BIO_COMMON
Common elements at the start of each private fr_bio_t.
static void test_shutdown_keeps_app_callback(void)
The application installs its callbacks on a queue bio at the head of the chain.
static void test_recoverable_flush_passes_up(void)
The queue bio passes a recoverable flush error up to the application, and keeps the saved packet.
static void cb_eof(fr_bio_t *bio)
static fr_bio_cb_funcs_t test_cb
static ssize_t stub_write_one(UNUSED fr_bio_t *bio, UNUSED void *packet_ctx, UNUSED void const *buffer, UNUSED size_t size)
A transport which accepts one byte of each write, so the queue bio saves the rest of the packet.
static ssize_t stub_write_all(UNUSED fr_bio_t *bio, UNUSED void *packet_ctx, UNUSED void const *buffer, size_t size)
A transport which accepts every write in full.
static uint8_t fill[1000]
static void test_recoverable_write_passes_up(void)
The queue bio passes a recoverable write error up to the application, and keeps working.
bool fatal
shut the chain down before failing
static void queue_cancel(fr_bio_t *bio, void *packet_ctx, void const *buffer, size_t size)
static bool queue_fill(fr_bio_t *head)
Leave one packet partly written in the queue.
static int cb_shutdown(fr_bio_t *bio)
static void test_fatal_flush_from_next(void)
When the next bio shuts the chain down on a fatal flush error, fr_bio_queue_shutdown() cancels the sa...
static fr_bio_t * test_queue_saved_alloc(TALLOC_CTX *ctx, fr_bio_t **stub_p)
Build a queue in front of a stub, with one packet saved after a partial write.
static void test_shutdown_not_head(void)
A queue bio in the middle of a chain is not the head, so only the private slot reaches it.
static fr_bio_t * stub_alloc(TALLOC_CTX *ctx)
static ssize_t stub_write_fail(fr_bio_t *bio, UNUSED void *packet_ctx, UNUSED void const *buffer, UNUSED size_t size)
static int shutdown_count
static uint8_t overflow[100]
static int cb_noop(fr_bio_t *bio)
A stub transport which fails recoverably or fatally, as each test chooses.
void fr_bio_cb_set(fr_bio_t *bio, fr_bio_cb_funcs_t const *cb)
int fr_bio_shutdown(fr_bio_t *bio)
Shut down a set of BIOs.
fr_bio_t * fr_bio_mem_alloc(TALLOC_CTX *ctx, size_t read_size, size_t write_size, fr_bio_t *next)
Allocate a memory buffer bio.
ssize_t fr_bio_null_read(UNUSED fr_bio_t *bio, UNUSED void *packet_ctx, UNUSED void *buffer, UNUSED size_t size)
Always return 0 on read.
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.
#define fr_strerror_const(_msg)