The FreeRADIUS server $Id: f3670dba8951ca10eb4948feb3dc3db9423a334f $
Loading...
Searching...
No Matches
Data Structures | Macros | Functions | Variables
bio_queue_tests.c File Reference

Tests for the queue bio's shutdown and error handling. More...

#include <freeradius-devel/util/test/acutest_common_init.h>
#include <freeradius-devel/util/test/acutest_helpers.h>
#include <freeradius-devel/bio/bio_priv.h>
#include <freeradius-devel/bio/mem.h>
#include <freeradius-devel/bio/null.h>
#include <freeradius-devel/bio/pipe.h>
#include <freeradius-devel/bio/queue.h>
+ Include dependency graph for bio_queue_tests.c:

Go to the source code of this file.

Data Structures

struct  stub_t
 A stub transport which fails recoverably or fatally, as each test chooses. More...
 

Macros

#define _BIO_PRIVATE   1
 

Functions

static void cb_eof (fr_bio_t *bio)
 
static int cb_noop (fr_bio_t *bio)
 
static int cb_shutdown (fr_bio_t *bio)
 
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 fr_bio_t * stub_alloc (TALLOC_CTX *ctx)
 
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 ssize_t stub_write_fail (fr_bio_t *bio, UNUSED void *packet_ctx, UNUSED void const *buffer, UNUSED size_t size)
 
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 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 saved packet.
 
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_recoverable_flush_passes_up (void)
 The queue bio passes a recoverable flush error up to the application, and keeps the saved packet.
 
static void test_recoverable_write_passes_up (void)
 The queue bio passes a recoverable write error up to the application, and keeps working.
 
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_shutdown_not_head (void)
 A queue bio in the middle of a chain is not the head, so only the private slot reaches it.
 

Variables

static int cancel_count
 
static uint8_t fill [1000]
 
static uint8_t overflow [100]
 
static int shutdown_count
 
static fr_bio_cb_funcs_t test_cb
 
 TEST_LIST
 

Detailed Description

Tests for the queue bio's shutdown and error handling.

Definition in file bio_queue_tests.c.


Data Structure Documentation

◆ stub_t

struct stub_t

A stub transport which fails recoverably or fatally, as each test chooses.

On a recoverable failure, the stub returns an error and changes nothing else. On a fatal failure, the stub first shuts the chain down, as the fd bio does. Only the failing bio decides whether a failure is recoverable or fatal.

Definition at line 288 of file bio_mem_tests.c.

Data Fields
bool data_sent the first read has returned "abcde"
bool fatal shut the chain down before failing
FR_BIO_COMMON

Macro Definition Documentation

◆ _BIO_PRIVATE

#define _BIO_PRIVATE   1

Definition at line 26 of file bio_queue_tests.c.

Function Documentation

◆ cb_eof()

static void cb_eof ( fr_bio_t *  bio)
static

Definition at line 36 of file bio_queue_tests.c.

◆ cb_noop()

static int cb_noop ( fr_bio_t *  bio)
static

Definition at line 38 of file bio_queue_tests.c.

◆ cb_shutdown()

static int cb_shutdown ( fr_bio_t *  bio)
static

Definition at line 37 of file bio_queue_tests.c.

◆ queue_cancel()

static void queue_cancel ( fr_bio_t *  bio,
void *  packet_ctx,
void const *  buffer,
size_t  size 
)
static

Definition at line 40 of file bio_queue_tests.c.

+ Here is the caller graph for this function:

◆ queue_fill()

static bool queue_fill ( fr_bio_t *  head)
static

Leave one packet partly written in the queue.

Definition at line 111 of file bio_queue_tests.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ stub_alloc()

static fr_bio_t * stub_alloc ( TALLOC_CTX *  ctx)
static

Definition at line 96 of file bio_queue_tests.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ stub_write_all()

static ssize_t stub_write_all ( UNUSED fr_bio_t *  bio,
UNUSED void *  packet_ctx,
UNUSED void const *  buffer,
size_t  size 
)
static

A transport which accepts every write in full.

Definition at line 91 of file bio_queue_tests.c.

