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

Tests for the dedup bio expiring entries after a reply. 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/util/rb.h>
#include <freeradius-devel/bio/dedup.h>
+ Include dependency graph for bio_dedup_tests.c:

Go to the source code of this file.

Macros

#define _BIO_PRIVATE   1
 

Functions

static fr_bio_dedup_entry_t * dedup_get_item (UNUSED fr_bio_t *bio, UNUSED void *pctx)
 
static bool dedup_receive (UNUSED fr_bio_t *bio, fr_bio_dedup_entry_t *dedup_ctx, UNUSED void *pctx)
 
static void dedup_release (UNUSED fr_bio_t *bio, UNUSED fr_bio_dedup_entry_t *dedup_ctx, fr_bio_dedup_release_reason_t reason)
 
static fr_bio_t * stub_alloc (TALLOC_CTX *ctx)
 
static ssize_t stub_read (UNUSED fr_bio_t *bio, UNUSED void *pctx, void *buffer, size_t size)
 The stub transport returns a copy of request on every read, and reports every write as complete.
 
static ssize_t stub_write_all (UNUSED fr_bio_t *bio, UNUSED void *pctx, void const *buffer, size_t size)
 
static ssize_t stub_write_block (UNUSED fr_bio_t *bio, UNUSED void *pctx, UNUSED void const *buffer, UNUSED size_t size)
 A stub transport write function which always returns IO_WOULD_BLOCK.
 
static ssize_t stub_write_one (UNUSED fr_bio_t *bio, UNUSED void *pctx, void const *buffer, UNUSED size_t size)
 A stub transport write function which accepts one byte of each write.
 
static fr_bio_t * test_dedup_alloc (TALLOC_CTX *ctx, fr_bio_dedup_config_t *cfg)
 Allocate a dedup bio with two entries and a one-second lifetime, in front of the stub transport.
 
static void test_entries_are_reused (void)
 The expiry timer returns each expired entry to the free list, so the dedup bio reads more requests than the dedup bio has entries.
 
static void test_equal_expiry (void)
 Two entries with the same expiry time both expire.
 
static bool test_pending_reply (fr_bio_t *dedup, fr_bio_t *stub, uint8_t *buffer, size_t size)
 Read a request, and respond while the stub transport is blocked, so that the reply goes on the pending list.
 
static bool test_read_request (fr_bio_t *dedup, uint8_t *buffer, size_t size)
 Read one request through the dedup bio, and attach reply to the dedup entry of the request.
 
static void test_respond_expires (void)
 The dedup entry for a reply sent with fr_bio_dedup_respond() expires once the lifetime is over.
 
static void test_resume_partial (void)
 When the stub transport writes only part of a pending reply, the next resume writes the rest.
 
static void test_resume_sends_pending (void)
 write_resume sends a pending reply, and the dedup entry then expires once the lifetime is over.
 
static void test_resume_still_blocked (void)
 write_resume keeps the pending reply when the stub transport is still blocked.
 
static void test_run_timers (fr_bio_dedup_config_t *cfg)
 Run every timer which is due within the next five seconds.
 
static void test_write_expires (void)
 The dedup entry for a reply sent with fr_bio_write() expires once the lifetime is over.
 
static int test_write_resume (fr_bio_t *dedup)
 Call the dedup bio's write_resume callback, as fr_bio_packet_write_resume() does.
 

Variables

static int expired_count
 
static int packet_ctx
 the tests pass only the address of packet_ctx
 
static uint8_t reply [4] = { 5, 6, 7, 8 }
 
static uint8_t request [4] = { 1, 2, 3, 4 }
 
static fr_bio_dedup_entry_t * saved_item
 
static size_t stub_bytes
 bytes of reply data which the stub transport has accepted
 
 TEST_LIST
 

Detailed Description

Tests for the dedup bio expiring entries after a reply.

Definition in file bio_dedup_tests.c.

Macro Definition Documentation

◆ _BIO_PRIVATE

#define _BIO_PRIVATE   1

