Commit d814a8cb authored by Maria Matejka's avatar Maria Matejka
Browse files

Replaced custom linpools in tests for the common tmp_linpool

parent 48bf1322
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -46,9 +46,7 @@ run_function(const void *arg)
  if (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, NULL);
  rfree(tmp);
  enum filter_return fret = f_eval(t->fn, tmp_linpool, NULL);

  return (fret < F_REJECT);
}
+1 −4
Original line number Diff line number Diff line
@@ -19,10 +19,7 @@ static void
start_conf_env(void)
{
  bt_bird_init();

  pool *p = rp_new(&root_pool, "helper_pool");
  linpool *l = lp_new_default(p);
  cfg_mem = l;
  cfg_mem = tmp_linpool;
}

static struct f_tree *
+33 −44
Original line number Diff line number Diff line
@@ -249,14 +249,14 @@ get_outer_net(net_addr *net, const struct f_prefix *src)
}

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);

  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);
    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 *
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;
  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.
 */
static list *
read_prefix_list(linpool *lp, FILE *f, int v6, int plus)
read_prefix_list(FILE *f, int v6, int plus)
{
  ASSERT(!v6);

@@ -294,7 +294,7 @@ read_prefix_list(linpool *lp, FILE *f, int v6, int plus)
  char s[32];
  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);

  errno = 0;
@@ -308,7 +308,7 @@ read_prefix_list(linpool *lp, FILE *f, int v6, int plus)
    if (n != 5)
      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);
    px->prefix.lo = 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
read_prefix_file(const char *filename, int plus,
		 linpool *lp0, linpool *lp1,
		 list *data[], struct f_trie *trie[])
{
  FILE *f = fopen(filename, "r");
@@ -339,10 +338,10 @@ read_prefix_file(const char *filename, int plus,

  int n = 0;
  list *pxlist;
  while (pxlist = read_prefix_list(lp0, f, 0, plus))
  while (pxlist = read_prefix_list(f, 0, plus))
  {
    data[n] = pxlist;
    trie[n] = make_trie_from_prefix_list(lp1, pxlist);
    trie[n] = make_trie_from_prefix_list(pxlist);
    bt_debug("NEXT\n");
    n++;
  }
@@ -437,11 +436,10 @@ t_match_random_net(void)
  bt_config_parse(BT_CONFIG_SIMPLE);

  int v6 = 0;
  linpool *lp = lp_new_default(&root_pool);
  for (int round = 0; round < TESTS_NUM; round++)
  {
    list *prefixes = make_random_prefix_list(lp, PREFIXES_NUM, v6, 0);
    struct f_trie *trie = make_trie_from_prefix_list(lp, prefixes);
    list *prefixes = make_random_prefix_list(PREFIXES_NUM, v6, 0);
    struct f_trie *trie = make_trie_from_prefix_list(prefixes);

    for (int i = 0; i < PREFIX_TESTS_NUM; i++)
    {
@@ -451,7 +449,7 @@ t_match_random_net(void)
    }

    v6 = !v6;
    lp_flush(lp);
    tmp_flush();
  }

  bt_bird_cleanup();
@@ -465,11 +463,10 @@ t_match_inner_net(void)
  bt_config_parse(BT_CONFIG_SIMPLE);

  int v6 = 0;
  linpool *lp = lp_new_default(&root_pool);
  for (int round = 0; round < TESTS_NUM; round++)
  {
    list *prefixes = make_random_prefix_list(lp, PREFIXES_NUM, v6, 0);
    struct f_trie *trie = make_trie_from_prefix_list(lp, prefixes);
    list *prefixes = make_random_prefix_list(PREFIXES_NUM, v6, 0);
    struct f_trie *trie = make_trie_from_prefix_list(prefixes);

    struct f_prefix_node *n = HEAD(*prefixes);
    for (int i = 0; i < PREFIX_TESTS_NUM; i++)
@@ -482,7 +479,7 @@ t_match_inner_net(void)
    }

    v6 = !v6;
    lp_flush(lp);
    tmp_flush();
  }

  bt_bird_cleanup();
@@ -496,11 +493,10 @@ t_match_outer_net(void)
  bt_config_parse(BT_CONFIG_SIMPLE);

  int v6 = 0;
  linpool *lp = lp_new_default(&root_pool);
  for (int round = 0; round < TESTS_NUM; round++)
  {
    list *prefixes = make_random_prefix_list(lp, PREFIXES_NUM, v6, 0);
    struct f_trie *trie = make_trie_from_prefix_list(lp, prefixes);
    list *prefixes = make_random_prefix_list(PREFIXES_NUM, v6, 0);
    struct f_trie *trie = make_trie_from_prefix_list(prefixes);

    struct f_prefix_node *n = HEAD(*prefixes);
    for (int i = 0; i < PREFIX_TESTS_NUM; i++)
@@ -513,7 +509,7 @@ t_match_outer_net(void)
    }

    v6 = !v6;
    lp_flush(lp);
    tmp_flush();
  }

  v6 = !v6;
