Commit a445327b authored by David Goulet's avatar David Goulet 🐼
Browse files

test: Add unit tests for addressset.c



This also adds one that tests the integration with the nodelist.

Signed-off-by: David Goulet's avatarDavid Goulet <dgoulet@torproject.org>
parent 6892d329
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -275,6 +275,17 @@ nodelist_add_microdesc(microdesc_t *md)
  return node;
}

/* Default value. */
#define ESTIMATED_ADDRESS_PER_NODE 2

/* Return the estimated number of address per node_t. This is used for the
 * size of the bloom filter in the nodelist (node_addrs). */
MOCK_IMPL(int,
get_estimated_address_per_node, (void))
{
  return ESTIMATED_ADDRESS_PER_NODE;
}

/** Tell the nodelist that the current usable consensus is <b>ns</b>.
 * This makes the nodelist change all of the routerstatus entries for
 * the nodes, drop nodes that no longer have enough info to get used,
@@ -294,7 +305,8 @@ nodelist_set_consensus(networkstatus_t *ns)
                    node->rs = NULL);

  /* Conservatively estimate that every node will have 2 addresses. */
  const int estimated_addresses = smartlist_len(ns->routerstatus_list) * 2;
  const int estimated_addresses = smartlist_len(ns->routerstatus_list) *
                                  get_estimated_address_per_node();
  address_set_free(the_nodelist->node_addrs);
  the_nodelist->node_addrs = address_set_new(estimated_addresses);

+2 −0
Original line number Diff line number Diff line
@@ -125,5 +125,7 @@ void router_dir_info_changed(void);
const char *get_dir_info_status_string(void);
int count_loading_descriptors_progress(void);

MOCK_DECL(int, get_estimated_address_per_node, (void));

#endif
+1 −0
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ src_test_test_SOURCES = \
	src/test/test_accounting.c \
	src/test/test_addr.c \
	src/test/test_address.c \
	src/test/test_address_set.c \
	src/test/test_buffers.c \
	src/test/test_cell_formats.c \
	src/test/test_cell_queue.c \
+1 −0
Original line number Diff line number Diff line
@@ -1182,6 +1182,7 @@ struct testgroup_t testgroups[] = {
  { "accounting/", accounting_tests },
  { "addr/", addr_tests },
  { "address/", address_tests },
  { "address_set/", address_set_tests },
  { "buffer/", buffer_tests },
  { "cellfmt/", cell_format_tests },
  { "cellqueue/", cell_queue_tests },
+1 −0
Original line number Diff line number Diff line
@@ -175,6 +175,7 @@ extern const struct testcase_setup_t ed25519_test_setup;
extern struct testcase_t accounting_tests[];
extern struct testcase_t addr_tests[];
extern struct testcase_t address_tests[];
extern struct testcase_t address_set_tests[];
extern struct testcase_t buffer_tests[];
extern struct testcase_t cell_format_tests[];
extern struct testcase_t cell_queue_tests[];
Loading