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

Tests for slab allocator. More...

#include "acutest_common_init.h"
#include "acutest_helpers.h"
#include <freeradius-devel/util/timer.h>
#include <freeradius-devel/util/slab.h>
+ Include dependency graph for slab_tests.c:

Go to the source code of this file.

Data Structures

struct  test_conf_t
 
struct  test_count_t
 How many times each callback has run. More...
 
struct  test_element_t
 
struct  test_uctx_t
 

Functions

static void test_alloc (void)
 Test basic allocation and reservation of elements.
 
static void test_alloc_fail (void)
 Test allocation beyond max fails correctly.
 
static void test_alloc_reserve_count (void)
 Count the callbacks across a reserve, release, reserve cycle.
 
static void test_bulk_teardown (void)
 Test that talloc free of the slab list with in-use elements does not assert.
 
static void test_child_alloc (void)
 
static void test_clearup_1 (void)
 Test of clearing unused slabs.
 
static void test_clearup_2 (void)
 Test that slab clearing does not go beyond the minimum.
 
static void test_clearup_3 (void)
 Test that repeated clearing frees more slabs.
 
static int test_element_alloc (test_element_t *elem, void *uctx)
 
static int test_element_count_alloc (test_element_t *elem, void *uctx)
 
static int test_element_count_reserve (UNUSED test_element_t *elem, void *uctx)
 
static int test_element_free (test_element_t *elem, void *uctx)
 
static int test_element_reserve (test_element_t *elem, void *uctx)
 
static void test_free (void)
 Test that freeing an element results in the destructor being called, and that all accounting is correctly updated.
 
static void test_free_and_reserve (void)
 Test that reserving after talloc_free of an element still works.
 
static void test_free_mixed (void)
 Test mixed release and talloc_free of elements from the same slab.
 
static void test_free_multiple (void)
 Test that talloc freeing multiple in-use elements correctly updates accounting.
 
static void test_init (void)
 Test that a callback correctly initialises slab elements on first use.
 
static void test_init_reserve (void)
 Test that reserve callback runs after init callback.
 
static void test_realloc (void)
 Test that reserving after clearup results in new slab allocation.
 
static void test_reserve (void)
 Test that a reserve callback correctly initialises slab elements.
 
static void test_reserve_mru (void)
 Test that setting reserve_mru to true works.
 
static void test_reuse_noreset (void)
 Test that freeing an element makes it available for reuse with the element not reset between uses.
 
static void test_reuse_reset (void)
 Test that freeing an element makes it available for reuse with the element reset between uses.
 
static fr_time_t test_time (void)
 

Variables

static fr_slab_config_t def_slab_config
 
 TEST_LIST
 
static fr_time_t test_time_base = fr_time_wrap(1)
 

Detailed Description

Tests for slab allocator.

Definition in file slab_tests.c.


Data Structure Documentation

◆ test_conf_t

struct test_conf_t

Definition at line 21 of file slab_tests.c.

Data Fields
int initial

◆ test_count_t

struct test_count_t

How many times each callback has run.

Definition at line 434 of file slab_tests.c.

Data Fields
int alloc Calls to the alloc callback.
int reserve Calls to the reserve callback.

◆ test_element_t

struct test_element_t

Definition at line 12 of file slab_tests.c.

Data Fields
char * name
int num

◆ test_uctx_t

struct test_uctx_t

Definition at line 17 of file slab_tests.c.

Data Fields
int count

Function Documentation

◆ test_alloc()

static void test_alloc ( void  )
static

Test basic allocation and reservation of elements.

Definition at line 54 of file slab_tests.c.

+ Here is the call graph for this function:

◆ test_alloc_fail()

static void test_alloc_fail ( void  )
static

Test allocation beyond max fails correctly.

Definition at line 124 of file slab_tests.c.

+ Here is the call graph for this function:

◆ test_alloc_reserve_count()

static void test_alloc_reserve_count ( void  )
static

Count the callbacks across a reserve, release, reserve cycle.

Releasing an element hands it back to the slab, and reserving again hands back the same element with whatever the alloc callback set up still in place. Callers rely on that. rlm_ftp, rlm_imap, rlm_rest and rlm_smtp create a CURL handle in their alloc callback, and rlm_krb5 creates a Kerberos context. None of those should be built again for every request.

So the alloc callback runs once per element, and the reserve callback runs once per reserve. Nothing else in this file measures the difference: a change which turned the slab into a plain memory recycler, freeing each element on release and building a new one on the next reserve, would still pass every other test here. The counts below are what notices.

Definition at line 512 of file slab_tests.c.

+ Here is the call graph for this function:

◆ test_bulk_teardown()

static void test_bulk_teardown ( void  )
static

Test that talloc free of the slab list with in-use elements does not assert.

This exercises the being_freed flag path: the slab destructor sets being_freed = true before children are freed, so element destructors will see the flag and skip the direct-free assertion.

Definition at line 892 of file slab_tests.c.

+ Here is the call graph for this function:

◆ test_child_alloc()

static void test_child_alloc ( void  )
static

Definition at line 1019 of file slab_tests.c.

+ Here is the call graph for this function:

◆ test_clearup_1()

static void test_clearup_1 ( void  )
static

Test of clearing unused slabs.

Definition at line 572 of file slab_tests.c.

+ Here is the call graph for this function:

◆ test_clearup_2()

static void test_clearup_2 ( void  )
static

Test that slab clearing does not go beyond the minimum.

Definition at line 625 of file slab_tests.c.

+ Here is the call graph for this function:

◆ test_clearup_3()

static void test_clearup_3 ( void  )
static

Test that repeated clearing frees more slabs.

Definition at line 689 of file slab_tests.c.

+ Here is the call graph for this function:

◆ test_element_alloc()

static int test_element_alloc ( test_element_t *  elem,
void *  uctx 
)
static

Definition at line 344 of file slab_tests.c.

+ Here is the caller graph for this function:

◆ test_element_count_alloc()

static int test_element_count_alloc ( test_element_t *  elem,
void *  uctx 
)
static

Definition at line 439 of file slab_tests.c.

+ Here is the caller graph for this function:

◆ test_element_count_reserve()

static int test_element_count_reserve ( UNUSED test_element_t *  elem,
void *  uctx 
)
static

Definition at line 453 of file slab_tests.c.

+ Here is the caller graph for this function:

◆ test_element_free()

static int test_element_free ( test_element_t *  elem,
void *  uctx 
)
static

Definition at line 35 of file slab_tests.c.

+ Here is the caller graph for this function:

◆ test_element_reserve()

static int test_element_reserve ( test_element_t *  elem,
void *  uctx 
)
static

Definition at line 425 of file slab_tests.c.

+ Here is the caller graph for this function:

◆ test_free()

static void test_free ( void  )
static

Test that freeing an element results in the destructor being called, and that all accounting is correctly updated.

Definition at line 316 of file slab_tests.c.

+ Here is the call graph for this function:

◆ test_free_and_reserve()

static void test_free_and_reserve ( void  )
static

Test that reserving after talloc_free of an element still works.

Definition at line 980 of file slab_tests.c.

+ Here is the call graph for this function:

◆ test_free_mixed()

static void test_free_mixed ( void  )
static

Test mixed release and talloc_free of elements from the same slab.

Definition at line 931 of file slab_tests.c.

+ Here is the call graph for this function:

◆ test_free_multiple()

static void test_free_multiple ( void  )
static

Test that talloc freeing multiple in-use elements correctly updates accounting.

Definition at line 845 of file slab_tests.c.

+ Here is the call graph for this function:

◆ test_init()

static void test_init ( void  )
static

Test that a callback correctly initialises slab elements on first use.

Definition at line 354 of file slab_tests.c.

+ Here is the call graph for this function:

◆ test_init_reserve()

static void test_init_reserve ( void  )
static

Test that reserve callback runs after init callback.

Definition at line 464 of file slab_tests.c.

+ Here is the call graph for this function:

◆ test_realloc()

static void test_realloc ( void  )
static

Test that reserving after clearup results in new slab allocation.

Definition at line 782 of file slab_tests.c.

+ Here is the call graph for this function:

◆ test_reserve()

static void test_reserve ( void  )
static

Test that a reserve callback correctly initialises slab elements.

Definition at line 391 of file slab_tests.c.

+ Here is the call graph for this function:

◆ test_reserve_mru()

static void test_reserve_mru ( void  )
static

Test that setting reserve_mru to true works.

After releasing an element, a subsequent reserve should return the same element

Definition at line 272 of file slab_tests.c.

+ Here is the call graph for this function:

◆ test_reuse_noreset()

static void test_reuse_noreset ( void  )
static

