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

Tests for the memory bio. 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 dependency graph for bio_mem_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...
 
struct  test_verify_ctx_t
 Framing for the tests: the first byte of a packet is its total length. More...
 

Macros

#define _BIO_PRIVATE   1
 

Functions

static int cb_noop (fr_bio_t *bio)
 
static void cb_noop_void (fr_bio_t *bio)
 
static int cb_shutdown (fr_bio_t *bio)
 
static fr_bio_t * stub_alloc (TALLOC_CTX *ctx)
 
static ssize_t stub_read (fr_bio_t *bio, UNUSED void *packet_ctx, void *buffer, size_t size)
 Return "abcde" once, and fail every read after that.
 
static ssize_t stub_write_all (UNUSED fr_bio_t *bio, UNUSED void *packet_ctx, UNUSED void const *buffer, size_t size)
 Accept 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)
 Accept one byte of each write, so the memory bio buffers the rest.
 
static void test_buffered_read_drains (void)
 Without a verify function the bio is a plain buffer, and hands back what it has.
 
static void test_fatal_read_drains (void)
 After a fatal read error in the next bio, the application still gets the buffered data.
 
static fr_bio_t * test_mem_alloc (TALLOC_CTX *ctx, fr_bio_t **source_p, test_verify_ctx_t *tctx)
 A memory bio in front of a pipe, which stands in for the network.
 
static void test_recoverable_flush_passes_up (void)
 The memory bio passes a recoverable flush error up to the application, and keeps the buffered data.
 
static void test_recoverable_read_datagram (void)
 With the datagram verify reader, the memory bio passes a recoverable read error up to the application.
 
static void test_recoverable_write_passes_up (void)
 The memory bio passes a recoverable write error up to the application, and keeps working.
 
static ssize_t test_source_write (fr_bio_t *source, char const *data, size_t size)
 Put bytes where the memory bio's reads will find them.
 
static fr_bio_verify_action_t test_verify (UNUSED fr_bio_t *bio, void *verify_ctx, UNUSED void *packet_ctx, const void *buffer, size_t *size)
 
static void test_verify_buffer_too_small (void)
 A caller buffer smaller than the packet is an error, and loses nothing.
 
static void test_verify_error_close (void)
 A verify function which says "close" shuts the chain down.
 
static void test_verify_one_packet (void)
 A complete packet is returned, and only one packet at a time.
 
static void test_verify_partial_packet (void)
 A packet split across two reads is reassembled.
 
static void test_verify_pipelined (void)
 Pipelined packets: a buffer holding more than one packet must still return the first.
 

Variables

static int shutdown_count
 
static fr_bio_cb_funcs_t stub_cb
 
static fr_bio_cb_funcs_t test_cb
 
 TEST_LIST
 

Detailed Description

Tests for the memory bio.

Definition in file bio_mem_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

◆ test_verify_ctx_t

struct test_verify_ctx_t

Framing for the tests: the first byte of a packet is its total length.

Definition at line 45 of file bio_mem_tests.c.

Data Fields
bool fail return ERROR_CLOSE for the next packet

Macro Definition Documentation

◆ _BIO_PRIVATE

#define _BIO_PRIVATE   1

Definition at line 26 of file bio_mem_tests.c.

Function Documentation

◆ cb_noop()

static int cb_noop ( fr_bio_t *  bio)
static

Definition at line 32 of file bio_mem_tests.c.

◆ cb_noop_void()

static void cb_noop_void ( fr_bio_t *  bio)
static

Definition at line 33 of file bio_mem_tests.c.

◆ cb_shutdown()

static int cb_shutdown ( fr_bio_t *  bio)
static

Definition at line 296 of file bio_mem_tests.c.

◆ stub_alloc()

static fr_bio_t * stub_alloc ( TALLOC_CTX *  ctx)
static

Definition at line 349 of file bio_mem_tests.c.

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

◆ stub_read()

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

Return "abcde" once, and fail every read after that.

Definition at line 309 of file bio_mem_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

Accept every write in full.

Definition at line 344 of file bio_mem_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 325 of file bio_mem_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

Accept one byte of each write, so the memory bio buffers the rest.

Definition at line 337 of file bio_mem_tests.c.

+ Here is the caller graph for this function:

◆ test_buffered_read_drains()

static void test_buffered_read_drains ( void  )
static

Without a verify function the bio is a plain buffer, and hands back what it has.

mem.md finding 9. A zero from the next bio means no more is coming, and the bytes already buffered still belong to the application.

Definition at line 251 of file bio_mem_tests.c.

+ Here is the call graph for this function:

◆ test_fatal_read_drains()

static void test_fatal_read_drains ( void  )
static

After a fatal read error in the next bio, the application still gets the buffered data.

The stub decides that the error is fatal, and calls fr_bio_shutdown(). The memory bio passes the error up, and fr_bio_mem_eof() keeps the buffered data for the application.

Definition at line 436 of file bio_mem_tests.c.

+ Here is the call graph for this function:

◆ test_mem_alloc()

static fr_bio_t * test_mem_alloc ( TALLOC_CTX *  ctx,
fr_bio_t **  source_p,
test_verify_ctx_t *  tctx 
)
static

A memory bio in front of a pipe, which stands in for the network.

Writing to the pipe puts bytes where the memory bio's reads will find them.

Definition at line 85 of file bio_mem_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 memory bio passes a recoverable flush error up to the application, and keeps the buffered data.

Definition at line 397 of file bio_mem_tests.c.

+ Here is the call graph for this function:

◆ test_recoverable_read_datagram()

static void test_recoverable_read_datagram ( void  )
static

With the datagram verify reader, the memory bio passes a recoverable read error up to the application.

Definition at line 483 of file bio_mem_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 memory bio passes a recoverable write error up to the application, and keeps working.

Definition at line 366 of file bio_mem_tests.c.

+ Here is the call graph for this function:

◆ test_source_write()

static ssize_t test_source_write ( fr_bio_t *  source,
char const *  data,
size_t  size 
)
static

Put bytes where the memory bio's reads will find them.

fr_bio_write() requires the head of a chain, and the source is the tail, so this calls the source's own write routine.

Definition at line 76 of file bio_mem_tests.c.

+ Here is the caller graph for this function:

◆ test_verify()

static fr_bio_verify_action_t test_verify ( UNUSED fr_bio_t *  bio,
void *  verify_ctx,
UNUSED void *  packet_ctx,
const void *  buffer,
size_t *  size 
)
static

Definition at line 49 of file bio_mem_tests.c.

+ Here is the caller graph for this function:

◆ test_verify_buffer_too_small()

static void test_verify_buffer_too_small ( void  )
static

A caller buffer smaller than the packet is an error, and loses nothing.

Definition at line 194 of file bio_mem_tests.c.

+ Here is the call graph for this function:

◆ test_verify_error_close()

static void test_verify_error_close ( void  )
static

A verify function which says "close" shuts the chain down.

Definition at line 222 of file bio_mem_tests.c.

+ Here is the call graph for this function:

◆ test_verify_one_packet()

static void test_verify_one_packet ( void  )
static

A complete packet is returned, and only one packet at a time.

Definition at line 103 of file bio_mem_tests.c.

+ Here is the call graph for this function:

◆ test_verify_partial_packet()

static void test_verify_partial_packet ( void  )
static

A packet split across two reads is reassembled.

Definition at line 131 of file bio_mem_tests.c.

+ Here is the call graph for this function:

◆ test_verify_pipelined()

static void test_verify_pipelined ( void  )
static

Pipelined packets: a buffer holding more than one packet must still return the first.

mem.md finding 1. The second path used to compare the whole buffer against the caller's size, and return BUFFER_TOO_SMALL although a complete packet was sitting at the front.

Definition at line 162 of file bio_mem_tests.c.

+ Here is the call graph for this function:

Variable Documentation

◆ shutdown_count

int shutdown_count
static

Definition at line 294 of file bio_mem_tests.c.

◆ stub_cb

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

Definition at line 298 of file bio_mem_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_noop_void,
}

Definition at line 35 of file bio_mem_tests.c.

◆ TEST_LIST

TEST_LIST
Initial value:
= {
{ "verify_one_packet", test_verify_one_packet },
{ "verify_partial_packet", test_verify_partial_packet },
{ "verify_pipelined", test_verify_pipelined },
{ "verify_buffer_too_small", test_verify_buffer_too_small },
{ "verify_error_close", test_verify_error_close },
{ "buffered_read_drains", test_buffered_read_drains },
{ "recoverable_write_passes_up", test_recoverable_write_passes_up },
{ "recoverable_flush_passes_up", test_recoverable_flush_passes_up },
{ "fatal_read_drains", test_fatal_read_drains },
{ "recoverable_read_datagram", test_recoverable_read_datagram },
}
#define TEST_TERMINATOR
Definition acutest.h:77
static void test_verify_one_packet(void)
A complete packet is returned, and only one packet at a time.
static void test_recoverable_flush_passes_up(void)
The memory bio passes a recoverable flush error up to the application, and keeps the buffered data.
static void test_recoverable_read_datagram(void)
With the datagram verify reader, the memory bio passes a recoverable read error up to the application...
static void test_recoverable_write_passes_up(void)
The memory bio passes a recoverable write error up to the application, and keeps working.
static void test_verify_error_close(void)
A verify function which says "close" shuts the chain down.
static void test_buffered_read_drains(void)
Without a verify function the bio is a plain buffer, and hands back what it has.
static void test_fatal_read_drains(void)
After a fatal read error in the next bio, the application still gets the buffered data.
static void test_verify_pipelined(void)
Pipelined packets: a buffer holding more than one packet must still return the first.
static void test_verify_buffer_too_small(void)
A caller buffer smaller than the packet is an error, and loses nothing.
static void test_verify_partial_packet(void)
A packet split across two reads is reassembled.

Definition at line 513 of file bio_mem_tests.c.