@@ -531,24 +527,22 @@ static int
benchmark_trie_dataset(const char *filename, int plus)
{
  int n = 0;
  linpool *lp0 = lp_new_default(&root_pool);
  linpool *lp1 = lp_new_default(&root_pool);
  list *data[TRIE_BUFFER_SIZE];
  struct f_trie *trie[TRIE_BUFFER_SIZE];
  net_addr *nets;

  bt_reset_suite_case_timer();
  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);

  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",
			   (uint) (trie_size / 1000), (uint) (trie_size % 1000));

  int t = PREFIX_BENCH_NUM / n;
  int tb = MIN(t, TEST_BUFFER_SIZE);
  nets = lp_alloc(lp0, tb * sizeof(net_addr));
  nets = tmp_alloc(tb * sizeof(net_addr));

  if (!plus)
    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);

  rfree(lp0);
  rfree(lp1);

  tmp_flush();
  return 1;
}

@@ -621,12 +613,11 @@ t_trie_same(void)
  bt_config_parse(BT_CONFIG_SIMPLE);

  int v6 = 0;
  linpool *lp = lp_new_default(&root_pool);
  for (int round = 0; round < TESTS_NUM*4; round++)
  {
    list *prefixes = make_random_prefix_list(lp, 100 * PREFIXES_NUM, v6, 0);
    struct f_trie *trie1 = f_new_trie(lp, 0);
    struct f_trie *trie2 = f_new_trie(lp, 0);
    list *prefixes = make_random_prefix_list(100 * PREFIXES_NUM, v6, 0);
    struct f_trie *trie1 = f_new_trie(tmp_linpool, 0);
    struct f_trie *trie2 = f_new_trie(tmp_linpool, 0);

    struct f_prefix_node *n;
    WALK_LIST(n, *prefixes)
@@ -638,7 +629,7 @@ t_trie_same(void)
    bt_assert(trie_same(trie1, trie2));

    v6 = !v6;
    lp_flush(lp);
    tmp_flush();
  }

  bt_bird_cleanup();
@@ -664,15 +655,14 @@ t_trie_walk(void)
  bt_bird_init();
  bt_config_parse(BT_CONFIG_SIMPLE);

  linpool *lp = lp_new_default(&root_pool);
  for (int round = 0; round < TESTS_NUM*8; round++)
  {
    int level = round / TESTS_NUM;
    int v6 = level % 2;
    int num = PREFIXES_NUM * (int[]){1, 10, 100, 1000}[level / 2];
    int pos = 0, end = 0;
    list *prefixes = make_random_prefix_list(lp, num, v6, 1);
    struct f_trie *trie = make_trie_from_prefix_list(lp, prefixes);
    list *prefixes = make_random_prefix_list(num, v6, 1);
    struct f_trie *trie = make_trie_from_prefix_list(prefixes);
    struct f_prefix *pxset = malloc((num + 1) * sizeof(struct f_prefix));

    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_debug("Subnet walk done for %s (found %d nets)\n", buf0, pos - p0);

    lp_flush(lp);
    tmp_flush();
  }

  bt_bird_cleanup();
