31 #define USE_CONSTRUCTOR
36 #ifdef USE_CONSTRUCTOR
40 #define TEST_INIT pair_list_perf_init()
43 #include <freeradius-devel/util/acutest.h>
45 #ifdef WITH_VERIFY_PTR
46 #undef WITH_VERIFY_PTR
49 #include <freeradius-devel/util/dict_test.h>
50 #include <freeradius-devel/server/base.h>
51 #include <freeradius-devel/util/rand.h>
52 #include <freeradius-devel/util/pair.h>
53 #include <freeradius-devel/util/pair_legacy.h>
61 static char const *test_attrs_0 = \
62 "Test-String-# = \"hello\","
63 "Test-Octets-# = 0x0102030405060708,"
64 "Test-IPv4-Addr-# = 192.168.1.1,"
65 "Test-IPv4-Prefix-# = 192.168/16,"
66 "Test-IPv6-Addr-# = fd12:3456:789a:1::1,"
67 "Test-IPv6-Prefix-# = fd12:3456:789a:1::/64,"
68 "Test-Ethernet-# = 11:22:33:44:55:66,"
70 "Test-Uint16-# = 65535,"
71 "Test-Uint32-# = 4294967295,"
72 "Test-Uint64-# = 18446744073709551615,"
74 "Test-Int16-# = -4573,"
75 "Test-Int32-# = 45645,"
76 "Test-Int64-# = 85645,"
77 "Test-Float32-# = 1.134,"
78 "Test-Float64-# = 1.1345,"
79 "Test-Date-# += \"Jan 1 2020 00:00:00 UTC\","
80 "Test-TLV-#.String = \"nested\","
81 "Test-Struct-#.uint32 = 1234";
83 static char const *test_attrs_25 = \
84 "Test-String-# += \"hello\","
85 "Test-String-# += \"goodbye\","
86 "Test-String-# += \"hola\","
87 "Test-String-# += \"hasta pronto\","
88 "Test-String-# += \"bonjour\","
89 "Test-Octets-# += 0x0102030405060708,"
90 "Test-IPv4-Addr-# = 192.168.1.1,"
91 "Test-IPv4-Prefix-# = 192.168/16,"
92 "Test-IPv6-Addr-# = fd12:3456:789a:1::1,"
93 "Test-IPv6-Prefix-# = fd12:3456:789a:1::/64,"
94 "Test-Ethernet-# = 11:22:33:44:55:66,"
96 "Test-Uint16-# = 65535,"
97 "Test-Uint32-# = 4294967295,"
98 "Test-Uint64-# = 18446744073709551615,"
99 "Test-Int64-# = 85645,"
100 "Test-Float32-# = 1.134,"
101 "Test-Date-# += \"Jan 1 2020 00:00:00 UTC\","
102 "Test-TLV-#.String = \"nested\","
103 "Test-Struct-#.uint32 = 1234";
105 static char const *test_attrs_50 = \
106 "Test-String-# += \"hello\","
107 "Test-String-# += \"goodbye\","
108 "Test-String-# += \"hola\","
109 "Test-String-# += \"hasta pronto\","
110 "Test-String-# += \"bonjour\","
111 "Test-String-# += \"au revoir\","
112 "Test-String-# += \"halo\","
113 "Test-String-# += \"kwaheri\","
114 "Test-String-# += \"ciao\","
115 "Test-String-# += \"arrivederci\","
116 "Test-IPv4-Addr-# = 192.168.1.1,"
117 "Test-IPv4-Prefix-# = 192.168/16,"
118 "Test-IPv6-Addr-# = fd12:3456:789a:1::1,"
119 "Test-IPv6-Prefix-# = fd12:3456:789a:1::/64,"
120 "Test-Ethernet-# = 11:22:33:44:55:66,"
121 "Test-Uint8-# = 255,"
122 "Test-Int64-# = 85645,"
123 "Test-Date-# += \"Jan 1 2020 00:00:00 UTC\","
124 "Test-TLV-#.String = \"nested\","
125 "Test-Struct-#.uint32 = 1234";
127 static char const *test_attrs_75 = \
128 "Test-String-# += \"hello\","
129 "Test-String-# += \"goodbye\","
130 "Test-String-# += \"hola\","
131 "Test-String-# += \"hasta pronto\","
132 "Test-String-# += \"bonjour\","
133 "Test-String-# += \"au revoir\","
134 "Test-String-# += \"halo\","
135 "Test-String-# += \"kwaheri\","
136 "Test-String-# += \"ciao\","
137 "Test-String-# += \"arrivederci\","
138 "Test-String-# += \"halo\","
139 "Test-String-# += \"selamat tinggal\","
140 "Test-String-# += \"你好\","
141 "Test-String-# += \"再见\","
142 "Test-String-# += \"Привет\","
143 "Test-Uint8-# = 255,"
144 "Test-Int64-# = 85645,"
145 "Test-Date-# += \"Jan 1 2020 00:00:00 UTC\","
146 "Test-TLV-#.String = \"nested\","
147 "Test-Struct-#.uint32 = 1234";
149 static char const *test_attrs_100 = \
150 "Test-String-# += \"hello\","
151 "Test-String-# += \"goodbye\","
152 "Test-String-# += \"hola\","
153 "Test-String-# += \"hasta pronto\","
154 "Test-String-# += \"bonjour\","
155 "Test-String-# += \"au revoir\","
156 "Test-String-# += \"halo\","
157 "Test-String-# += \"kwaheri\","
158 "Test-String-# += \"ciao\","
159 "Test-String-# += \"arrivederci\","
160 "Test-String-# += \"halo\","
161 "Test-String-# += \"selamat tinggal\","
162 "Test-String-# += \"你好\","
163 "Test-String-# += \"再见\","
164 "Test-String-# += \"Привет\","
165 "Test-String-# += \"до свидания\","
166 "Test-String-# += \"вся слава советской россии\","
167 "Test-String-# += \"у нас есть видео с мочой\","
168 "Test-String-# += \"Байден заплатит за\","
169 "Test-String-# += \"приставание к бурундукам\"";
178 int const perc,
int const reps)
181 char *prep_pairs, *p;
193 prep_pairs = talloc_array(NULL,
char, strlen(pairs) + 1);
200 for (i = 0; i < reps; i++) {
210 strcpy(prep_pairs, pairs);
212 while ((p = strchr(p,
'#'))) {
216 if (slen <= 0)
fr_perror(
"pair_list_perf_tests");
221 if ((i == 0) && (perc > 0) && (reps > 0)) {
230 for (j = 0; j < (
size_t)(input_count * perc / 100); j++) {
322 size_t input_count = talloc_array_length(source_vps);
333 if (input_count > len) input_count = len;
338 for (i = 0; i < reps; i++) {
339 for (j = 0; j < len; j++) {
365 size_t input_count = talloc_array_length(source_vps);
369 if (input_count > len) input_count = len;
376 for (i = 0; i < len; i++) {
385 for (i = 0; i < reps; i++) {
386 for (j = 0; j < len; j++) {
388 da = source_vps[idx]->
da;
406 unsigned int i, j, nth_item;
411 size_t input_count = talloc_array_length(source_vps);
415 if (input_count > len) input_count = len;
422 for (i = 0; i < len; i++) {
432 nth_item = perc == 0 ? 1 : (
unsigned int)(len * perc / 100);
433 for (i = 0; i < reps; i++) {
434 for (j = 0; j < len; j++) {
437 da = source_vps[idx]->
da;
459 size_t input_count = talloc_array_length(source_vps);
463 if (input_count > len) input_count = len;
467 for (i = 0; i < reps; i++) {
468 for (j = 0; j < len; j++) {
486 #define test_func(_func, _count, _perc, _source_vps) \
487 static void test_ ## _func ## _ ## _count ## _ ## _perc(void)\
489 do_test_ ## _func(_count, _perc, 10000, _source_vps);\
492 #define test_funcs(_func, _perc) \
493 test_func(_func, 20, _perc, source_vps_ ## _perc) \
494 test_func(_func, 40, _perc, source_vps_ ## _perc) \
495 test_func(_func, 60, _perc, source_vps_ ## _perc) \
496 test_func(_func, 80, _perc, source_vps_ ## _perc) \
497 test_func(_func, 100, _perc, source_vps_ ## _perc)
499 #define all_test_funcs(_func) \
500 test_funcs(_func, 0) \
501 test_funcs(_func, 25) \
502 test_funcs(_func, 50) \
503 test_funcs(_func, 75) \
504 test_funcs(_func, 100)
511 #define repetition_tests(_func, _perc) \
512 { #_func "_20_" #_perc, test_ ## _func ## _20_ ## _perc},\
513 { #_func "_40_" #_perc, test_ ## _func ## _40_ ## _perc},\
514 { #_func "_60_" #_perc, test_ ## _func ## _60_ ## _perc},\
515 { #_func "_80_" #_perc, test_ ## _func ## _80_ ## _perc},\
516 { #_func "_100_" #_perc, test_ ## _func ## _100_ ## _perc},\
518 #define all_repetition_tests(_func) \
519 repetition_tests(_func, 0) \
520 repetition_tests(_func, 25) \
521 repetition_tests(_func, 50) \
522 repetition_tests(_func, 75) \
523 repetition_tests(_func, 100)
#define TEST_MSG_ALWAYS(...)
strcpy(log_entry->msg, buffer)
#define TEST_ASSERT(cond)
#define fr_exit_now(_x)
Exit without calling atexit() handlers, producing a log message in debug builds.
fr_dict_attr_t const * fr_dict_root(fr_dict_t const *dict)
Return the root attribute of a dictionary.
fr_dict_test_attr_t const fr_dict_test_attrs[]
int fr_dict_test_attrs_init(fr_dict_t *dict, fr_dict_test_attr_t const *test_defs, unsigned int base, int inst)
Add our test attributes to our test dictionary.
int fr_dict_test_init(TALLOC_CTX *ctx, fr_dict_t **dict_p, fr_dict_test_attr_t const *test_defs)
Initialise a test dictionary and add our test_defs to it.
fr_pair_t * fr_pair_find_by_da(fr_pair_list_t const *list, fr_pair_t const *prev, fr_dict_attr_t const *da)
Find the first pair with a matching da.
int fr_pair_append(fr_pair_list_t *list, fr_pair_t *to_add)
Add a VP to the end of the list.
void fr_pair_list_init(fr_pair_list_t *list)
Initialise a pair list header.
fr_pair_t * fr_pair_find_by_da_idx(fr_pair_list_t const *list, fr_dict_attr_t const *da, unsigned int idx)
Find a pair with a matching da at a given index.
int fr_pair_sublist_copy(TALLOC_CTX *ctx, fr_pair_list_t *to, fr_pair_list_t const *from, fr_pair_t const *start, unsigned int count)
Duplicate a list of pairs starting at a particular item.
fr_pair_t * fr_pair_copy(TALLOC_CTX *ctx, fr_pair_t const *vp)
Copy a single valuepair.
fr_slen_t fr_pair_list_afrom_substr(fr_pair_parse_t const *root, fr_pair_parse_t *relative, fr_sbuff_t *in)
Parse a fr_pair_list_t from a substring.
struct fr_pair_parse_s fr_pair_parse_t
static void do_test_fr_pair_find_by_da_idx(unsigned int len, unsigned int perc, unsigned int reps, fr_pair_t *source_vps[])
#define all_repetition_tests(_func)
static void do_test_fr_pair_append(unsigned int len, unsigned int perc, unsigned int reps, fr_pair_t *source_vps[])
static void pair_list_perf_init(void)
static void do_test_find_nth(unsigned int len, unsigned int perc, unsigned int reps, fr_pair_t *source_vps[])
#define all_test_funcs(_func)
static void do_test_fr_pair_list_free(unsigned int len, unsigned int perc, unsigned int reps, fr_pair_t *source_vps[])
static fr_dict_t * test_dict
static TALLOC_CTX * autofree
uint32_t fr_fast_rand(fr_fast_rand_t *ctx)
uint32_t fr_rand(void)
Return a 32-bit random number.
Smaller fast random number generator.
#define FR_SBUFF_IN(_start, _len_or_end)
#define fr_time()
Allow us to arbitrarily manipulate time.
Stores an attribute, a value and various bits of other data.
fr_dict_attr_t const *_CONST da
Dictionary attribute defines the attribute number, vendor and type of the pair.
#define talloc_autofree_context
The original function is deprecated, so replace it with our version.
int fr_time_start(void)
Initialize the local time.
static fr_time_delta_t fr_time_delta_add(fr_time_delta_t a, fr_time_delta_t b)
static int64_t fr_time_delta_unwrap(fr_time_delta_t time)
#define fr_time_delta_wrap(_time)
#define fr_time_sub(_a, _b)
Subtract one time from another.
A time delta, a difference in time measured in nanoseconds.
fr_pair_t * fr_pair_list_head(fr_pair_list_t const *list)
Get the head of a valuepair list.
fr_pair_t * fr_pair_remove(fr_pair_list_t *list, fr_pair_t *vp)
Remove fr_pair_t from a list without freeing.
fr_pair_t * fr_pair_list_next(fr_pair_list_t const *list, fr_pair_t const *item))
Get the next item in a valuepair list after a specific entry.
void fr_pair_list_free(fr_pair_list_t *list)
Free memory used by a valuepair list.
void fr_pair_list_append(fr_pair_list_t *dst, fr_pair_list_t *src)
Appends a list of fr_pair_t from a temporary list to a destination list.
size_t fr_pair_list_num_elements(fr_pair_list_t const *list)
Get the length of a list of fr_pair_t.
void fr_perror(char const *fmt,...)
Print the current error to stderr with a prefix.
int fr_check_lib_magic(uint64_t magic)
Check if the application linking to the library has the correct magic number.
#define RADIUSD_MAGIC_NUMBER
static size_t char ** out