31#define USE_CONSTRUCTOR
40#define TEST_INIT pair_list_perf_init()
49#include <freeradius-devel/util/dict_test.h>
50#include <freeradius-devel/server/base.h>
53#define TEST_MSG_STATS \
55 TEST_MSG_ALWAYS("\n"); \
56 TEST_MSG_ALWAYS("repetitions = %u", reps); \
57 TEST_MSG_ALWAYS("%% repeated = %u", perc); \
58 TEST_MSG_ALWAYS("list_length = %u", len); \
59 TEST_MSG_ALWAYS("elapsed (ns) = %" PRId64, fr_time_delta_unwrap(used)); \
60 TEST_MSG_ALWAYS("calls/s = %0.0lf", (reps * len)/(fr_time_delta_unwrap(used) / (double)NSEC)); \
61 TEST_MSG_ALWAYS("(ns) / call = %0.0lf", (double) fr_time_delta_unwrap(used) / (double) reps); \
70static char const *test_attrs_0 = \
71 "Test-String-# = \"hello\","
72 "Test-Octets-# = 0x0102030405060708,"
73 "Test-IPv4-Addr-# = 192.168.1.1,"
74 "Test-IPv4-Prefix-# = 192.168/16,"
75 "Test-IPv6-Addr-# = fd12:3456:789a:1::1,"
76 "Test-IPv6-Prefix-# = fd12:3456:789a:1::/64,"
77 "Test-Ethernet-# = 11:22:33:44:55:66,"
79 "Test-Uint16-# = 65535,"
80 "Test-Uint32-# = 4294967295,"
81 "Test-Uint64-# = 18446744073709551615,"
83 "Test-Int16-# = -4573,"
84 "Test-Int32-# = 45645,"
85 "Test-Int64-# = 85645,"
86 "Test-Float32-# = 1.134,"
87 "Test-Float64-# = 1.1345,"
88 "Test-Date-# += \"Jan 1 2020 00:00:00 UTC\","
89 "Test-TLV-#.String = \"nested\","
90 "Test-Struct-#.uint32 = 1234";
92static char const *test_attrs_25 = \
93 "Test-String-# += \"hello\","
94 "Test-String-# += \"goodbye\","
95 "Test-String-# += \"hola\","
96 "Test-String-# += \"hasta pronto\","
97 "Test-String-# += \"bonjour\","
98 "Test-Octets-# += 0x0102030405060708,"
99 "Test-IPv4-Addr-# = 192.168.1.1,"
100 "Test-IPv4-Prefix-# = 192.168/16,"
101 "Test-IPv6-Addr-# = fd12:3456:789a:1::1,"
102 "Test-IPv6-Prefix-# = fd12:3456:789a:1::/64,"
103 "Test-Ethernet-# = 11:22:33:44:55:66,"
104 "Test-Uint8-# = 255,"
105 "Test-Uint16-# = 65535,"
106 "Test-Uint32-# = 4294967295,"
107 "Test-Uint64-# = 18446744073709551615,"
108 "Test-Int64-# = 85645,"
109 "Test-Float32-# = 1.134,"
110 "Test-Date-# += \"Jan 1 2020 00:00:00 UTC\","
111 "Test-TLV-#.String = \"nested\","
112 "Test-Struct-#.uint32 = 1234";
114static char const *test_attrs_50 = \
115 "Test-String-# += \"hello\","
116 "Test-String-# += \"goodbye\","
117 "Test-String-# += \"hola\","
118 "Test-String-# += \"hasta pronto\","
119 "Test-String-# += \"bonjour\","
120 "Test-String-# += \"au revoir\","
121 "Test-String-# += \"halo\","
122 "Test-String-# += \"kwaheri\","
123 "Test-String-# += \"ciao\","
124 "Test-String-# += \"arrivederci\","
125 "Test-IPv4-Addr-# = 192.168.1.1,"
126 "Test-IPv4-Prefix-# = 192.168/16,"
127 "Test-IPv6-Addr-# = fd12:3456:789a:1::1,"
128 "Test-IPv6-Prefix-# = fd12:3456:789a:1::/64,"
129 "Test-Ethernet-# = 11:22:33:44:55:66,"
130 "Test-Uint8-# = 255,"
131 "Test-Int64-# = 85645,"
132 "Test-Date-# += \"Jan 1 2020 00:00:00 UTC\","
133 "Test-TLV-#.String = \"nested\","
134 "Test-Struct-#.uint32 = 1234";
136static char const *test_attrs_75 = \
137 "Test-String-# += \"hello\","
138 "Test-String-# += \"goodbye\","
139 "Test-String-# += \"hola\","
140 "Test-String-# += \"hasta pronto\","
141 "Test-String-# += \"bonjour\","
142 "Test-String-# += \"au revoir\","
143 "Test-String-# += \"halo\","
144 "Test-String-# += \"kwaheri\","
145 "Test-String-# += \"ciao\","
146 "Test-String-# += \"arrivederci\","
147 "Test-String-# += \"halo\","
148 "Test-String-# += \"selamat tinggal\","
149 "Test-String-# += \"你好\","
150 "Test-String-# += \"再见\","
151 "Test-String-# += \"Я люблю сир\","
152 "Test-Uint8-# = 255,"
153 "Test-Int64-# = 85645,"
154 "Test-Date-# += \"Jan 1 2020 00:00:00 UTC\","
155 "Test-TLV-#.String = \"nested\","
156 "Test-Struct-#.uint32 = 1234";
158static char const *test_attrs_100 = \
159 "Test-String-# += \"hello\","
160 "Test-String-# += \"goodbye\","
161 "Test-String-# += \"hola\","
162 "Test-String-# += \"hasta pronto\","
163 "Test-String-# += \"bonjour\","
164 "Test-String-# += \"au revoir\","
165 "Test-String-# += \"halo\","
166 "Test-String-# += \"kwaheri\","
167 "Test-String-# += \"ciao\","
168 "Test-String-# += \"arrivederci\","
169 "Test-String-# += \"halo\","
170 "Test-String-# += \"selamat tinggal\","
171 "Test-String-# += \"你好\","
172 "Test-String-# += \"再见\","
173 "Test-String-# += \"Я люблю сир\","
174 "Test-String-# += \"Найкращий сир - бринза\","
175 "Test-String-# += \"Сулугуні чудовий на грилі\","
176 "Test-String-# += \"Сирники з домашнього сиру\","
177 "Test-String-# += \"Карпатська бринза пахне гірськими травами\","
178 "Test-String-# += \"Вареники з сиром найсмачніші\"";
199static int fr_pair_sublist_copy(TALLOC_CTX *ctx,
fr_pair_list_t *to,
204 unsigned int cnt = 0;
231 int const perc,
int const reps)
234 char *prep_pairs, *p;
246 prep_pairs = talloc_array(NULL,
char, strlen(pairs) + 1);
253 for (i = 0; i < reps; i++) {
265 strcpy(prep_pairs, pairs);
267 while ((p = strchr(p,
'#'))) {
271 if (slen <= 0)
fr_perror(
"pair_list_perf_tests");
276 if ((i == 0) && (perc > 0) && (reps > 0)) {
285 for (j = 0; j < (
size_t)(input_count * perc / 100); j++) {
305 fr_pair_sublist_copy(ctx, &full_list, &dups,
vp);
316 fr_pair_sublist_copy(ctx, &full_list, &list,
vp);
377 size_t input_count = talloc_array_length(source_vps);
388 if (input_count > len) input_count = len;
393 for (i = 0; i < reps; i++) {
394 for (j = 0; j < len; j++) {
416 size_t input_count = talloc_array_length(source_vps);
420 if (input_count > len) input_count = len;
427 for (i = 0; i < len; i++) {
436 for (i = 0; i < reps; i++) {
437 for (j = 0; j < len; j++) {
439 da = source_vps[idx]->
da;
453 unsigned int i, j, nth_item;
458 size_t input_count = talloc_array_length(source_vps);
462 if (input_count > len) input_count = len;
469 for (i = 0; i < len; i++) {
479 nth_item = perc == 0 ? 1 : (
unsigned int)(len * perc / 100);
480 for (i = 0; i < reps; i++) {
481 for (j = 0; j < len; j++) {
484 da = source_vps[idx]->
da;
502 size_t input_count = talloc_array_length(source_vps);
506 if (input_count > len) input_count = len;
510 for (i = 0; i < reps; i++) {
511 for (j = 0; j < len; j++) {
525#define test_func(_func, _count, _perc, _source_vps) \
526static void test_ ## _func ## _ ## _count ## _ ## _perc(void)\
528 do_test_ ## _func(_count, _perc, 10000, _source_vps);\
531#define test_funcs(_func, _perc) \
532 test_func(_func, 20, _perc, source_vps_ ## _perc) \
533 test_func(_func, 40, _perc, source_vps_ ## _perc) \
534 test_func(_func, 60, _perc, source_vps_ ## _perc) \
535 test_func(_func, 80, _perc, source_vps_ ## _perc) \
536 test_func(_func, 100, _perc, source_vps_ ## _perc)
538#define all_test_funcs(_func) \
539 test_funcs(_func, 0) \
540 test_funcs(_func, 25) \
541 test_funcs(_func, 50) \
542 test_funcs(_func, 75) \
543 test_funcs(_func, 100)
550#define repetition_tests(_func, _perc) \
551 { #_func "_20_" #_perc, test_ ## _func ## _20_ ## _perc},\
552 { #_func "_40_" #_perc, test_ ## _func ## _40_ ## _perc},\
553 { #_func "_60_" #_perc, test_ ## _func ## _60_ ## _perc},\
554 { #_func "_80_" #_perc, test_ ## _func ## _80_ ## _perc},\
555 { #_func "_100_" #_perc, test_ ## _func ## _100_ ## _perc},\
557#define all_repetition_tests(_func) \
558 repetition_tests(_func, 0) \
559 repetition_tests(_func, 25) \
560 repetition_tests(_func, 50) \
561 repetition_tests(_func, 75) \
562 repetition_tests(_func, 100)
strcpy(log_entry->msg, buffer)
#define TEST_ASSERT(cond)
Common initialisation for acutest binaries.
#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_t const * fr_dict_internal(void)
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.
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.
void fr_pair_list_init(fr_pair_list_t *list)
Initialise a pair list header.
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.
#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 void pair_list_init(TALLOC_CTX *ctx, fr_pair_t ***out, fr_dict_t const *dict, char const *pairs, int const perc, int const reps)
static void do_test_fr_pair_find_by_da(unsigned int len, unsigned int perc, unsigned int reps, fr_pair_t *source_vps[])
static fr_dict_t * test_dict
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_STR(_start)
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)
#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_next(fr_pair_list_t const *list, fr_pair_t const *item))
Get the next item in a valuepair list after a specific entry.
fr_pair_t * fr_pair_remove(fr_pair_list_t *list, fr_pair_t *vp)
Remove fr_pair_t from a list without freeing.
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.
#define PAIR_VERIFY_WITH_LIST(_l, _x)
fr_pair_t * fr_pair_list_head(fr_pair_list_t const *list)
Get the head of a valuepair 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