@@ -815,7 +805,6 @@ t_trie_walk_to_root(void)
  bt_bird_init();
  bt_config_parse(BT_CONFIG_SIMPLE);

  linpool *lp = lp_new_default(&root_pool);
  for (int round = 0; round < TESTS_NUM * 4; round++)
  {
    int level = round / TESTS_NUM;
@@ -824,8 +813,8 @@ t_trie_walk_to_root(void)
    int pos = 0;
    int st = 0, sn = 0, sm = 0;

    list *prefixes = make_random_prefix_list(lp, num, v6, 1);
    struct f_trie *trie = make_trie_from_prefix_list(lp, prefixes);
    list *prefixes = make_random_prefix_list(num, v6, 1);
    struct f_trie *trie = make_trie_from_prefix_list(prefixes);
    struct f_prefix *pxset = malloc((num + 1) * sizeof(struct f_prefix));

    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);

    lp_flush(lp);
    tmp_flush();
  }

  bt_bird_cleanup();
+3 −5
Original line number Diff line number Diff line
@@ -449,7 +449,6 @@ t_builder4(void)
  resource_init();

  struct flow_builder *fb = flow_builder_init(&root_pool);
  linpool *lp = lp_new_default(&root_pool);

  /* Expectation */

@@ -492,7 +491,7 @@ t_builder4(void)
  flow_builder_set_type(fb, FLOW_TYPE_TCP_FLAGS);
  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);

@@ -530,7 +529,6 @@ t_builder6(void)
  net_addr_ip6 ip;

  resource_init();
  linpool *lp = lp_new_default(&root_pool);
  struct flow_builder *fb = flow_builder_init(&root_pool);
  fb->ipv6 = 1;

@@ -574,7 +572,7 @@ t_builder6(void)
  flow_builder_set_type(fb, FLOW_TYPE_LABEL);
  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);

  /* Reverse order */
@@ -601,7 +599,7 @@ t_builder6(void)
  flow_builder_set_type(fb, FLOW_TYPE_DST_PREFIX);
  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);

  return 1;
+9 −13
Original line number Diff line number Diff line
@@ -32,14 +32,13 @@ t_as_path_match(void)
    struct adata *as_path = &empty_as_path;
    u32 first_prepended, last_prepended;
    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));
    mask->len = AS_PATH_LENGTH;
    for (int i = AS_PATH_LENGTH - 1; i >= 0; i--)
    {
      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);

      if (i == 0)
@@ -61,7 +60,7 @@ t_as_path_match(void)
    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");

    rfree(lp);
    tmp_flush();
  }

  return 1;
@@ -74,12 +73,11 @@ t_path_format(void)

  struct adata empty_as_path = {};
  struct adata *as_path = &empty_as_path;
  struct linpool *lp = lp_new_default(&root_pool);

  uint 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);
  }

@@ -97,7 +95,7 @@ t_path_format(void)
  as_path_format(as_path, buf2, SMALL_BUFFER_SIZE);
  bt_assert_msg(strcmp(buf2, "4294967294 42...") == 0, "Small Buffer(%zu): '%s'", strlen(buf2), buf2);

  rfree(lp);
  tmp_flush();

  return 1;
}
@@ -120,7 +118,6 @@ t_path_include(void)

  struct adata empty_as_path = {};
  struct adata *as_path = &empty_as_path;
  struct linpool *lp = lp_new_default(&root_pool);

  u32 as_nums[AS_PATH_LENGTH] = {};
  int i;
@@ -128,7 +125,7 @@ t_path_include(void)
  {
    u32 val = bt_random();
    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++)
@@ -136,8 +133,8 @@ t_path_include(void)
    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(as_path_filter(lp, 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], 0) != NULL);
    bt_assert(as_path_filter(tmp_linpool, as_path, NULL, as_nums[i], 1) != NULL);
  }

  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);
  }

  rfree(lp);
  tmp_flush();

  return 1;
}
@@ -165,12 +162,11 @@ t_as_path_converting(void)

  struct adata 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

  int 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);

Loading