Definition at line 27 of file bio_dedup_tests.c.

Function Documentation

◆ dedup_get_item()

static fr_bio_dedup_entry_t * dedup_get_item ( UNUSED fr_bio_t *  bio,
UNUSED void *  pctx 
)
static

Definition at line 51 of file bio_dedup_tests.c.

+ Here is the caller graph for this function:

◆ dedup_receive()

static bool dedup_receive ( UNUSED fr_bio_t *  bio,
fr_bio_dedup_entry_t *  dedup_ctx,
UNUSED void *  pctx 
)
static

Definition at line 39 of file bio_dedup_tests.c.

+ Here is the caller graph for this function:

◆ dedup_release()

static void dedup_release ( UNUSED fr_bio_t *  bio,
UNUSED fr_bio_dedup_entry_t *  dedup_ctx,
fr_bio_dedup_release_reason_t  reason 
)
static

Definition at line 45 of file bio_dedup_tests.c.

+ Here is the caller graph for this function:

◆ stub_alloc()

static fr_bio_t * stub_alloc ( TALLOC_CTX *  ctx)
static

Definition at line 93 of file bio_dedup_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 ( UNUSED fr_bio_t *  bio,
UNUSED void *  pctx,
void *  buffer,
size_t  size 
)
static

The stub transport returns a copy of request on every read, and reports every write as complete.

Definition at line 58 of file bio_dedup_tests.c.

+ Here is the caller graph for this function:

◆ stub_write_all()

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

Definition at line 68 of file bio_dedup_tests.c.

+ Here is the caller graph for this function:

◆ stub_write_block()

static ssize_t stub_write_block ( UNUSED fr_bio_t *  bio,
UNUSED void *  pctx,
UNUSED void const *  buffer,
UNUSED size_t  size 
)
static

A stub transport write function which always returns IO_WOULD_BLOCK.

Definition at line 78 of file bio_dedup_tests.c.

+ Here is the caller graph for this function:

◆ stub_write_one()

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

A stub transport write function which accepts one byte of each write.

Definition at line 85 of file bio_dedup_tests.c.

+ Here is the caller graph for this function:

◆ test_dedup_alloc()

static fr_bio_t * test_dedup_alloc ( TALLOC_CTX *  ctx,
fr_bio_dedup_config_t *  cfg 
)
static

Allocate a dedup bio with two entries and a one-second lifetime, in front of the stub transport.

Definition at line 108 of file bio_dedup_tests.c.

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

◆ test_entries_are_reused()

static void test_entries_are_reused ( void  )
static

The expiry timer returns each expired entry to the free list, so the dedup bio reads more requests than the dedup bio has entries.

The UDP bio of the RADIUS server has 256 entries. Without the fix for dedup.md finding 1, the UDP bio returned fr_bio_error(OOM) for every request after 256 replies.

Definition at line 214 of file bio_dedup_tests.c.

+ Here is the call graph for this function:

◆ test_equal_expiry()

static void test_equal_expiry ( void  )
static

Two entries with the same expiry time both expire.

See finding 1 in dedup.md. The expiry tree compared only the expiry time, so the tree treated the second entry as a duplicate, and never inserted the second entry.

Definition at line 246 of file bio_dedup_tests.c.

+ Here is the call graph for this function:

◆ test_pending_reply()

static bool test_pending_reply ( fr_bio_t *  dedup,
fr_bio_t *  stub,
uint8_t *  buffer,
size_t  size 
)
static

Read a request, and respond while the stub transport is blocked, so that the reply goes on the pending list.

Definition at line 296 of file bio_dedup_tests.c.

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

◆ test_read_request()

static bool test_read_request ( fr_bio_t *  dedup,
uint8_t *  buffer,
size_t  size 
)
static

Read one request through the dedup bio, and attach reply to the dedup entry of the request.

Definition at line 129 of file bio_dedup_tests.c.

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

◆ test_respond_expires()

static void test_respond_expires ( void  )
static

