[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Basic entry_is_live() unittest.



commit 46d41e6e9b4208b1a951f2d7f14da92606b82195
Author: George Kadianakis <desnacked@xxxxxxxxxx>
Date:   Wed Jun 25 15:39:00 2014 -0400

    Basic entry_is_live() unittest.
---
 src/or/entrynodes.c        |    2 +-
 src/or/entrynodes.h        |    5 ++++
 src/test/test_entrynodes.c |   62 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 68 insertions(+), 1 deletion(-)

diff --git a/src/or/entrynodes.c b/src/or/entrynodes.c
index 3dcb8f7..d025a54 100644
--- a/src/or/entrynodes.c
+++ b/src/or/entrynodes.c
@@ -190,7 +190,7 @@ entry_is_time_to_retry(const entry_guard_t *e, time_t now)
  * If need_descriptor is true, only return the node if we currently have
  * a descriptor (routerinfo or microdesc) for it.
  */
-static INLINE const node_t *
+STATIC INLINE const node_t *
 entry_is_live(const entry_guard_t *e, int need_uptime, int need_capacity,
               int assume_reachable, int need_descriptor, const char **msg)
 {
diff --git a/src/or/entrynodes.h b/src/or/entrynodes.h
index d49ca50..afbe9e9 100644
--- a/src/or/entrynodes.h
+++ b/src/or/entrynodes.h
@@ -91,6 +91,11 @@ STATIC int populate_live_entry_guards(smartlist_t *live_entry_guards,
 STATIC int decide_num_guards(const or_options_t *options, int for_directory);
 
 STATIC void entry_guards_set_from_config(const or_options_t *options);
+
+STATIC INLINE const node_t *entry_is_live(const entry_guard_t *e,
+                                          int need_uptime, int need_capacity,
+                                          int assume_reachable,
+                                          int need_descriptor,const char **msg);
 #endif
 
 void remove_all_entry_guards(void);
diff --git a/src/test/test_entrynodes.c b/src/test/test_entrynodes.c
index 09a847f..528329a 100644
--- a/src/test/test_entrynodes.c
+++ b/src/test/test_entrynodes.c
@@ -542,6 +542,65 @@ test_entry_guards_set_from_config(void *arg)
   routerset_free(options->EntryNodes);
 }
 
+/** XXX Do some tests that entry_is_live() */
+static void
+test_entry_is_live(void *arg)
+{
+  smartlist_t *our_nodelist = NULL;
+  const smartlist_t *all_entry_guards = get_entry_guards();
+  const node_t *test_node = NULL;
+  const entry_guard_t *test_entry = NULL;
+  const char *msg;
+
+  (void) arg;
+
+  /* The global entry guards smartlist should be empty now. */
+  tt_int_op(smartlist_len(all_entry_guards), ==, 0);
+
+  /* Walk the nodelist and add all nodes as entry guards. */
+  our_nodelist = nodelist_get_list();
+  tt_int_op(smartlist_len(our_nodelist), ==, NUMBER_OF_DESCRIPTORS);
+
+  SMARTLIST_FOREACH_BEGIN(our_nodelist, const node_t *, node) {
+    const node_t *node_tmp;
+    node_tmp = add_an_entry_guard(node, 0, 1, 0, 0);
+    test_assert(node_tmp);
+
+    tt_int_op(node->is_stable, ==, 0);
+    tt_int_op(node->is_fast, ==, 0);
+  } SMARTLIST_FOREACH_END(node);
+
+  /* Make sure the nodes were added as entry guards. */
+  tt_int_op(smartlist_len(all_entry_guards), ==, NUMBER_OF_DESCRIPTORS);
+
+  /* Now get a random test entry that we will use for this unit test. */
+  test_entry = smartlist_get(all_entry_guards, 3); /* chosen by fair dice roll */
+
+  /* Let's do some entry_is_live() tests! */
+
+  /* Require the node to be stable, but it's not. Should fail.
+     Also enable 'assume_reachable' because why not. */
+  test_node = entry_is_live(test_entry, 1, 0, 1, 0, &msg);
+  test_assert(!test_node);
+
+  /* Require the node to be fast, but it's not. Should fail. */
+  test_node = entry_is_live(test_entry, 0, 1, 1, 0, &msg);
+  test_assert(!test_node);
+
+  /* Don't impose any restrictions on the node. Should succeed. */
+  test_node = entry_is_live(test_entry, 0, 0, 0, 0, &msg);
+  test_assert(test_node);
+  tt_ptr_op(test_node, ==, node_get_by_id(test_entry->identity));
+
+  /* Require descriptor for this node. It has one so it should succeed. */
+  test_node = entry_is_live(test_entry, 0, 0, 0, 1, &msg);
+  test_assert(test_node);
+  tt_ptr_op(test_node, ==, node_get_by_id(test_entry->identity));
+
+ done:
+  ; /* XXX */
+}
+
 static const struct testcase_setup_t fake_network = {
   fake_network_setup, fake_network_cleanup
 };
@@ -567,6 +626,9 @@ struct testcase_t entrynodes_tests[] = {
   { "entry_guards_set_from_config",
     test_entry_guards_set_from_config,
     TT_FORK, &fake_network, NULL },
+  { "entry_is_live",
+    test_entry_is_live,
+    TT_FORK, &fake_network, NULL },
   END_OF_TESTCASES
 };
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits