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

Tests for radius_pairmove() More...

#include <freeradius-devel/util/test/acutest_common_init.h>
#include <freeradius-devel/util/test/acutest_helpers.h>
#include <freeradius-devel/util/dict_test.h>
#include <freeradius-devel/server/pairmove.h>
#include <freeradius-devel/server/request.h>
#include <freeradius-devel/util/conf.h>
#include <freeradius-devel/util/pair.h>
+ Include dependency graph for pairmove_tests.c:

Go to the source code of this file.

Data Structures

struct  pairmove_case_t
 

Macros

#define TEST_GLOBAL_INIT   test_init()
 

Enumerations

enum  list_target_t {
  LIST_REQUEST = 0 ,
  LIST_REPLY ,
  LIST_CONTROL ,
  LIST_NUM
}
 

Functions

static void list_alloc (TALLOC_CTX *ctx, fr_pair_list_t *list, char const *spec)
 Build a list of pairs from the text in spec
 
static char const * list_str (fr_pair_list_t const *list)
 Render a list in the text form that list_alloc() accepts.
 
static fr_pair_list_t * list_target (TALLOC_CTX **ctx, request_t *request, list_target_t target)
 Get the pair list and the talloc context for a target.
 
static void pairmove_run (pairmove_case_t const *tc, list_target_t target)
 
static void pairmove_run_cases (pairmove_case_t const *cases, size_t num)
 
static request_t * request_make (void)
 Make a request with empty pair lists.
 
static void test_empty_to (void)
 
static void test_init (void)
 Global initialisation.
 
static void test_long_lists (void)
 Merge lists of up to 100 pairs.
 
static void test_mixed (void)
 
static void test_op_add (void)
 
static void test_op_cmp_eq (void)
 
static void test_op_cmp_false (void)
 
static void test_op_eq (void)
 
static void test_op_eq_after_edit (void)
 
static void test_op_le_ge (void)
 
static void test_op_le_ge_prefix (void)
 
static void test_op_prepend (void)
 
static void test_op_set (void)
 
static void test_op_sub (void)
 
static void test_original_list_only (void)
 
static void test_stale_next (void)
 

Variables

struct { 
 
fr_dict_attr_t const * da
 
char const * name
 
} attr_names [] 
 
static TALLOC_CTX * autofree
 
static char const * list_target_names [LIST_NUM] = { "request", "reply", "control" }
 
struct { 
 
fr_token_t op
 
char const * str
 
} op_names [] 
 
static fr_dict_test_attr_t const test_attrs []
 
static fr_dict_t * test_dict
 
 TEST_LIST
 

Detailed Description

Tests for radius_pairmove()

radius_pairmove() merges the pairs of the from list into the to list, and applies the operator of each pair in the from list. These tests record the behaviour of radius_pairmove(). A developer who rewrites the function runs the tests to check that the behaviour is unchanged.

Each test writes a list as short text, for example s0=a i0+=5. Each entry has a name, an operator, and a value:

 s0, s1, s2 `Test-String-0`, `Test-String-1`, `Test-String-2`
 i0, i1             `Test-Uint32-0`, `Test-Uint32-1`
 p4, p6             `Test-IPv4-Prefix`, `Test-IPv6-Prefix`
 un, up             `Test-User-Name`, `Test-User-Password`

Each test renders the merged to list in the same text form, and compares the result with the expected text. Each case runs against the request list, the reply list, and the control list of a request. After the merge, the test frees the to list and checks that the number of talloc blocks under the request equals the number before the merge. The check catches a leak of pairs, or of the temporary arrays that radius_pairmove() allocates.

Definition in file pairmove_tests.c.


Data Structure Documentation

◆ pairmove_case_t

struct pairmove_case_t

Definition at line 278 of file pairmove_tests.c.

Data Fields
char const * expect Expected text form of the to list after the merge.
char const * from Text form of the from list.
char const * name
char const * to Text form of the to list before the merge.

Macro Definition Documentation

◆ TEST_GLOBAL_INIT

#define TEST_GLOBAL_INIT   test_init()

Definition at line 44 of file pairmove_tests.c.

Enumeration Type Documentation

◆ list_target_t

Enumerator
LIST_REQUEST 
LIST_REPLY 
LIST_CONTROL 
LIST_NUM 

Definition at line 229 of file pairmove_tests.c.

Function Documentation

◆ list_alloc()

static void list_alloc ( TALLOC_CTX *  ctx,
fr_pair_list_t *  list,
char const *  spec 
)
static

Build a list of pairs from the text in spec

list_alloc() allocates the pairs in ctx. Because the '!*' operator does not take a value, list_alloc() gives the pair an empty string, or zero for an integer.