The dedup entry for a reply sent with fr_bio_dedup_respond() expires once the lifetime is over.

Regression test for dedup.md finding 1. fr_bio_dedup_respond() and fr_bio_dedup_write() did not arm the expiry timer, so no entry expired.

Definition at line 156 of file bio_dedup_tests.c.

+ Here is the call graph for this function:

◆ test_resume_partial()

static void test_resume_partial ( void  )
static

When the stub transport writes only part of a pending reply, the next resume writes the rest.

Definition at line 365 of file bio_dedup_tests.c.

+ Here is the call graph for this function:

◆ test_resume_sends_pending()

static void test_resume_sends_pending ( void  )
static

write_resume sends a pending reply, and the dedup entry then expires once the lifetime is over.

Definition at line 306 of file bio_dedup_tests.c.

+ Here is the call graph for this function:

◆ test_resume_still_blocked()

static void test_resume_still_blocked ( void  )
static

write_resume keeps the pending reply when the stub transport is still blocked.

Definition at line 337 of file bio_dedup_tests.c.

+ Here is the call graph for this function:

◆ test_run_timers()

static void test_run_timers ( fr_bio_dedup_config_t *  cfg)
static

Run every timer which is due within the next five seconds.

Definition at line 144 of file bio_dedup_tests.c.

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

◆ test_write_expires()

static void test_write_expires ( void  )
static

The dedup entry for a reply sent with fr_bio_write() expires once the lifetime is over.

Definition at line 183 of file bio_dedup_tests.c.

+ Here is the call graph for this function:

◆ test_write_resume()

static int test_write_resume ( fr_bio_t *  dedup)
static

Call the dedup bio's write_resume callback, as fr_bio_packet_write_resume() does.

Definition at line 284 of file bio_dedup_tests.c.

+ Here is the caller graph for this function:

Variable Documentation

◆ expired_count

int expired_count
static

Definition at line 32 of file bio_dedup_tests.c.

◆ packet_ctx

int packet_ctx
static

the tests pass only the address of packet_ctx

Definition at line 37 of file bio_dedup_tests.c.

◆ reply

uint8_t reply[4] = { 5, 6, 7, 8 }
static

Definition at line 36 of file bio_dedup_tests.c.

◆ request

uint8_t request[4] = { 1, 2, 3, 4 }
static

Definition at line 35 of file bio_dedup_tests.c.

◆ saved_item

fr_bio_dedup_entry_t* saved_item
static

Definition at line 33 of file bio_dedup_tests.c.

◆ stub_bytes

size_t stub_bytes
static

bytes of reply data which the stub transport has accepted

Definition at line 66 of file bio_dedup_tests.c.

◆ TEST_LIST

TEST_LIST
Initial value:
= {
{ "respond_expires", test_respond_expires },
{ "write_expires", test_write_expires },
{ "entries_are_reused", test_entries_are_reused },
{ "equal_expiry", test_equal_expiry },
{ "resume_sends_pending", test_resume_sends_pending },
{ "resume_still_blocked", test_resume_still_blocked },
{ "resume_partial", test_resume_partial },
}
#define TEST_TERMINATOR
Definition acutest.h:77
static void test_respond_expires(void)
The dedup entry for a reply sent with fr_bio_dedup_respond() expires once the lifetime is over.
static void test_resume_partial(void)
When the stub transport writes only part of a pending reply, the next resume writes the rest.
static void test_write_expires(void)
The dedup entry for a reply sent with fr_bio_write() expires once the lifetime is over.
static void test_resume_still_blocked(void)
write_resume keeps the pending reply when the stub transport is still blocked.
static void test_equal_expiry(void)
Two entries with the same expiry time both expire.
static void test_entries_are_reused(void)
The expiry timer returns each expired entry to the free list, so the dedup bio reads more requests th...
static void test_resume_sends_pending(void)
write_resume sends a pending reply, and the dedup entry then expires once the lifetime is over.

Definition at line 393 of file bio_dedup_tests.c.