Replaced custom linpools in tests for the common tmp_linpool
This commit is contained in:
parent
48bf1322aa
commit
d814a8cb93
6 changed files with 63 additions and 95 deletions
|
@ -46,9 +46,7 @@ run_function(const void *arg)
|
||||||
if (t->cmp)
|
if (t->cmp)
|
||||||
return t->result == f_same(t->fn, t->cmp);
|
return t->result == f_same(t->fn, t->cmp);
|
||||||
|
|
||||||
linpool *tmp = lp_new_default(&root_pool);
|
enum filter_return fret = f_eval(t->fn, tmp_linpool, NULL);
|
||||||
enum filter_return fret = f_eval(t->fn, tmp, NULL);
|
|
||||||
rfree(tmp);
|
|
||||||
|
|
||||||
return (fret < F_REJECT);
|
return (fret < F_REJECT);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,10 +19,7 @@ static void
|
||||||
start_conf_env(void)
|
start_conf_env(void)
|
||||||
{
|
{
|
||||||
bt_bird_init();
|
bt_bird_init();
|
||||||
|
cfg_mem = tmp_linpool;
|
||||||
pool *p = rp_new(&root_pool, "helper_pool");
|
|
||||||
linpool *l = lp_new_default(p);
|
|
||||||
cfg_mem = l;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct f_tree *
|
static struct f_tree *
|
||||||
|
|
|
@ -249,14 +249,14 @@ get_outer_net(net_addr *net, const struct f_prefix *src)
|
||||||
}
|
}
|
||||||
|
|
||||||
static list *
|
static list *
|
||||||
make_random_prefix_list(linpool *lp, int num, int v6, int tight)
|
make_random_prefix_list(int num, int v6, int tight)
|
||||||
{
|
{
|
||||||
list *prefixes = lp_allocz(lp, sizeof(struct f_prefix_node));
|
list *prefixes = lp_allocz(tmp_linpool, sizeof(struct f_prefix_node));
|
||||||
init_list(prefixes);
|
init_list(prefixes);
|
||||||
|
|
||||||
for (int i = 0; i < num; i++)
|
for (int i = 0; i < num; i++)
|
||||||
{
|
{
|
||||||
struct f_prefix_node *px = lp_allocz(lp, sizeof(struct f_prefix_node));
|
struct f_prefix_node *px = lp_allocz(tmp_linpool, sizeof(struct f_prefix_node));
|
||||||
get_random_prefix(&px->prefix, v6, tight);
|
get_random_prefix(&px->prefix, v6, tight);
|
||||||
add_tail(prefixes, &px->n);
|
add_tail(prefixes, &px->n);
|
||||||
|
|
||||||
|
@ -269,9 +269,9 @@ make_random_prefix_list(linpool *lp, int num, int v6, int tight)
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct f_trie *
|
static struct f_trie *
|
||||||
make_trie_from_prefix_list(linpool *lp, list *prefixes)
|
make_trie_from_prefix_list(list *prefixes)
|
||||||
{
|
{
|
||||||
struct f_trie *trie = f_new_trie(lp, 0);
|
struct f_trie *trie = f_new_trie(tmp_linpool, 0);
|
||||||
|
|
||||||
struct f_prefix_node *n;
|
struct f_prefix_node *n;
|
||||||
WALK_LIST(n, *prefixes)
|
WALK_LIST(n, *prefixes)
|
||||||
|
@ -286,7 +286,7 @@ make_trie_from_prefix_list(linpool *lp, list *prefixes)
|
||||||
* Arg @plus means prefix should include all longer ones.
|
* Arg @plus means prefix should include all longer ones.
|
||||||
*/
|
*/
|
||||||
static list *
|
static list *
|
||||||
read_prefix_list(linpool *lp, FILE *f, int v6, int plus)
|
read_prefix_list(FILE *f, int v6, int plus)
|
||||||
{
|
{
|
||||||
ASSERT(!v6);
|
ASSERT(!v6);
|
||||||
|
|
||||||
|
@ -294,7 +294,7 @@ read_prefix_list(linpool *lp, FILE *f, int v6, int plus)
|
||||||
char s[32];
|
char s[32];
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
list *pxlist = lp_allocz(lp, sizeof(struct f_prefix_node));
|
list *pxlist = lp_allocz(tmp_linpool, sizeof(struct f_prefix_node));
|
||||||
init_list(pxlist);
|
init_list(pxlist);
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
@ -308,7 +308,7 @@ read_prefix_list(linpool *lp, FILE *f, int v6, int plus)
|
||||||
if (n != 5)
|
if (n != 5)
|
||||||
bt_abort_msg("Invalid content of trie_data");
|
bt_abort_msg("Invalid content of trie_data");
|
||||||
|
|
||||||
struct f_prefix_node *px = lp_allocz(lp, sizeof(struct f_prefix_node));
|
struct f_prefix_node *px = lp_allocz(tmp_linpool, sizeof(struct f_prefix_node));
|
||||||
net_fill_ip4(&px->prefix.net, ip4_build(a0, a1, a2, a3), pl);
|
net_fill_ip4(&px->prefix.net, ip4_build(a0, a1, a2, a3), pl);
|
||||||
px->prefix.lo = pl;
|
px->prefix.lo = pl;
|
||||||
px->prefix.hi = plus ? IP4_MAX_PREFIX_LENGTH : pl;
|
px->prefix.hi = plus ? IP4_MAX_PREFIX_LENGTH : pl;
|
||||||
|
@ -331,7 +331,6 @@ read_prefix_list(linpool *lp, FILE *f, int v6, int plus)
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
read_prefix_file(const char *filename, int plus,
|
read_prefix_file(const char *filename, int plus,
|
||||||
linpool *lp0, linpool *lp1,
|
|
||||||
list *data[], struct f_trie *trie[])
|
list *data[], struct f_trie *trie[])
|
||||||
{
|
{
|
||||||
FILE *f = fopen(filename, "r");
|
FILE *f = fopen(filename, "r");
|
||||||
|
@ -339,10 +338,10 @@ read_prefix_file(const char *filename, int plus,
|
||||||
|
|
||||||
int n = 0;
|
int n = 0;
|
||||||
list *pxlist;
|
list *pxlist;
|
||||||
while (pxlist = read_prefix_list(lp0, f, 0, plus))
|
while (pxlist = read_prefix_list(f, 0, plus))
|
||||||
{
|
{
|
||||||
data[n] = pxlist;
|
data[n] = pxlist;
|
||||||
trie[n] = make_trie_from_prefix_list(lp1, pxlist);
|
trie[n] = make_trie_from_prefix_list(pxlist);
|
||||||
bt_debug("NEXT\n");
|
bt_debug("NEXT\n");
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
|
@ -437,11 +436,10 @@ t_match_random_net(void)
|
||||||
bt_config_parse(BT_CONFIG_SIMPLE);
|
bt_config_parse(BT_CONFIG_SIMPLE);
|
||||||
|
|
||||||
int v6 = 0;
|
int v6 = 0;
|
||||||
linpool *lp = lp_new_default(&root_pool);
|
|
||||||
for (int round = 0; round < TESTS_NUM; round++)
|
for (int round = 0; round < TESTS_NUM; round++)
|
||||||
{
|
{
|
||||||
list *prefixes = make_random_prefix_list(lp, PREFIXES_NUM, v6, 0);
|
list *prefixes = make_random_prefix_list(PREFIXES_NUM, v6, 0);
|
||||||
struct f_trie *trie = make_trie_from_prefix_list(lp, prefixes);
|
struct f_trie *trie = make_trie_from_prefix_list(prefixes);
|
||||||
|
|
||||||
for (int i = 0; i < PREFIX_TESTS_NUM; i++)
|
for (int i = 0; i < PREFIX_TESTS_NUM; i++)
|
||||||
{
|
{
|
||||||
|
@ -451,7 +449,7 @@ t_match_random_net(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
v6 = !v6;
|
v6 = !v6;
|
||||||
lp_flush(lp);
|
tmp_flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
bt_bird_cleanup();
|
bt_bird_cleanup();
|
||||||
|
@ -465,11 +463,10 @@ t_match_inner_net(void)
|
||||||
bt_config_parse(BT_CONFIG_SIMPLE);
|
bt_config_parse(BT_CONFIG_SIMPLE);
|
||||||
|
|
||||||
int v6 = 0;
|
int v6 = 0;
|
||||||
linpool *lp = lp_new_default(&root_pool);
|
|
||||||
for (int round = 0; round < TESTS_NUM; round++)
|
for (int round = 0; round < TESTS_NUM; round++)
|
||||||
{
|
{
|
||||||
list *prefixes = make_random_prefix_list(lp, PREFIXES_NUM, v6, 0);
|
list *prefixes = make_random_prefix_list(PREFIXES_NUM, v6, 0);
|
||||||
struct f_trie *trie = make_trie_from_prefix_list(lp, prefixes);
|
struct f_trie *trie = make_trie_from_prefix_list(prefixes);
|
||||||
|
|
||||||
struct f_prefix_node *n = HEAD(*prefixes);
|
struct f_prefix_node *n = HEAD(*prefixes);
|
||||||
for (int i = 0; i < PREFIX_TESTS_NUM; i++)
|
for (int i = 0; i < PREFIX_TESTS_NUM; i++)
|
||||||
|
@ -482,7 +479,7 @@ t_match_inner_net(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
v6 = !v6;
|
v6 = !v6;
|
||||||
lp_flush(lp);
|
tmp_flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
bt_bird_cleanup();
|
bt_bird_cleanup();
|
||||||
|
@ -496,11 +493,10 @@ t_match_outer_net(void)
|
||||||
bt_config_parse(BT_CONFIG_SIMPLE);
|
bt_config_parse(BT_CONFIG_SIMPLE);
|
||||||
|
|
||||||
int v6 = 0;
|
int v6 = 0;
|
||||||
linpool *lp = lp_new_default(&root_pool);
|
|
||||||
for (int round = 0; round < TESTS_NUM; round++)
|
for (int round = 0; round < TESTS_NUM; round++)
|
||||||
{
|
{
|
||||||
list *prefixes = make_random_prefix_list(lp, PREFIXES_NUM, v6, 0);
|
list *prefixes = make_random_prefix_list(PREFIXES_NUM, v6, 0);
|
||||||
struct f_trie *trie = make_trie_from_prefix_list(lp, prefixes);
|
struct f_trie *trie = make_trie_from_prefix_list(prefixes);
|
||||||
|
|
||||||
struct f_prefix_node *n = HEAD(*prefixes);
|
struct f_prefix_node *n = HEAD(*prefixes);
|
||||||
for (int i = 0; i < PREFIX_TESTS_NUM; i++)
|
for (int i = 0; i < PREFIX_TESTS_NUM; i++)
|
||||||
|
@ -513,7 +509,7 @@ t_match_outer_net(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
v6 = !v6;
|
v6 = !v6;
|
||||||
lp_flush(lp);
|
tmp_flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
v6 = !v6;
|
v6 = !v6;
|
||||||
|
@ -531,24 +527,22 @@ static int
|
||||||
benchmark_trie_dataset(const char *filename, int plus)
|
benchmark_trie_dataset(const char *filename, int plus)
|
||||||
{
|
{
|
||||||
int n = 0;
|
int n = 0;
|
||||||
linpool *lp0 = lp_new_default(&root_pool);
|
|
||||||
linpool *lp1 = lp_new_default(&root_pool);
|
|
||||||
list *data[TRIE_BUFFER_SIZE];
|
list *data[TRIE_BUFFER_SIZE];
|
||||||
struct f_trie *trie[TRIE_BUFFER_SIZE];
|
struct f_trie *trie[TRIE_BUFFER_SIZE];
|
||||||
net_addr *nets;
|
net_addr *nets;
|
||||||
|
|
||||||
bt_reset_suite_case_timer();
|
bt_reset_suite_case_timer();
|
||||||
bt_log_suite_case_result(1, "Reading %s", filename, n);
|
bt_log_suite_case_result(1, "Reading %s", filename, n);
|
||||||
n = read_prefix_file(filename, plus, lp0, lp1, data, trie);
|
n = read_prefix_file(filename, plus, data, trie);
|
||||||
bt_log_suite_case_result(1, "Read prefix data, %d lists, ", n);
|
bt_log_suite_case_result(1, "Read prefix data, %d lists, ", n);
|
||||||
|
|
||||||
size_t trie_size = rmemsize(lp1).effective * 1000 / (1024*1024);
|
size_t trie_size = rmemsize(tmp_linpool).effective * 1000 / (1024*1024);
|
||||||
bt_log_suite_case_result(1, "Trie size %u.%03u MB",
|
bt_log_suite_case_result(1, "Trie size %u.%03u MB",
|
||||||
(uint) (trie_size / 1000), (uint) (trie_size % 1000));
|
(uint) (trie_size / 1000), (uint) (trie_size % 1000));
|
||||||
|
|
||||||
int t = PREFIX_BENCH_NUM / n;
|
int t = PREFIX_BENCH_NUM / n;
|
||||||
int tb = MIN(t, TEST_BUFFER_SIZE);
|
int tb = MIN(t, TEST_BUFFER_SIZE);
|
||||||
nets = lp_alloc(lp0, tb * sizeof(net_addr));
|
nets = tmp_alloc(tb * sizeof(net_addr));
|
||||||
|
|
||||||
if (!plus)
|
if (!plus)
|
||||||
select_random_prefix_subset(data, nets, n, tb);
|
select_random_prefix_subset(data, nets, n, tb);
|
||||||
|
@ -573,9 +567,7 @@ benchmark_trie_dataset(const char *filename, int plus)
|
||||||
|
|
||||||
bt_log_suite_case_result(1, "Matching done, %d / %d matches", match, t * n);
|
bt_log_suite_case_result(1, "Matching done, %d / %d matches", match, t * n);
|
||||||
|
|
||||||
rfree(lp0);
|
tmp_flush();
|
||||||
rfree(lp1);
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -621,12 +613,11 @@ t_trie_same(void)
|
||||||
bt_config_parse(BT_CONFIG_SIMPLE);
|
bt_config_parse(BT_CONFIG_SIMPLE);
|
||||||
|
|
||||||
int v6 = 0;
|
int v6 = 0;
|
||||||
linpool *lp = lp_new_default(&root_pool);
|
|
||||||
for (int round = 0; round < TESTS_NUM*4; round++)
|
for (int round = 0; round < TESTS_NUM*4; round++)
|
||||||
{
|
{
|
||||||
list *prefixes = make_random_prefix_list(lp, 100 * PREFIXES_NUM, v6, 0);
|
list *prefixes = make_random_prefix_list(100 * PREFIXES_NUM, v6, 0);
|
||||||
struct f_trie *trie1 = f_new_trie(lp, 0);
|
struct f_trie *trie1 = f_new_trie(tmp_linpool, 0);
|
||||||
struct f_trie *trie2 = f_new_trie(lp, 0);
|
struct f_trie *trie2 = f_new_trie(tmp_linpool, 0);
|
||||||
|
|
||||||
struct f_prefix_node *n;
|
struct f_prefix_node *n;
|
||||||
WALK_LIST(n, *prefixes)
|
WALK_LIST(n, *prefixes)
|
||||||
|
@ -638,7 +629,7 @@ t_trie_same(void)
|
||||||
bt_assert(trie_same(trie1, trie2));
|
bt_assert(trie_same(trie1, trie2));
|
||||||
|
|
||||||
v6 = !v6;
|
v6 = !v6;
|
||||||
lp_flush(lp);
|
tmp_flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
bt_bird_cleanup();
|
bt_bird_cleanup();
|
||||||
|
@ -664,15 +655,14 @@ t_trie_walk(void)
|
||||||
bt_bird_init();
|
bt_bird_init();
|
||||||
bt_config_parse(BT_CONFIG_SIMPLE);
|
bt_config_parse(BT_CONFIG_SIMPLE);
|
||||||
|
|
||||||
linpool *lp = lp_new_default(&root_pool);
|
|
||||||
for (int round = 0; round < TESTS_NUM*8; round++)
|
for (int round = 0; round < TESTS_NUM*8; round++)
|
||||||
{
|
{
|
||||||
int level = round / TESTS_NUM;
|
int level = round / TESTS_NUM;
|
||||||
int v6 = level % 2;
|
int v6 = level % 2;
|
||||||
int num = PREFIXES_NUM * (int[]){1, 10, 100, 1000}[level / 2];
|
int num = PREFIXES_NUM * (int[]){1, 10, 100, 1000}[level / 2];
|
||||||
int pos = 0, end = 0;
|
int pos = 0, end = 0;
|
||||||
list *prefixes = make_random_prefix_list(lp, num, v6, 1);
|
list *prefixes = make_random_prefix_list(num, v6, 1);
|
||||||
struct f_trie *trie = make_trie_from_prefix_list(lp, prefixes);
|
struct f_trie *trie = make_trie_from_prefix_list(prefixes);
|
||||||
struct f_prefix *pxset = malloc((num + 1) * sizeof(struct f_prefix));
|
struct f_prefix *pxset = malloc((num + 1) * sizeof(struct f_prefix));
|
||||||
|
|
||||||
struct f_prefix_node *n;
|
struct f_prefix_node *n;
|
||||||
|
@ -770,7 +760,7 @@ t_trie_walk(void)
|
||||||
bt_assert((pos == num) || !net_in_netX(&pxset[pos].net, &from.net));
|
bt_assert((pos == num) || !net_in_netX(&pxset[pos].net, &from.net));
|
||||||
bt_debug("Subnet walk done for %s (found %d nets)\n", buf0, pos - p0);
|
bt_debug("Subnet walk done for %s (found %d nets)\n", buf0, pos - p0);
|
||||||
|
|
||||||
lp_flush(lp);
|
tmp_flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
bt_bird_cleanup();
|
bt_bird_cleanup();
|
||||||
|
@ -815,7 +805,6 @@ t_trie_walk_to_root(void)
|
||||||
bt_bird_init();
|
bt_bird_init();
|
||||||
bt_config_parse(BT_CONFIG_SIMPLE);
|
bt_config_parse(BT_CONFIG_SIMPLE);
|
||||||
|
|
||||||
linpool *lp = lp_new_default(&root_pool);
|
|
||||||
for (int round = 0; round < TESTS_NUM * 4; round++)
|
for (int round = 0; round < TESTS_NUM * 4; round++)
|
||||||
{
|
{
|
||||||
int level = round / TESTS_NUM;
|
int level = round / TESTS_NUM;
|
||||||
|
@ -824,8 +813,8 @@ t_trie_walk_to_root(void)
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
int st = 0, sn = 0, sm = 0;
|
int st = 0, sn = 0, sm = 0;
|
||||||
|
|
||||||
list *prefixes = make_random_prefix_list(lp, num, v6, 1);
|
list *prefixes = make_random_prefix_list(num, v6, 1);
|
||||||
struct f_trie *trie = make_trie_from_prefix_list(lp, prefixes);
|
struct f_trie *trie = make_trie_from_prefix_list(prefixes);
|
||||||
struct f_prefix *pxset = malloc((num + 1) * sizeof(struct f_prefix));
|
struct f_prefix *pxset = malloc((num + 1) * sizeof(struct f_prefix));
|
||||||
|
|
||||||
struct f_prefix_node *pxn;
|
struct f_prefix_node *pxn;
|
||||||
|
@ -884,7 +873,7 @@ t_trie_walk_to_root(void)
|
||||||
|
|
||||||
bt_debug("Success in %d / %d, sum %d, max %d\n", sn, i, st, sm);
|
bt_debug("Success in %d / %d, sum %d, max %d\n", sn, i, st, sm);
|
||||||
|
|
||||||
lp_flush(lp);
|
tmp_flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
bt_bird_cleanup();
|
bt_bird_cleanup();
|
||||||
|
|
|
@ -449,7 +449,6 @@ t_builder4(void)
|
||||||
resource_init();
|
resource_init();
|
||||||
|
|
||||||
struct flow_builder *fb = flow_builder_init(&root_pool);
|
struct flow_builder *fb = flow_builder_init(&root_pool);
|
||||||
linpool *lp = lp_new_default(&root_pool);
|
|
||||||
|
|
||||||
/* Expectation */
|
/* Expectation */
|
||||||
|
|
||||||
|
@ -492,7 +491,7 @@ t_builder4(void)
|
||||||
flow_builder_set_type(fb, FLOW_TYPE_TCP_FLAGS);
|
flow_builder_set_type(fb, FLOW_TYPE_TCP_FLAGS);
|
||||||
flow_builder_add_op_val(fb, 0, 0x55);
|
flow_builder_add_op_val(fb, 0, 0x55);
|
||||||
|
|
||||||
net_addr_flow4 *res = flow_builder4_finalize(fb, lp);
|
net_addr_flow4 *res = flow_builder4_finalize(fb, tmp_linpool);
|
||||||
|
|
||||||
bt_assert(memcmp(res, expect, expect->length) == 0);
|
bt_assert(memcmp(res, expect, expect->length) == 0);
|
||||||
|
|
||||||
|
@ -530,7 +529,6 @@ t_builder6(void)
|
||||||
net_addr_ip6 ip;
|
net_addr_ip6 ip;
|
||||||
|
|
||||||
resource_init();
|
resource_init();
|
||||||
linpool *lp = lp_new_default(&root_pool);
|
|
||||||
struct flow_builder *fb = flow_builder_init(&root_pool);
|
struct flow_builder *fb = flow_builder_init(&root_pool);
|
||||||
fb->ipv6 = 1;
|
fb->ipv6 = 1;
|
||||||
|
|
||||||
|
@ -574,7 +572,7 @@ t_builder6(void)
|
||||||
flow_builder_set_type(fb, FLOW_TYPE_LABEL);
|
flow_builder_set_type(fb, FLOW_TYPE_LABEL);
|
||||||
flow_builder_add_op_val(fb, 0, 0x55);
|
flow_builder_add_op_val(fb, 0, 0x55);
|
||||||
|
|
||||||
net_addr_flow6 *res = flow_builder6_finalize(fb, lp);
|
net_addr_flow6 *res = flow_builder6_finalize(fb, tmp_linpool);
|
||||||
bt_assert(memcmp(res, expect, expect->length) == 0);
|
bt_assert(memcmp(res, expect, expect->length) == 0);
|
||||||
|
|
||||||
/* Reverse order */
|
/* Reverse order */
|
||||||
|
@ -601,7 +599,7 @@ t_builder6(void)
|
||||||
flow_builder_set_type(fb, FLOW_TYPE_DST_PREFIX);
|
flow_builder_set_type(fb, FLOW_TYPE_DST_PREFIX);
|
||||||
flow_builder6_add_pfx(fb, &ip, 61);
|
flow_builder6_add_pfx(fb, &ip, 61);
|
||||||
|
|
||||||
res = flow_builder6_finalize(fb, lp);
|
res = flow_builder6_finalize(fb, tmp_linpool);
|
||||||
bt_assert(memcmp(res, expect, expect->length) == 0);
|
bt_assert(memcmp(res, expect, expect->length) == 0);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -32,14 +32,13 @@ t_as_path_match(void)
|
||||||
struct adata *as_path = &empty_as_path;
|
struct adata *as_path = &empty_as_path;
|
||||||
u32 first_prepended, last_prepended;
|
u32 first_prepended, last_prepended;
|
||||||
first_prepended = last_prepended = 0;
|
first_prepended = last_prepended = 0;
|
||||||
struct linpool *lp = lp_new_default(&root_pool);
|
|
||||||
|
|
||||||
struct f_path_mask *mask = alloca(sizeof(struct f_path_mask) + AS_PATH_LENGTH * sizeof(struct f_path_mask_item));
|
struct f_path_mask *mask = alloca(sizeof(struct f_path_mask) + AS_PATH_LENGTH * sizeof(struct f_path_mask_item));
|
||||||
mask->len = AS_PATH_LENGTH;
|
mask->len = AS_PATH_LENGTH;
|
||||||
for (int i = AS_PATH_LENGTH - 1; i >= 0; i--)
|
for (int i = AS_PATH_LENGTH - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
u32 val = bt_random();
|
u32 val = bt_random();
|
||||||
as_path = as_path_prepend(lp, as_path, val);
|
as_path = as_path_prepend(tmp_linpool, as_path, val);
|
||||||
bt_debug("Prepending ASN: %10u \n", val);
|
bt_debug("Prepending ASN: %10u \n", val);
|
||||||
|
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
|
@ -61,7 +60,7 @@ t_as_path_match(void)
|
||||||
bt_assert(as_path_get_last(as_path, &asn));
|
bt_assert(as_path_get_last(as_path, &asn));
|
||||||
bt_assert_msg(asn == first_prepended, "as_path_get_last() should return the first prepended ASN");
|
bt_assert_msg(asn == first_prepended, "as_path_get_last() should return the first prepended ASN");
|
||||||
|
|
||||||
rfree(lp);
|
tmp_flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -74,12 +73,11 @@ t_path_format(void)
|
||||||
|
|
||||||
struct adata empty_as_path = {};
|
struct adata empty_as_path = {};
|
||||||
struct adata *as_path = &empty_as_path;
|
struct adata *as_path = &empty_as_path;
|
||||||
struct linpool *lp = lp_new_default(&root_pool);
|
|
||||||
|
|
||||||
uint i;
|
uint i;
|
||||||
for (i = 4294967285; i <= 4294967294; i++)
|
for (i = 4294967285; i <= 4294967294; i++)
|
||||||
{
|
{
|
||||||
as_path = as_path_prepend(lp, as_path, i);
|
as_path = as_path_prepend(tmp_linpool, as_path, i);
|
||||||
bt_debug("Prepending ASN: %10u \n", i);
|
bt_debug("Prepending ASN: %10u \n", i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +95,7 @@ t_path_format(void)
|
||||||
as_path_format(as_path, buf2, SMALL_BUFFER_SIZE);
|
as_path_format(as_path, buf2, SMALL_BUFFER_SIZE);
|
||||||
bt_assert_msg(strcmp(buf2, "4294967294 42...") == 0, "Small Buffer(%zu): '%s'", strlen(buf2), buf2);
|
bt_assert_msg(strcmp(buf2, "4294967294 42...") == 0, "Small Buffer(%zu): '%s'", strlen(buf2), buf2);
|
||||||
|
|
||||||
rfree(lp);
|
tmp_flush();
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -120,7 +118,6 @@ t_path_include(void)
|
||||||
|
|
||||||
struct adata empty_as_path = {};
|
struct adata empty_as_path = {};
|
||||||
struct adata *as_path = &empty_as_path;
|
struct adata *as_path = &empty_as_path;
|
||||||
struct linpool *lp = lp_new_default(&root_pool);
|
|
||||||
|
|
||||||
u32 as_nums[AS_PATH_LENGTH] = {};
|
u32 as_nums[AS_PATH_LENGTH] = {};
|
||||||
int i;
|
int i;
|
||||||
|
@ -128,7 +125,7 @@ t_path_include(void)
|
||||||
{
|
{
|
||||||
u32 val = bt_random();
|
u32 val = bt_random();
|
||||||
as_nums[i] = val;
|
as_nums[i] = val;
|
||||||
as_path = as_path_prepend(lp, as_path, val);
|
as_path = as_path_prepend(tmp_linpool, as_path, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < AS_PATH_LENGTH; i++)
|
for (i = 0; i < AS_PATH_LENGTH; i++)
|
||||||
|
@ -136,8 +133,8 @@ t_path_include(void)
|
||||||
int counts_of_contains = count_asn_in_array(as_nums, as_nums[i]);
|
int counts_of_contains = count_asn_in_array(as_nums, as_nums[i]);
|
||||||
bt_assert_msg(as_path_contains(as_path, as_nums[i], counts_of_contains), "AS Path should contains %d-times number %d", counts_of_contains, as_nums[i]);
|
bt_assert_msg(as_path_contains(as_path, as_nums[i], counts_of_contains), "AS Path should contains %d-times number %d", counts_of_contains, as_nums[i]);
|
||||||
|
|
||||||
bt_assert(as_path_filter(lp, as_path, NULL, as_nums[i], 0) != NULL);
|
bt_assert(as_path_filter(tmp_linpool, as_path, NULL, as_nums[i], 0) != NULL);
|
||||||
bt_assert(as_path_filter(lp, as_path, NULL, as_nums[i], 1) != NULL);
|
bt_assert(as_path_filter(tmp_linpool, as_path, NULL, as_nums[i], 1) != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < 10000; i++)
|
for (i = 0; i < 10000; i++)
|
||||||
|
@ -152,7 +149,7 @@ t_path_include(void)
|
||||||
bt_assert_msg(result == 0, "As path should not contain the number %u", test_val);
|
bt_assert_msg(result == 0, "As path should not contain the number %u", test_val);
|
||||||
}
|
}
|
||||||
|
|
||||||
rfree(lp);
|
tmp_flush();
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -165,12 +162,11 @@ t_as_path_converting(void)
|
||||||
|
|
||||||
struct adata empty_as_path = {};
|
struct adata empty_as_path = {};
|
||||||
struct adata *as_path = &empty_as_path;
|
struct adata *as_path = &empty_as_path;
|
||||||
struct linpool *lp = lp_new_default(&root_pool);
|
|
||||||
#define AS_PATH_LENGTH_FOR_CONVERTING_TEST 10
|
#define AS_PATH_LENGTH_FOR_CONVERTING_TEST 10
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < AS_PATH_LENGTH_FOR_CONVERTING_TEST; i++)
|
for (i = 0; i < AS_PATH_LENGTH_FOR_CONVERTING_TEST; i++)
|
||||||
as_path = as_path_prepend(lp, as_path, i);
|
as_path = as_path_prepend(tmp_linpool, as_path, i);
|
||||||
|
|
||||||
bt_debug("data length: %u \n", as_path->length);
|
bt_debug("data length: %u \n", as_path->length);
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,6 @@ static byte buf[BUFFER_SIZE] = {};
|
||||||
|
|
||||||
#define SET_SIZE_FOR_FORMAT_OUTPUT 10
|
#define SET_SIZE_FOR_FORMAT_OUTPUT 10
|
||||||
|
|
||||||
struct linpool *lp;
|
|
||||||
|
|
||||||
enum set_type
|
enum set_type
|
||||||
{
|
{
|
||||||
SET_TYPE_INT,
|
SET_TYPE_INT,
|
||||||
|
@ -38,24 +36,23 @@ generate_set_sequence(enum set_type type, int len)
|
||||||
{
|
{
|
||||||
struct adata empty_as_path = {};
|
struct adata empty_as_path = {};
|
||||||
set_sequence = set_sequence_same = set_sequence_higher = set_random = &empty_as_path;
|
set_sequence = set_sequence_same = set_sequence_higher = set_random = &empty_as_path;
|
||||||
lp = lp_new_default(&root_pool);
|
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
if (type == SET_TYPE_INT)
|
if (type == SET_TYPE_INT)
|
||||||
{
|
{
|
||||||
set_sequence = int_set_add(lp, set_sequence, i);
|
set_sequence = int_set_add(tmp_linpool, set_sequence, i);
|
||||||
set_sequence_same = int_set_add(lp, set_sequence_same, i);
|
set_sequence_same = int_set_add(tmp_linpool, set_sequence_same, i);
|
||||||
set_sequence_higher = int_set_add(lp, set_sequence_higher, i + SET_SIZE);
|
set_sequence_higher = int_set_add(tmp_linpool, set_sequence_higher, i + SET_SIZE);
|
||||||
set_random = int_set_add(lp, set_random, bt_random());
|
set_random = int_set_add(tmp_linpool, set_random, bt_random());
|
||||||
}
|
}
|
||||||
else if (type == SET_TYPE_EC)
|
else if (type == SET_TYPE_EC)
|
||||||
{
|
{
|
||||||
set_sequence = ec_set_add(lp, set_sequence, i);
|
set_sequence = ec_set_add(tmp_linpool, set_sequence, i);
|
||||||
set_sequence_same = ec_set_add(lp, set_sequence_same, i);
|
set_sequence_same = ec_set_add(tmp_linpool, set_sequence_same, i);
|
||||||
set_sequence_higher = ec_set_add(lp, set_sequence_higher, i + SET_SIZE);
|
set_sequence_higher = ec_set_add(tmp_linpool, set_sequence_higher, i + SET_SIZE);
|
||||||
set_random = ec_set_add(lp, set_random, (bt_random() << 32 | bt_random()));
|
set_random = ec_set_add(tmp_linpool, set_random, (bt_random() << 32 | bt_random()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
bt_abort_msg("This should be unreachable");
|
bt_abort_msg("This should be unreachable");
|
||||||
|
@ -85,7 +82,6 @@ t_set_int_contains(void)
|
||||||
for (i = 0; i < SET_SIZE; i++)
|
for (i = 0; i < SET_SIZE; i++)
|
||||||
bt_assert_msg(data[i] == i, "(data[i] = %d) == i = %d)", data[i], i);
|
bt_assert_msg(data[i] == i, "(data[i] = %d) == i = %d)", data[i], i);
|
||||||
|
|
||||||
rfree(lp);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,15 +92,14 @@ t_set_int_union(void)
|
||||||
generate_set_sequence(SET_TYPE_INT, SET_SIZE);
|
generate_set_sequence(SET_TYPE_INT, SET_SIZE);
|
||||||
|
|
||||||
const struct adata *set_union;
|
const struct adata *set_union;
|
||||||
set_union = int_set_union(lp, set_sequence, set_sequence_same);
|
set_union = int_set_union(tmp_linpool, set_sequence, set_sequence_same);
|
||||||
bt_assert(int_set_get_size(set_union) == SET_SIZE);
|
bt_assert(int_set_get_size(set_union) == SET_SIZE);
|
||||||
bt_assert(int_set_format(set_union, 0, 2, buf, BUFFER_SIZE) == 0);
|
bt_assert(int_set_format(set_union, 0, 2, buf, BUFFER_SIZE) == 0);
|
||||||
|
|
||||||
set_union = int_set_union(lp, set_sequence, set_sequence_higher);
|
set_union = int_set_union(tmp_linpool, set_sequence, set_sequence_higher);
|
||||||
bt_assert_msg(int_set_get_size(set_union) == SET_SIZE*2, "int_set_get_size(set_union) %d, SET_SIZE*2 %d", int_set_get_size(set_union), SET_SIZE*2);
|
bt_assert_msg(int_set_get_size(set_union) == SET_SIZE*2, "int_set_get_size(set_union) %d, SET_SIZE*2 %d", int_set_get_size(set_union), SET_SIZE*2);
|
||||||
bt_assert(int_set_format(set_union, 0, 2, buf, BUFFER_SIZE) == 0);
|
bt_assert(int_set_format(set_union, 0, 2, buf, BUFFER_SIZE) == 0);
|
||||||
|
|
||||||
rfree(lp);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,7 +120,6 @@ t_set_int_format(void)
|
||||||
bt_assert(int_set_format(set_sequence, 1, 0, buf, BUFFER_SIZE) == 0);
|
bt_assert(int_set_format(set_sequence, 1, 0, buf, BUFFER_SIZE) == 0);
|
||||||
bt_assert(strcmp(buf, "(0,0) (0,1) (0,2) (0,3) (0,4) (0,5) (0,6) (0,7) (0,8) (0,9)") == 0);
|
bt_assert(strcmp(buf, "(0,0) (0,1) (0,2) (0,3) (0,4) (0,5) (0,6) (0,7) (0,8) (0,9)") == 0);
|
||||||
|
|
||||||
rfree(lp);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +133,7 @@ t_set_int_delete(void)
|
||||||
u32 i;
|
u32 i;
|
||||||
for (i = 0; i < SET_SIZE; i++)
|
for (i = 0; i < SET_SIZE; i++)
|
||||||
{
|
{
|
||||||
deleting_sequence = int_set_del(lp, deleting_sequence, i);
|
deleting_sequence = int_set_del(tmp_linpool, deleting_sequence, i);
|
||||||
bt_assert_msg(int_set_get_size(deleting_sequence) == (int) (SET_SIZE-1-i),
|
bt_assert_msg(int_set_get_size(deleting_sequence) == (int) (SET_SIZE-1-i),
|
||||||
"int_set_get_size(deleting_sequence) %d == SET_SIZE-1-i %d",
|
"int_set_get_size(deleting_sequence) %d == SET_SIZE-1-i %d",
|
||||||
int_set_get_size(deleting_sequence),
|
int_set_get_size(deleting_sequence),
|
||||||
|
@ -174,7 +168,6 @@ t_set_ec_contains(void)
|
||||||
// for (i = 0; i < SET_SIZE; i++)
|
// for (i = 0; i < SET_SIZE; i++)
|
||||||
// bt_assert_msg(data[i] == (SET_SIZE-1-i), "(data[i] = %d) == ((SET_SIZE-1-i) = %d)", data[i], SET_SIZE-1-i);
|
// bt_assert_msg(data[i] == (SET_SIZE-1-i), "(data[i] = %d) == ((SET_SIZE-1-i) = %d)", data[i], SET_SIZE-1-i);
|
||||||
|
|
||||||
rfree(lp);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,15 +178,14 @@ t_set_ec_union(void)
|
||||||
generate_set_sequence(SET_TYPE_EC, SET_SIZE);
|
generate_set_sequence(SET_TYPE_EC, SET_SIZE);
|
||||||
|
|
||||||
const struct adata *set_union;
|
const struct adata *set_union;
|
||||||
set_union = ec_set_union(lp, set_sequence, set_sequence_same);
|
set_union = ec_set_union(tmp_linpool, set_sequence, set_sequence_same);
|
||||||
bt_assert(ec_set_get_size(set_union) == SET_SIZE);
|
bt_assert(ec_set_get_size(set_union) == SET_SIZE);
|
||||||
bt_assert(ec_set_format(set_union, 0, buf, BUFFER_SIZE) == 0);
|
bt_assert(ec_set_format(set_union, 0, buf, BUFFER_SIZE) == 0);
|
||||||
|
|
||||||
set_union = ec_set_union(lp, set_sequence, set_sequence_higher);
|
set_union = ec_set_union(tmp_linpool, set_sequence, set_sequence_higher);
|
||||||
bt_assert_msg(ec_set_get_size(set_union) == SET_SIZE*2, "ec_set_get_size(set_union) %d, SET_SIZE*2 %d", ec_set_get_size(set_union), SET_SIZE*2);
|
bt_assert_msg(ec_set_get_size(set_union) == SET_SIZE*2, "ec_set_get_size(set_union) %d, SET_SIZE*2 %d", ec_set_get_size(set_union), SET_SIZE*2);
|
||||||
bt_assert(ec_set_format(set_union, 0, buf, BUFFER_SIZE) == 0);
|
bt_assert(ec_set_format(set_union, 0, buf, BUFFER_SIZE) == 0);
|
||||||
|
|
||||||
rfree(lp);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,18 +196,16 @@ t_set_ec_format(void)
|
||||||
|
|
||||||
const struct adata empty_as_path = {};
|
const struct adata empty_as_path = {};
|
||||||
set_sequence = set_sequence_same = set_sequence_higher = set_random = &empty_as_path;
|
set_sequence = set_sequence_same = set_sequence_higher = set_random = &empty_as_path;
|
||||||
lp = lp_new_default(&root_pool);
|
|
||||||
|
|
||||||
u64 i = 0;
|
u64 i = 0;
|
||||||
set_sequence = ec_set_add(lp, set_sequence, i);
|
set_sequence = ec_set_add(tmp_linpool, set_sequence, i);
|
||||||
for (i = 1; i < SET_SIZE_FOR_FORMAT_OUTPUT; i++)
|
for (i = 1; i < SET_SIZE_FOR_FORMAT_OUTPUT; i++)
|
||||||
set_sequence = ec_set_add(lp, set_sequence, i + ((i%2) ? ((u64)EC_RO << 48) : ((u64)EC_RT << 48)));
|
set_sequence = ec_set_add(tmp_linpool, set_sequence, i + ((i%2) ? ((u64)EC_RO << 48) : ((u64)EC_RT << 48)));
|
||||||
|
|
||||||
bt_assert(ec_set_format(set_sequence, 0, buf, BUFFER_SIZE) == 0);
|
bt_assert(ec_set_format(set_sequence, 0, buf, BUFFER_SIZE) == 0);
|
||||||
bt_assert_msg(strcmp(buf, "(unknown 0x0, 0, 0) (ro, 0, 1) (rt, 0, 2) (ro, 0, 3) (rt, 0, 4) (ro, 0, 5) (rt, 0, 6) (ro, 0, 7) (rt, 0, 8) (ro, 0, 9)") == 0,
|
bt_assert_msg(strcmp(buf, "(unknown 0x0, 0, 0) (ro, 0, 1) (rt, 0, 2) (ro, 0, 3) (rt, 0, 4) (ro, 0, 5) (rt, 0, 6) (ro, 0, 7) (rt, 0, 8) (ro, 0, 9)") == 0,
|
||||||
"ec_set_format() returns '%s'", buf);
|
"ec_set_format() returns '%s'", buf);
|
||||||
|
|
||||||
rfree(lp);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,7 +219,7 @@ t_set_ec_delete(void)
|
||||||
u32 i;
|
u32 i;
|
||||||
for (i = 0; i < SET_SIZE; i++)
|
for (i = 0; i < SET_SIZE; i++)
|
||||||
{
|
{
|
||||||
deleting_sequence = ec_set_del(lp, deleting_sequence, i);
|
deleting_sequence = ec_set_del(tmp_linpool, deleting_sequence, i);
|
||||||
bt_assert_msg(ec_set_get_size(deleting_sequence) == (int) (SET_SIZE-1-i),
|
bt_assert_msg(ec_set_get_size(deleting_sequence) == (int) (SET_SIZE-1-i),
|
||||||
"ec_set_get_size(deleting_sequence) %d == SET_SIZE-1-i %d",
|
"ec_set_get_size(deleting_sequence) %d == SET_SIZE-1-i %d",
|
||||||
ec_set_get_size(deleting_sequence), SET_SIZE-1-i);
|
ec_set_get_size(deleting_sequence), SET_SIZE-1-i);
|
||||||
|
|
Loading…
Reference in a new issue