The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
Loading...
Searching...
No Matches
Typedefs | Functions | Variables
dbuff_tests.c File Reference
#include "acutest_common_init.h"
#include "acutest_helpers.h"
#include <float.h>
#include <freeradius-devel/util/dbuff.h>
#include <sys/mman.h>
#include <unistd.h>
+ Include dependency graph for dbuff_tests.c:

Go to the source code of this file.

Typedefs

typedef void(* fr_dbuff_fd_test_body) (fr_dbuff_t *dbuff, uint8_t const data[])
 

Functions

static void fd_body (fr_dbuff_t *dbuff, uint8_t const data[])
 
static void max_body (fr_dbuff_t *dbuff, uint8_t const data[])
 
static void test_dbuff_advance_extend (void)
 Test fr_dbuff_advance_extend against a talloc-backed (extensible) dbuff.
 
static void test_dbuff_bind_end_abs_extend (void)
 FR_DBUFF_BIND_END_ABS hands the extend function to the producer.
 
static void test_dbuff_child (void)
 Test the child-dbuff macros: FR_DBUFF, FR_DBUFF_ABS, FR_DBUFF_BIND_CURRENT, FR_DBUFF_BIND_CURRENT_ABS, FR_DBUFF_BIND_END_ABS and FR_DBUFF_MAX.
 
static void test_dbuff_const_no_extend (void)
 A const dbuff must never extend.
 
static void test_dbuff_drain (void)
 Draining a buffer without knowing in advance how much is in it.
 
static void test_dbuff_extend (void)
 Test the extension-request API: fr_dbuff_extend, fr_dbuff_extend_lowat, fr_dbuff_is_extendable and fr_dbuff_was_extended.
 
static void test_dbuff_fd (void)
 
static void test_dbuff_fd_max (void)
 
static void test_dbuff_fd_shell (fr_dbuff_fd_test_body body, uint8_t const data[], size_t datasize, uint8_t buff[], size_t buffsize, size_t max)
 
static void test_dbuff_in_memcpy (void)
 Test fr_dbuff_in_memcpy, fr_dbuff_in_memcpy_partial and fr_dbuff_in_bytes_partial.
 
static void test_dbuff_init (void)
 
static void test_dbuff_init_no_parent (void)
 
static void test_dbuff_init_zero_length (void)
 A zero length output buffer accepts nothing, and nothing is written to the buffer.
 
static void test_dbuff_marker_release (void)
 Test fr_dbuff_marker_release, fr_dbuff_marker_release_behind and _ahead.
 
static void test_dbuff_max (void)
 
static void test_dbuff_measure (void)
 Test the measurement / accessor macros against both a dbuff and a marker.
 
static void test_dbuff_memset (void)
 Test fr_dbuff_memset.
 
static void test_dbuff_move (void)
 
static void test_dbuff_net_encode (void)
 Test the various dbuff_net_encode() functions and macros.
 
static void test_dbuff_no_advance (void)
 
static void test_dbuff_out (void)
 Test functions that read from dbuffs.
 
static void test_dbuff_out_int64v (void)
 Test fr_dbuff_out_int64v, which sign-extends based on the most significant bit.
 
static void test_dbuff_producer_consumer (void)
 A producer and a consumer sharing one talloc buffer.
 
static void test_dbuff_producer_consumer_rounds (void)
 A consumer which is drained, refilled, and drained again.
 
static void test_dbuff_set (void)
 Test fr_dbuff_set (by size_t, pointer, marker) and fr_dbuff_set_end.
 
static void test_dbuff_shift (void)
 Test fr_dbuff_shift moves unconsumed content to the front of the buffer.
 
static void test_dbuff_talloc_extend (void)
 Test extensible dbuffs.
 
static void test_dbuff_talloc_extend_multi_level (void)
 
static void test_dbuff_tmp (void)
 Test FR_DBUFF_TMP, the compound-literal dbuff.
 
static void test_dbuff_trim_reset_talloc (void)
 Test fr_dbuff_trim_talloc, fr_dbuff_reset_talloc and fr_dbuff_free_talloc.
 
static void test_dbuff_update (void)
 Test fr_dbuff_update repoints the dbuff and its markers after a buffer move.
 

Variables

 TEST_LIST
 

Typedef Documentation

◆ fr_dbuff_fd_test_body

typedef void(* fr_dbuff_fd_test_body) (fr_dbuff_t *dbuff, uint8_t const data[])

Definition at line 23 of file dbuff_tests.c.

Function Documentation

◆ fd_body()

static void fd_body ( fr_dbuff_t *  dbuff,
uint8_t const  data[] 
)
static

Definition at line 397 of file dbuff_tests.c.

+ Here is the caller graph for this function:

◆ max_body()

static void max_body ( fr_dbuff_t *  dbuff,
uint8_t const  data[] 
)
static

Definition at line 426 of file dbuff_tests.c.

+ Here is the caller graph for this function:

◆ test_dbuff_advance_extend()

static void test_dbuff_advance_extend ( void  )
static

Test fr_dbuff_advance_extend against a talloc-backed (extensible) dbuff.

Definition at line 712 of file dbuff_tests.c.

+ Here is the call graph for this function:

◆ test_dbuff_bind_end_abs_extend()

static void test_dbuff_bind_end_abs_extend ( void  )
static

FR_DBUFF_BIND_END_ABS hands the extend function to the producer.

The bind is what creates the producer/consumer relationship, so the bind is where the rule belongs. Only the producer may extend, because fr_dbuff_update() repairs the dbuff which was extended and that dbuff's ancestors, and never its children. Extending through the consumer would leave the producer addressing the old buffer.

The producer's fields are copied out of the consumer while the consumer is still writable, because the compound literal is a function argument and so is evaluated before the bind runs. These checks pin that ordering, which the whole scheme rests on.

Definition at line 1132 of file dbuff_tests.c.

+ Here is the call graph for this function:

◆ test_dbuff_child()

static void test_dbuff_child ( void  )
static

Test the child-dbuff macros: FR_DBUFF, FR_DBUFF_ABS, FR_DBUFF_BIND_CURRENT, FR_DBUFF_BIND_CURRENT_ABS, FR_DBUFF_BIND_END_ABS and FR_DBUFF_MAX.

These differ only in where the child's 'start' pointer is set (parent 'current' vs parent 'start') and whether writing to the child advances the parent's 'current' pointer, 'end' pointer, or neither.

Definition at line 562 of file dbuff_tests.c.

◆ test_dbuff_const_no_extend()

static void test_dbuff_const_no_extend ( void  )
static

A const dbuff must never extend.

A dbuff extends to make room to write. A const dbuff cannot be written to, so a request to extend one is always a caller asking to read more than the dbuff holds. _fr_dbuff_extend_lowat() answers with what is there, rather than reallocating the buffer.

Definition at line 993 of file dbuff_tests.c.

+ Here is the call graph for this function:

◆ test_dbuff_drain()

static void test_dbuff_drain ( void  )
static

Draining a buffer without knowing in advance how much is in it.

fr_tls_record_to_buff() used to clamp a request to what the record held. Callers now reach for a dbuff primitive instead, and the two differ: fr_dbuff_move() copies what both sides allow and advances both, while fr_dbuff_out_memcpy() advances only the source and reports a shortfall.

Definition at line 1084 of file dbuff_tests.c.

◆ test_dbuff_extend()

static void test_dbuff_extend ( void  )
static

Test the extension-request API: fr_dbuff_extend, fr_dbuff_extend_lowat, fr_dbuff_is_extendable and fr_dbuff_was_extended.

Definition at line 957 of file dbuff_tests.c.

+ Here is the call graph for this function:

◆ test_dbuff_fd()

static void test_dbuff_fd ( void  )
static

Definition at line 416 of file dbuff_tests.c.

+ Here is the call graph for this function:

◆ test_dbuff_fd_max()

static void test_dbuff_fd_max ( void  )
static

Definition at line 441 of file dbuff_tests.c.

+ Here is the call graph for this function:

◆ test_dbuff_fd_shell()

static void test_dbuff_fd_shell ( fr_dbuff_fd_test_body  body,
uint8_t const  data[],
size_t  datasize,
uint8_t  buff[],
size_t  buffsize,
size_t  max 
)
static

Definition at line 379 of file dbuff_tests.c.

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

◆ test_dbuff_in_memcpy()

static void test_dbuff_in_memcpy ( void  )
static

Test fr_dbuff_in_memcpy, fr_dbuff_in_memcpy_partial and fr_dbuff_in_bytes_partial.

Definition at line 753 of file dbuff_tests.c.

◆ test_dbuff_init()

static void test_dbuff_init ( void  )
static

Definition at line 25 of file dbuff_tests.c.

◆ test_dbuff_init_no_parent()

static void test_dbuff_init_no_parent ( void  )
static

Definition at line 86 of file dbuff_tests.c.

◆ test_dbuff_init_zero_length()

static void test_dbuff_init_zero_length ( void  )
static

A zero length output buffer accepts nothing, and nothing is written to the buffer.

The buffer sits against an unwritable page, so a write of even one byte past the end faults rather than landing on whatever follows the buffer.

Definition at line 57 of file dbuff_tests.c.

+ Here is the call graph for this function:

◆ test_dbuff_marker_release()

static void test_dbuff_marker_release ( void  )
static

Test fr_dbuff_marker_release, fr_dbuff_marker_release_behind and _ahead.

Definition at line 811 of file dbuff_tests.c.

+ Here is the call graph for this function:

◆ test_dbuff_max()

static void test_dbuff_max ( void  )
static

Definition at line 96 of file dbuff_tests.c.

◆ test_dbuff_measure()

static void test_dbuff_measure ( void  )
static

Test the measurement / accessor macros against both a dbuff and a marker.