Definition at line 132 of file pairmove_tests.c.

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

◆ list_str()

static char const * list_str ( fr_pair_list_t const *  list)
static

Render a list in the text form that list_alloc() accepts.

Because list_str() omits the '=' operator, a result pair that still has an operator from the from list shows the operator in the output.

Definition at line 197 of file pairmove_tests.c.

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

◆ list_target()

static fr_pair_list_t * list_target ( TALLOC_CTX **  ctx,
request_t *  request,
list_target_t  target 
)
static

Get the pair list and the talloc context for a target.

list_target() sets *ctx to the talloc context in which the server allocates the pairs of the list.

Definition at line 261 of file pairmove_tests.c.

+ Here is the caller graph for this function:

◆ pairmove_run()

static void pairmove_run ( pairmove_case_t const *  tc,
list_target_t  target 
)
static

Definition at line 285 of file pairmove_tests.c.

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

◆ pairmove_run_cases()

static void pairmove_run_cases ( pairmove_case_t const *  cases,
size_t  num 
)
static

Definition at line 323 of file pairmove_tests.c.

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

◆ request_make()

static request_t * request_make ( void  )
static

Make a request with empty pair lists.

Definition at line 240 of file pairmove_tests.c.

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

◆ test_empty_to()

static void test_empty_to ( void  )
static

Definition at line 755 of file pairmove_tests.c.

+ Here is the call graph for this function:

◆ test_init()

static void test_init ( void  )
static

Global initialisation.

Definition at line 87 of file pairmove_tests.c.

+ Here is the call graph for this function:

◆ test_long_lists()

static void test_long_lists ( void  )
static

Merge lists of up to 100 pairs.

This test checks the sizes of the temporary arrays that radius_pairmove() allocates. The lengths of the to list and the from list are 1 and 100, 100 and 1, 100 and 100, 0 and 100, and 100 and 0.

Definition at line 688 of file pairmove_tests.c.

+ Here is the call graph for this function:

◆ test_mixed()

static void test_mixed ( void  )
static

Definition at line 661 of file pairmove_tests.c.

+ Here is the call graph for this function:

◆ test_op_add()

static void test_op_add ( void  )
static

Definition at line 386 of file pairmove_tests.c.

+ Here is the call graph for this function:

◆ test_op_cmp_eq()

static void test_op_cmp_eq ( void  )
static

Definition at line 464 of file pairmove_tests.c.

+ Here is the call graph for this function:

◆ test_op_cmp_false()

static void test_op_cmp_false ( void  )
static

Definition at line 446 of file pairmove_tests.c.

+ Here is the call graph for this function:

◆ test_op_eq()

static void test_op_eq ( void  )
static

Definition at line 337 of file pairmove_tests.c.

+ Here is the call graph for this function:

◆ test_op_eq_after_edit()

static void test_op_eq_after_edit ( void  )
static

Definition at line 581 of file pairmove_tests.c.

+ Here is the call graph for this function:

◆ test_op_le_ge()

static void test_op_le_ge ( void  )
static

Definition at line 484 of file pairmove_tests.c.

+ Here is the call graph for this function:

◆ test_op_le_ge_prefix()

static void test_op_le_ge_prefix ( void  )
static

Definition at line 521 of file pairmove_tests.c.

+ Here is the call graph for this function:

◆ test_op_prepend()

static void test_op_prepend ( void  )
static

Definition at line 407 of file pairmove_tests.c.

+ Here is the call graph for this function:

◆ test_op_set()

static void test_op_set ( void  )
static

Definition at line 361 of file pairmove_tests.c.

+ Here is the call graph for this function:

◆ test_op_sub()

static void test_op_sub ( void  )
static

Definition at line 426 of file pairmove_tests.c.

+ Here is the call graph for this function:

◆ test_original_list_only()

static void test_original_list_only ( void  )
static

Definition at line 562 of file pairmove_tests.c.

+ Here is the call graph for this function:

◆ test_stale_next()

static void test_stale_next ( void  )
static

Definition at line 613 of file pairmove_tests.c.

+ Here is the call graph for this function:

Variable Documentation

◆ [struct]

struct { ... } attr_names[]
Initial value:
= {
{ .name = "s0" }, { .name = "s1" }, { .name = "s2" },
{ .name = "i0" }, { .name = "i1" },
{ .name = "p4" }, { .name = "p6" },
{ .name = "un" }, { .name = "up" },
}

◆ autofree

TALLOC_CTX* autofree
static

Definition at line 55 of file pairmove_tests.c.

◆ list_target_names

char const* list_target_names[LIST_NUM] = { "request", "reply", "control" }
static