+ Here is the caller graph for this function:

◆ stub_write_fail()

static ssize_t stub_write_fail ( fr_bio_t *  bio,
UNUSED void *  packet_ctx,
UNUSED void const *  buffer,
UNUSED size_t  size 
)
static

Definition at line 72 of file bio_queue_tests.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ stub_write_one()

static ssize_t stub_write_one ( UNUSED fr_bio_t *  bio,
UNUSED void *  packet_ctx,
UNUSED void const *  buffer,
UNUSED size_t  size 
)
static

A transport which accepts one byte of each write, so the queue bio saves the rest of the packet.

Definition at line 84 of file bio_queue_tests.c.

+ Here is the caller graph for this function:

◆ test_fatal_flush_from_next()

static void test_fatal_flush_from_next ( void  )
static

When the next bio shuts the chain down on a fatal flush error, fr_bio_queue_shutdown() cancels the saved packet.

Definition at line 284 of file bio_queue_tests.c.

+ Here is the call graph for this function:

◆ test_queue_saved_alloc()

static fr_bio_t * test_queue_saved_alloc ( TALLOC_CTX *  ctx,
fr_bio_t **  stub_p 
)
static

Build a queue in front of a stub, with one packet saved after a partial write.

Definition at line 200 of file bio_queue_tests.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ test_recoverable_flush_passes_up()

static void test_recoverable_flush_passes_up ( void  )
static

The queue bio passes a recoverable flush error up to the application, and keeps the saved packet.

Definition at line 256 of file bio_queue_tests.c.

+ Here is the call graph for this function:

◆ test_recoverable_write_passes_up()

static void test_recoverable_write_passes_up ( void  )
static

The queue bio passes a recoverable write error up to the application, and keeps working.

Definition at line 223 of file bio_queue_tests.c.

+ Here is the call graph for this function:

◆ test_shutdown_keeps_app_callback()

static void test_shutdown_keeps_app_callback ( void  )
static

The application installs its callbacks on a queue bio at the head of the chain.

The queue's own shutdown routine must survive that, and still cancel the saved packet.

Definition at line 122 of file bio_queue_tests.c.

+ Here is the call graph for this function:

◆ test_shutdown_not_head()

static void test_shutdown_not_head ( void  )
static

A queue bio in the middle of a chain is not the head, so only the private slot reaches it.

Definition at line 159 of file bio_queue_tests.c.

+ Here is the call graph for this function:

Variable Documentation

◆ cancel_count

int cancel_count
static

Definition at line 33 of file bio_queue_tests.c.

◆ fill

uint8_t fill[1000]
static

Definition at line 58 of file bio_queue_tests.c.

◆ overflow

uint8_t overflow[100]
static

Definition at line 59 of file bio_queue_tests.c.

◆ shutdown_count

int shutdown_count
static

Definition at line 34 of file bio_queue_tests.c.

◆ test_cb

fr_bio_cb_funcs_t test_cb
static
Initial value:
= {
.read_resume = cb_noop,
.write_resume = cb_noop,
.read_blocked = cb_noop,
.write_blocked = cb_noop,
.eof = cb_eof,
.shutdown = cb_shutdown,
}
static void cb_eof(fr_bio_t *bio)
static int cb_shutdown(fr_bio_t *bio)
static int cb_noop(fr_bio_t *bio)

Definition at line 46 of file bio_queue_tests.c.

◆ TEST_LIST

TEST_LIST
Initial value:
= {
{ "shutdown_keeps_app_callback", test_shutdown_keeps_app_callback },
{ "shutdown_not_head", test_shutdown_not_head },
{ "recoverable_write_passes_up", test_recoverable_write_passes_up },
{ "recoverable_flush_passes_up", test_recoverable_flush_passes_up },
{ "fatal_flush_from_next", test_fatal_flush_from_next },
}
#define TEST_TERMINATOR
Definition acutest.h:77
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 test_recoverable_write_passes_up(void)
The queue bio passes a recoverable write error up to the application, and keeps working.
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 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.

Definition at line 309 of file bio_queue_tests.c.