26#define TEST_GLOBAL_INIT pair_list_perf_init()
34#include <freeradius-devel/util/dict_test.h>
35#include <freeradius-devel/server/base.h>
38#define TEST_MSG_STATS \
40 TEST_MSG_ALWAYS("\n"); \
41 TEST_MSG_ALWAYS("repetitions = %u", reps); \
42 TEST_MSG_ALWAYS("%% repeated = %u", perc); \
43 TEST_MSG_ALWAYS("list_length = %u", len); \
44 TEST_MSG_ALWAYS("elapsed (ns) = %" PRId64, fr_time_delta_unwrap(used)); \
45 TEST_MSG_ALWAYS("calls/s = %0.0lf", (reps * len)/(fr_time_delta_unwrap(used) / (double)NSEC)); \
46 TEST_MSG_ALWAYS("(ns) / call = %0.0lf", (double) fr_time_delta_unwrap(used) / (double) reps); \
56 "Test-String-# = \"hello\","
57 "Test-Octets-# = 0x0102030405060708,"
58 "Test-IPv4-Addr-# = 192.168.1.1,"
59 "Test-IPv4-Prefix-# = 192.168/16,"
60 "Test-IPv6-Addr-# = fd12:3456:789a:1::1,"
61 "Test-IPv6-Prefix-# = fd12:3456:789a:1::/64,"
62 "Test-Ethernet-# = 11:22:33:44:55:66,"
64 "Test-Uint16-# = 65535,"
65 "Test-Uint32-# = 4294967295,"
66 "Test-Uint64-# = 18446744073709551615,"
68 "Test-Int16-# = -4573,"
69 "Test-Int32-# = 45645,"
70 "Test-Int64-# = 85645,"
71 "Test-Float32-# = 1.134,"
72 "Test-Float64-# = 1.1345,"
73 "Test-Date-# += \"Jan 1 2020 00:00:00 UTC\","
74 "Test-TLV-#.String = \"nested\","
75 "Test-Struct-#.uint32 = 1234";
78 "Test-String-# += \"hello\","
79 "Test-String-# += \"goodbye\","
80 "Test-String-# += \"hola\","
81 "Test-String-# += \"hasta pronto\","
82 "Test-String-# += \"bonjour\","
83 "Test-Octets-# += 0x0102030405060708,"
84 "Test-IPv4-Addr-# = 192.168.1.1,"
85 "Test-IPv4-Prefix-# = 192.168/16,"
86 "Test-IPv6-Addr-# = fd12:3456:789a:1::1,"
87 "Test-IPv6-Prefix-# = fd12:3456:789a:1::/64,"
88 "Test-Ethernet-# = 11:22:33:44:55:66,"
90 "Test-Uint16-# = 65535,"
91 "Test-Uint32-# = 4294967295,"
92 "Test-Uint64-# = 18446744073709551615,"
93 "Test-Int64-# = 85645,"
94 "Test-Float32-# = 1.134,"
95 "Test-Date-# += \"Jan 1 2020 00:00:00 UTC\","
96 "Test-TLV-#.String = \"nested\","
97 "Test-Struct-#.uint32 = 1234";
100 "Test-String-# += \"hello\","
101 "Test-String-# += \"goodbye\","
102 "Test-String-# += \"hola\","
103 "Test-String-# += \"hasta pronto\","
104 "Test-String-# += \"bonjour\","
105 "Test-String-# += \"au revoir\","
106 "Test-String-# += \"halo\","
107 "Test-String-# += \"kwaheri\","
108 "Test-String-# += \"ciao\","
109 "Test-String-# += \"arrivederci\","
110 "Test-IPv4-Addr-# = 192.168.1.1,"
111 "Test-IPv4-Prefix-# = 192.168/16,"
112 "Test-IPv6-Addr-# = fd12:3456:789a:1::1,"
113 "Test-IPv6-Prefix-# = fd12:3456:789a:1::/64,"
114 "Test-Ethernet-# = 11:22:33:44:55:66,"
115 "Test-Uint8-# = 255,"
116 "Test-Int64-# = 85645,"
117 "Test-Date-# += \"Jan 1 2020 00:00:00 UTC\","
118 "Test-TLV-#.String = \"nested\","
119 "Test-Struct-#.uint32 = 1234";
122 "Test-String-# += \"hello\","
123 "Test-String-# += \"goodbye\","
124 "Test-String-# += \"hola\","
125 "Test-String-# += \"hasta pronto\","
126 "Test-String-# += \"bonjour\","
127 "Test-String-# += \"au revoir\","
128 "Test-String-# += \"halo\","
129 "Test-String-# += \"kwaheri\","
130 "Test-String-# += \"ciao\","
131 "Test-String-# += \"arrivederci\","
132 "Test-String-# += \"halo\","
133 "Test-String-# += \"selamat tinggal\","
134 "Test-String-# += \"你好\","
135 "Test-String-# += \"再见\","
136 "Test-String-# += \"Я люблю сир\","
137 "Test-Uint8-# = 255,"
138 "Test-Int64-# = 85645,"
139 "Test-Date-# += \"Jan 1 2020 00:00:00 UTC\","
140 "Test-TLV-#.String = \"nested\","
141 "Test-Struct-#.uint32 = 1234";
144 "Test-String-# += \"hello\","
145 "Test-String-# += \"goodbye\","
146 "Test-String-# += \"hola\","
147 "Test-String-# += \"hasta pronto\","
148 "Test-String-# += \"bonjour\","
149 "Test-String-# += \"au revoir\","
150 "Test-String-# += \"halo\","
151 "Test-String-# += \"kwaheri\","
152 "Test-String-# += \"ciao\","
153 "Test-String-# += \"arrivederci\","
154 "Test-String-# += \"halo\","
155 "Test-String-# += \"selamat tinggal\","
156 "Test-String-# += \"你好\","
157 "Test-String-# += \"再见\","
158 "Test-String-# += \"Я люблю сир\","
159 "Test-String-# += \"Найкращий сир - бринза\","
160 "Test-String-# += \"Сулугуні чудовий на грилі\","
161 "Test-String-# += \"Сирники з домашнього сиру\","
162 "Test-String-# += \"Карпатська бринза пахне гірськими травами\","
163 "Test-String-# += \"Вареники з сиром найсмачніші\"";
189 unsigned int cnt = 0;
216 int const perc,
int const reps)
219 char *prep_pairs, *p;
231 prep_pairs = talloc_array(NULL,
char, strlen(pairs) + 1);
238 for (i = 0; i < reps; i++) {
250 strcpy(prep_pairs, pairs);
252 while ((p = strchr(p,
'#'))) {
256 if (slen <= 0)
fr_perror(
"pair_list_perf_tests");
261 if ((i == 0) && (perc > 0) && (reps > 0)) {
269 for (j = 0; j < (
size_t)(input_count * perc / 100); j++) {
359 size_t input_count = talloc_array_length(source_vps);
370 if (input_count >
len) input_count =
len;
375 for (i = 0; i < reps; i++) {
376 for (j = 0; j <
len; j++) {
398 size_t input_count = talloc_array_length(source_vps);
402 if (input_count >
len) input_count =
len;
409 for (i = 0; i <
len; i++) {
418 for (i = 0; i < reps; i++) {
419 for (j = 0; j <
len; j++) {
421 da = source_vps[idx]->
da;
435 unsigned int i, j, nth_item;
440 size_t input_count = talloc_array_length(source_vps);
444 if (input_count >
len) input_count =
len;
451 for (i = 0; i <
len; i++) {
461 nth_item = perc == 0 ? 1 : (
unsigned int)(
len * perc / 100);
462 for (i = 0; i < reps; i++) {
463 for (j = 0; j <
len; j++) {
466 da = source_vps[idx]->
da;
484 size_t input_count = talloc_array_length(source_vps);
488 if (input_count >
len) input_count =
len;
492 for (i = 0; i < reps; i++) {
493 for (j = 0; j <
len; j++) {
507#define test_func(_func, _count, _perc, _source_vps) \
508static void test_ ## _func ## _ ## _count ## _ ## _perc(void)\
510 do_test_ ## _func(_count, _perc, 10000, _source_vps);\
513#define test_funcs(_func, _perc) \
514 test_func(_func, 20, _perc, source_vps_ ## _perc) \
515 test_func(_func, 40, _perc, source_vps_ ## _perc) \
516 test_func(_func, 60, _perc, source_vps_ ## _perc) \
517 test_func(_func, 80, _perc, source_vps_ ## _perc) \
518 test_func(_func, 100, _perc, source_vps_ ## _perc)
520#define all_test_funcs(_func) \
521 test_funcs(_func, 0) \
522 test_funcs(_func, 25) \
523 test_funcs(_func, 50) \
524 test_funcs(_func, 75) \
525 test_funcs(_func, 100)
532#define repetition_tests(_func, _perc) \
533 { #_func "_20_" #_perc, test_ ## _func ## _20_ ## _perc},\
534 { #_func "_40_" #_perc, test_ ## _func ## _40_ ## _perc},\
535 { #_func "_60_" #_perc, test_ ## _func ## _60_ ## _perc},\
536 { #_func "_80_" #_perc, test_ ## _func ## _80_ ## _perc},\
537 { #_func "_100_" #_perc, test_ ## _func ## _100_ ## _perc},\
539#define all_repetition_tests(_func) \
540 repetition_tests(_func, 0) \
541 repetition_tests(_func, 25) \
542 repetition_tests(_func, 50) \
543 repetition_tests(_func, 75) \
544 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.
static char const * test_attrs_75
static char const * test_attrs_100
static fr_pair_t ** source_vps_25
List with 25% duplicate attributes.
static fr_pair_t ** source_vps_100
List with 100% duplicate attributes, i.e. all the same.
static fr_pair_t ** source_vps_75
List with 75% duplicate attributes.
#define all_repetition_tests(_func)
static TALLOC_CTX * autofree
static char const * test_attrs_50
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 char const * test_attrs_0
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 char const * test_attrs_25
static fr_pair_t ** source_vps_0
List with zero duplicate attributes.
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 fr_pair_t ** source_vps_50
List with 50% duplicate attributes.
static void do_test_fr_pair_find_by_da(unsigned int len, unsigned int perc, unsigned int reps, fr_pair_t *source_vps[])
static int fr_pair_sublist_copy(TALLOC_CTX *ctx, fr_pair_list_t *to, fr_pair_list_t const *from, fr_pair_t const *start)
Duplicate a list of pairs starting at a particular item.
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 fr_sbuff_err_t char ** out
static fr_sbuff_err_t char size_t * len