Definition at line 236 of file pairmove_tests.c.

◆ [struct]

struct { ... } op_names[]
Initial value:
= {
{ ":=", T_OP_SET },
{ "+=", T_OP_ADD_EQ },
{ "-=", T_OP_SUB_EQ },
{ "==", T_OP_CMP_EQ },
{ "<=", T_OP_LE },
{ ">=", T_OP_GE },
{ "!*", T_OP_CMP_FALSE },
{ "^=", T_OP_PREPEND },
{ "=", T_OP_EQ },
}
@ T_OP_SUB_EQ
Definition token.h:68
@ T_OP_EQ
Definition token.h:81
@ T_OP_SET
Definition token.h:82
@ T_OP_ADD_EQ
Definition token.h:67
@ T_OP_CMP_FALSE
Definition token.h:103
@ T_OP_CMP_EQ
Definition token.h:104
@ T_OP_LE
Definition token.h:98
@ T_OP_GE
Definition token.h:96
@ T_OP_PREPEND
Definition token.h:83

◆ test_attrs

fr_dict_test_attr_t const test_attrs[]
static
Initial value:
= {
{ .attr = (fr_dict_test_attr_number_t) 1, .da = &attr_names[0].da, .name = "Test-String-0", .type = FR_TYPE_STRING },
{ .attr = (fr_dict_test_attr_number_t) 2, .da = &attr_names[1].da, .name = "Test-String-1", .type = FR_TYPE_STRING },
{ .attr = (fr_dict_test_attr_number_t) 3, .da = &attr_names[2].da, .name = "Test-String-2", .type = FR_TYPE_STRING },
{ .attr = (fr_dict_test_attr_number_t) 4, .da = &attr_names[3].da, .name = "Test-Uint32-0", .type = FR_TYPE_UINT32 },
{ .attr = (fr_dict_test_attr_number_t) 5, .da = &attr_names[4].da, .name = "Test-Uint32-1", .type = FR_TYPE_UINT32 },
{ .attr = (fr_dict_test_attr_number_t) 6, .da = &attr_names[5].da, .name = "Test-IPv4-Prefix", .type = FR_TYPE_IPV4_PREFIX },
{ .attr = (fr_dict_test_attr_number_t) 7, .da = &attr_names[6].da, .name = "Test-IPv6-Prefix", .type = FR_TYPE_IPV6_PREFIX },
{ .attr = (fr_dict_test_attr_number_t) 8, .da = &attr_names[7].da, .name = "Test-User-Name", .type = FR_TYPE_STRING },
{ .attr = (fr_dict_test_attr_number_t) 9, .da = &attr_names[8].da, .name = "Test-User-Password", .type = FR_TYPE_STRING },
}
fr_dict_test_attr_number_t
Test attribute numbers.
Definition dict_test.h:35
@ FR_TEST_ATTR_INVALID
Definition dict_test.h:36
@ FR_TYPE_IPV6_PREFIX
IPv6 Prefix.
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_IPV4_PREFIX
IPv4 Prefix.
static struct @88 attr_names[]
static char const * name
fr_aka_sim_id_type_t type

Definition at line 72 of file pairmove_tests.c.

◆ test_dict

fr_dict_t* test_dict
static

Definition at line 56 of file pairmove_tests.c.

◆ TEST_LIST

TEST_LIST
Initial value:
= {
{ "op_eq", test_op_eq },
{ "op_set", test_op_set },
{ "op_add", test_op_add },
{ "op_prepend", test_op_prepend },
{ "op_sub", test_op_sub },
{ "op_cmp_false", test_op_cmp_false },
{ "op_cmp_eq", test_op_cmp_eq },
{ "op_le_ge", test_op_le_ge },
{ "op_le_ge_prefix", test_op_le_ge_prefix },
{ "original_list_only", test_original_list_only },
{ "op_eq_after_edit", test_op_eq_after_edit },
{ "stale_next", test_stale_next },
{ "mixed", test_mixed },
{ "long_lists", test_long_lists },
{ "empty_to", test_empty_to },
{ NULL, NULL }
}
static void test_op_cmp_eq(void)
static void test_stale_next(void)
static void test_op_le_ge_prefix(void)
static void test_op_le_ge(void)
static void test_empty_to(void)
static void test_original_list_only(void)
static void test_op_cmp_false(void)
static void test_op_set(void)
static void test_op_eq(void)
static void test_op_prepend(void)
static void test_long_lists(void)
Merge lists of up to 100 pairs.
static void test_op_add(void)
static void test_op_sub(void)
static void test_op_eq_after_edit(void)
static void test_mixed(void)

Definition at line 818 of file pairmove_tests.c.