Test that freeing an element makes it available for reuse with the element not reset between uses.

Definition at line 220 of file slab_tests.c.

+ Here is the call graph for this function:

◆ test_reuse_reset()

static void test_reuse_reset ( void  )
static

Test that freeing an element makes it available for reuse with the element reset between uses.

Definition at line 161 of file slab_tests.c.

+ Here is the call graph for this function:

◆ test_time()

static fr_time_t test_time ( void  )
static

Definition at line 43 of file slab_tests.c.

+ Here is the caller graph for this function:

Variable Documentation

◆ def_slab_config

fr_slab_config_t def_slab_config
static
Initial value:
.elements_per_slab = 2,
.min_elements = 1,
.max_elements = 4,
.at_max_fail = false,
.num_children = 0,
.child_pool_size = 0,
.interval.value = 1 * NSEC
}
Tuneable parameters for slabs.
Definition slab.h:42
#define NSEC
Definition time.h:379

Definition at line 25 of file slab_tests.c.

◆ TEST_LIST

TEST_LIST
Initial value:
= {
{ "test_alloc", test_alloc },
{ "test_alloc_fail", test_alloc_fail },
{ "test_reuse_reset", test_reuse_reset },
{ "test_reuse_noreset", test_reuse_noreset },
{ "test_reserve_mru", test_reserve_mru },
{ "test_free", test_free },
{ "test_free_multiple", test_free_multiple },
{ "test_bulk_teardown", test_bulk_teardown },
{ "test_free_mixed", test_free_mixed },
{ "test_free_and_reserve", test_free_and_reserve },
{ "test_init", test_init },
{ "test_reserve", test_reserve },
{ "test_init_reserve", test_init_reserve },
{ "test_alloc_reserve_count", test_alloc_reserve_count },
{ "test_clearup_1", test_clearup_1 },
{ "test_clearup_2", test_clearup_2 },
{ "test_clearup_3", test_clearup_3 },
{ "test_realloc", test_realloc },
{ "test_child_alloc", test_child_alloc },
}
#define TEST_TERMINATOR
Definition acutest.h:64
static void test_clearup_3(void)
Test that repeated clearing frees more slabs.
Definition slab_tests.c:689
static void test_reserve(void)
Test that a reserve callback correctly initialises slab elements.
Definition slab_tests.c:391
static void test_init_reserve(void)
Test that reserve callback runs after init callback.
Definition slab_tests.c:464
static void test_reserve_mru(void)
Test that setting reserve_mru to true works.
Definition slab_tests.c:272
static void test_clearup_2(void)
Test that slab clearing does not go beyond the minimum.
Definition slab_tests.c:625
static void test_reuse_noreset(void)
Test that freeing an element makes it available for reuse with the element not reset between uses.
Definition slab_tests.c:220
static void test_child_alloc(void)
static void test_clearup_1(void)
Test of clearing unused slabs.
Definition slab_tests.c:572
static void test_free(void)
Test that freeing an element results in the destructor being called, and that all accounting is corre...
Definition slab_tests.c:316
static void test_alloc(void)
Test basic allocation and reservation of elements.
Definition slab_tests.c:54
static void test_reuse_reset(void)
Test that freeing an element makes it available for reuse with the element reset between uses.
Definition slab_tests.c:161
static void test_free_and_reserve(void)
Test that reserving after talloc_free of an element still works.
Definition slab_tests.c:980
static void test_free_mixed(void)
Test mixed release and talloc_free of elements from the same slab.
Definition slab_tests.c:931
static void test_alloc_reserve_count(void)
Count the callbacks across a reserve, release, reserve cycle.
Definition slab_tests.c:512
static void test_init(void)
Test that a callback correctly initialises slab elements on first use.
Definition slab_tests.c:354
static void test_bulk_teardown(void)
Test that talloc free of the slab list with in-use elements does not assert.
Definition slab_tests.c:892
static void test_alloc_fail(void)
Test allocation beyond max fails correctly.
Definition slab_tests.c:124
static void test_realloc(void)
Test that reserving after clearup results in new slab allocation.
Definition slab_tests.c:782
static void test_free_multiple(void)
Test that talloc freeing multiple in-use elements correctly updates accounting.
Definition slab_tests.c:845

Definition at line 1056 of file slab_tests.c.

◆ test_time_base

fr_time_t test_time_base = fr_time_wrap(1)
static

Definition at line 42 of file slab_tests.c.