Covers fr_dbuff_len, fr_dbuff_buff, fr_dbuff_end, fr_dbuff_ptr, fr_dbuff_behind and fr_dbuff_ahead, which the existing tests never touch.

Definition at line 635 of file dbuff_tests.c.

+ Here is the call graph for this function:

◆ test_dbuff_memset()

static void test_dbuff_memset ( void  )
static

Test fr_dbuff_memset.

Definition at line 735 of file dbuff_tests.c.

◆ test_dbuff_move()

static void test_dbuff_move ( void  )
static

Definition at line 268 of file dbuff_tests.c.

+ Here is the call graph for this function:

◆ test_dbuff_net_encode()

static void test_dbuff_net_encode ( void  )
static

Test the various dbuff_net_encode() functions and macros.

Note
Passing constants to fr_dbuff_in() as it is written results in warnings about narrowing casts on the constants–but those casts are in the underlying inlined fr_nbo_from*() functions. They have to be there; that's how those functions work. (The tests worked despite the warnings.) Using variables avoids the warnings, at least with the compile options the build system uses by default.

Definition at line 122 of file dbuff_tests.c.

+ Here is the call graph for this function:

◆ test_dbuff_no_advance()

static void test_dbuff_no_advance ( void  )
static

Definition at line 248 of file dbuff_tests.c.

◆ test_dbuff_out()

static void test_dbuff_out ( void  )
static

Test functions that read from dbuffs.

Definition at line 454 of file dbuff_tests.c.

+ Here is the call graph for this function:

◆ test_dbuff_out_int64v()

static void test_dbuff_out_int64v ( void  )
static

Test fr_dbuff_out_int64v, which sign-extends based on the most significant bit.

Definition at line 843 of file dbuff_tests.c.

◆ test_dbuff_producer_consumer()

static void test_dbuff_producer_consumer ( void  )
static

A producer and a consumer sharing one talloc buffer.

fr_tls_bio_dbuff_t in src/lib/tls/bio.c builds its two cursors this way, so that OpenSSL and the caller share one allocation per direction. The consumer is the parent and the producer is the child.

Only the producer may extend. fr_dbuff_update() repairs the dbuff which was extended and that dbuff's ancestors, and never its children, so extending through the consumer would leave the producer addressing the old buffer. Marking the consumer const is what stops that, which is what this test pins.

Definition at line 1036 of file dbuff_tests.c.

+ Here is the call graph for this function:

◆ test_dbuff_producer_consumer_rounds()

static void test_dbuff_producer_consumer_rounds ( void  )
static

A consumer which is drained, refilled, and drained again.

fr_tls_bio_dbuff_t is used this way for a whole TLS handshake, so the cursors have to survive more than one round. A read leaves the consumer empty without any reset, which is what lets a caller loop on fr_dbuff_remaining() rather than tracking a fill and drain phase.

Definition at line 1193 of file dbuff_tests.c.

+ Here is the call graph for this function:

◆ test_dbuff_set()

static void test_dbuff_set ( void  )
static

Test fr_dbuff_set (by size_t, pointer, marker) and fr_dbuff_set_end.

The backing array is deliberately larger than the dbuff window so that we can form a pointer past the dbuff 'end' without forming a pointer outside the real allocation (which would be undefined behaviour).

Definition at line 677 of file dbuff_tests.c.

+ Here is the call graph for this function:

◆ test_dbuff_shift()

static void test_dbuff_shift ( void  )
static

Test fr_dbuff_shift moves unconsumed content to the front of the buffer.

Definition at line 871 of file dbuff_tests.c.

+ Here is the call graph for this function:

◆ test_dbuff_talloc_extend()

static void test_dbuff_talloc_extend ( void  )
static

Test extensible dbuffs.

Definition at line 313 of file dbuff_tests.c.

+ Here is the call graph for this function:

◆ test_dbuff_talloc_extend_multi_level()

static void test_dbuff_talloc_extend_multi_level ( void  )
static

Definition at line 347 of file dbuff_tests.c.

+ Here is the call graph for this function:

◆ test_dbuff_tmp()

static void test_dbuff_tmp ( void  )
static

Test FR_DBUFF_TMP, the compound-literal dbuff.

Definition at line 940 of file dbuff_tests.c.

◆ test_dbuff_trim_reset_talloc()

static void test_dbuff_trim_reset_talloc ( void  )
static

Test fr_dbuff_trim_talloc, fr_dbuff_reset_talloc and fr_dbuff_free_talloc.

Definition at line 911 of file dbuff_tests.c.

+ Here is the call graph for this function:

◆ test_dbuff_update()

static void test_dbuff_update ( void  )
static

Test fr_dbuff_update repoints the dbuff and its markers after a buffer move.

Definition at line 888 of file dbuff_tests.c.

+ Here is the call graph for this function:

Variable Documentation

◆ TEST_LIST

TEST_LIST

Definition at line 1236 of file dbuff_tests.c.