31#define USE_CONSTRUCTOR
40#define TEST_INIT pair_list_perf_init()
43#include <freeradius-devel/util/acutest.h>
49#include <freeradius-devel/util/dict_test.h>
50#include <freeradius-devel/server/base.h>
58static char const *test_attrs_0 = \
59 "Test-String-# = \"hello\","
60 "Test-Octets-# = 0x0102030405060708,"
61 "Test-IPv4-Addr-# = 192.168.1.1,"
62 "Test-IPv4-Prefix-# = 192.168/16,"
63 "Test-IPv6-Addr-# = fd12:3456:789a:1::1,"
64 "Test-IPv6-Prefix-# = fd12:3456:789a:1::/64,"
65 "Test-Ethernet-# = 11:22:33:44:55:66,"
67 "Test-Uint16-# = 65535,"
68 "Test-Uint32-# = 4294967295,"
69 "Test-Uint64-# = 18446744073709551615,"
71 "Test-Int16-# = -4573,"
72 "Test-Int32-# = 45645,"
73 "Test-Int64-# = 85645,"
74 "Test-Float32-# = 1.134,"
75 "Test-Float64-# = 1.1345,"
76 "Test-Date-# += \"Jan 1 2020 00:00:00 UTC\","
77 "Test-TLV-#.String = \"nested\","
78 "Test-Struct-#.uint32 = 1234";
80static char const *test_attrs_25 = \
81 "Test-String-# += \"hello\","
82 "Test-String-# += \"goodbye\","
83 "Test-String-# += \"hola\","
84 "Test-String-# += \"hasta pronto\","
85 "Test-String-# += \"bonjour\","
86 "Test-Octets-# += 0x0102030405060708,"
87 "Test-IPv4-Addr-# = 192.168.1.1,"
88 "Test-IPv4-Prefix-# = 192.168/16,"
89 "Test-IPv6-Addr-# = fd12:3456:789a:1::1,"
90 "Test-IPv6-Prefix-# = fd12:3456:789a:1::/64,"
91 "Test-Ethernet-# = 11:22:33:44:55:66,"
93 "Test-Uint16-# = 65535,"
94 "Test-Uint32-# = 4294967295,"
95 "Test-Uint64-# = 18446744073709551615,"
96 "Test-Int64-# = 85645,"
97 "Test-Float32-# = 1.134,"
98 "Test-Date-# += \"Jan 1 2020 00:00:00 UTC\","
99 "Test-TLV-#.String = \"nested\","
100 "Test-Struct-#.uint32 = 1234";
102static char const *test_attrs_50 = \
103 "Test-String-# += \"hello\","
104 "Test-String-# += \"goodbye\","
105 "Test-String-# += \"hola\","
106 "Test-String-# += \"hasta pronto\","
107 "Test-String-# += \"bonjour\","
108 "Test-String-# += \"au revoir\","
109 "Test-String-# += \"halo\","
110 "Test-String-# += \"kwaheri\","
111 "Test-String-# += \"ciao\","
112 "Test-String-# += \"arrivederci\","
113 "Test-IPv4-Addr-# = 192.168.1.1,"
114 "Test-IPv4-Prefix-# = 192.168/16,"
115 "Test-IPv6-Addr-# = fd12:3456:789a:1::1,"
116 "Test-IPv6-Prefix-# = fd12:3456:789a:1::/64,"
117 "Test-Ethernet-# = 11:22:33:44:55:66,"
118 "Test-Uint8-# = 255,"
119 "Test-Int64-# = 85645,"
120 "Test-Date-# += \"Jan 1 2020 00:00:00 UTC\","
121 "Test-TLV-#.String = \"nested\","
122 "Test-Struct-#.uint32 = 1234";
124static char const *test_attrs_75 = \
125 "Test-String-# += \"hello\","
126 "Test-String-# += \"goodbye\","
127 "Test-String-# += \"hola\","
128 "Test-String-# += \"hasta pronto\","
129 "Test-String-# += \"bonjour\","
130 "Test-String-# += \"au revoir\","
131 "Test-String-# += \"halo\","
132 "Test-String-# += \"kwaheri\","
133 "Test-String-# += \"ciao\","
134 "Test-String-# += \"arrivederci\","
135 "Test-String-# += \"halo\","
136 "Test-String-# += \"selamat tinggal\","
137 "Test-String-# += \"你好\","
138 "Test-String-# += \"再见\","
139 "Test-String-# += \"Привет\","
140 "Test-Uint8-# = 255,"
141 "Test-Int64-# = 85645,"
142 "Test-Date-# += \"Jan 1 2020 00:00:00 UTC\","
143 "Test-TLV-#.String = \"nested\","
144 "Test-Struct-#.uint32 = 1234";
146static char const *test_attrs_100 = \
147 "Test-String-# += \"hello\","
148 "Test-String-# += \"goodbye\","
149 "Test-String-# += \"hola\","
150 "Test-String-# += \"hasta pronto\","
151 "Test-String-# += \"bonjour\","
152 "Test-String-# += \"au revoir\","
153 "Test-String-# += \"halo\","
154 "Test-String-# += \"kwaheri\","
155 "Test-String-# += \"ciao\","
156 "Test-String-# += \"arrivederci\","
157 "Test-String-# += \"halo\","
158 "Test-String-# += \"selamat tinggal\","
159 "Test-String-# += \"你好\","
160 "Test-String-# += \"再见\","
161 "Test-String-# += \"Привет\","
162 "Test-String-# += \"до свидания\","
163 "Test-String-# += \"вся слава советской россии\","
164 "Test-String-# += \"у нас есть видео с мочой\","
165 "Test-String-# += \"Байден заплатит за\","
166 "Test-String-# += \"приставание к бурундукам\"";
174static void pair_list_init(TALLOC_CTX *ctx,
fr_pair_t ***
out,
fr_dict_t const *dict,
char const *pairs,
175 int const perc,
int const reps)
178 char *prep_pairs, *p;
190 prep_pairs = talloc_array(NULL,
char, strlen(pairs) + 1);
197 for (i = 0; i < reps; i++) {
207 strcpy(prep_pairs, pairs);
209 while ((p = strchr(p,
'#'))) {
213 if (slen <= 0)
fr_perror(
"pair_list_perf_tests");
218 if ((i == 0) && (perc > 0) && (reps > 0)) {
227 for (j = 0; j < (
size_t)(input_count * perc / 100); j++) {
319 size_t input_count = talloc_array_length(source_vps);
330 if (input_count > len) input_count = len;
335 for (i = 0; i < reps; i++) {
336 for (j = 0; j < len; j++) {
362 size_t input_count = talloc_array_length(source_vps);
366 if (input_count > len) input_count = len;
373 for (i = 0; i < len; i++) {
382 for (i = 0; i < reps; i++) {
383 for (j = 0; j < len; j++) {
385 da = source_vps[idx]->
da;
403 unsigned int i, j, nth_item;
408 size_t input_count = talloc_array_length(source_vps);
412 if (input_count > len) input_count = len;
419 for (i = 0; i < len; i++) {
429 nth_item = perc == 0 ? 1 : (
unsigned int)(len * perc / 100);
430 for (i = 0; i < reps; i++) {
431 for (j = 0; j < len; j++) {
434 da = source_vps[idx]->
da;
456 size_t input_count = talloc_array_length(source_vps);
460 if (input_count > len) input_count = len;
464 for (i = 0; i < reps; i++) {
465 for (j = 0; j < len; j++) {
483#define test_func(_func, _count, _perc, _source_vps) \
484static void test_ ## _func ## _ ## _count ## _ ## _perc(void)\
486 do_test_ ## _func(_count, _perc, 10000, _source_vps);\
489#define test_funcs(_func, _perc) \
490 test_func(_func, 20, _perc, source_vps_ ## _perc) \
491 test_func(_func, 40, _perc, source_vps_ ## _perc) \
492 test_func(_func, 60, _perc, source_vps_ ## _perc) \
493 test_func(_func, 80, _perc, source_vps_ ## _perc) \
494 test_func(_func, 100, _perc, source_vps_ ## _perc)
496#define all_test_funcs(_func) \
497 test_funcs(_func, 0) \
498 test_funcs(_func, 25) \
499 test_funcs(_func, 50) \
500 test_funcs(_func, 75) \
501 test_funcs(_func, 100)
508#define repetition_tests(_func, _perc) \
509 { #_func "_20_" #_perc, test_ ## _func ## _20_ ## _perc},\
510 { #_func "_40_" #_perc, test_ ## _func ## _40_ ## _perc},\
511 { #_func "_60_" #_perc, test_ ## _func ## _60_ ## _perc},\
512 { #_func "_80_" #_perc, test_ ## _func ## _80_ ## _perc},\
513 { #_func "_100_" #_perc, test_ ## _func ## _100_ ## _perc},\
515#define all_repetition_tests(_func) \
516 repetition_tests(_func, 0) \
517 repetition_tests(_func, 25) \
518 repetition_tests(_func, 50) \
519 repetition_tests(_func, 75) \
520 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.
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.
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_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.
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