commit a72b92676e936e4936073e10a2452a12982e7ab4
Author: George Kadianakis <desnac...@riseup.net>
Date:   Mon Sep 15 15:51:20 2014 +0300

    Fix up testhelper to be used by the entryguard unittests.
---
 src/test/include.am        |    2 ++
 src/test/test_entrynodes.c |   12 ++++++------
 src/test/testhelper.c      |   14 ++++++++------
 src/test/testhelper.h      |   10 ++++++++++
 4 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/src/test/include.am b/src/test/include.am
index 77c92f1..28f3a83 100644
--- a/src/test/include.am
+++ b/src/test/include.am
@@ -47,6 +47,7 @@ src_test_test_SOURCES = \
        src/test/test_policy.c \
        src/test/test_status.c \
        src/test/test_routerset.c \
+       src/test/testhelper.c \
        src/ext/tinytest.c
 
 src_test_test_CFLAGS = $(AM_CFLAGS) $(TEST_CFLAGS)
@@ -74,6 +75,7 @@ src_test_bench_LDADD = src/or/libtor.a src/common/libor.a \
 
 noinst_HEADERS+= \
        src/test/test.h \
+       src/test/testhelper.h \
        src/test/test_descriptors.inc
 
 if CURVE25519_ENABLED
diff --git a/src/test/test_entrynodes.c b/src/test/test_entrynodes.c
index 0f7fcb0..1298159 100644
--- a/src/test/test_entrynodes.c
+++ b/src/test/test_entrynodes.c
@@ -18,7 +18,7 @@
 #include "statefile.h"
 #include "config.h"
 
-#include "test_descriptors.inc"
+#include "testhelper.h"
 
 /* TODO:
  * choose_random_entry() test with state set.
@@ -64,7 +64,7 @@ fake_network_setup(const struct testcase_t *testcase)
        get_or_state_replacement);
 
   /* Setup fake routerlist. */
-  setup_fake_routerlist();
+  helper_setup_fake_routerlist();
 
   /* Return anything but NULL (it's interpreted as test fail) */
   return dummy_state;
@@ -141,7 +141,7 @@ populate_live_entry_guards_test_helper(int num_needed)
 
   /* 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);
+  tt_int_op(smartlist_len(our_nodelist), ==, HELPER_NUMBER_OF_DESCRIPTORS);
 
   SMARTLIST_FOREACH_BEGIN(our_nodelist, const node_t *, node) {
     const node_t *node_tmp;
@@ -150,7 +150,7 @@ populate_live_entry_guards_test_helper(int num_needed)
   } SMARTLIST_FOREACH_END(node);
 
   /* Make sure the nodes were added as entry guards. */
-  tt_int_op(smartlist_len(all_entry_guards), ==, NUMBER_OF_DESCRIPTORS);
+  tt_int_op(smartlist_len(all_entry_guards), ==, HELPER_NUMBER_OF_DESCRIPTORS);
 
   /* Ensure that all the possible entry guards are enough to satisfy us. */
   tt_int_op(smartlist_len(all_entry_guards), >=, num_needed);
@@ -590,7 +590,7 @@ test_entry_is_live(void *arg)
 
   /* 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);
+  tt_int_op(smartlist_len(our_nodelist), ==, HELPER_NUMBER_OF_DESCRIPTORS);
 
   SMARTLIST_FOREACH_BEGIN(our_nodelist, const node_t *, node) {
     const node_t *node_tmp;
@@ -602,7 +602,7 @@ test_entry_is_live(void *arg)
   } SMARTLIST_FOREACH_END(node);
 
   /* Make sure the nodes were added as entry guards. */
-  tt_int_op(smartlist_len(all_entry_guards), ==, NUMBER_OF_DESCRIPTORS);
+  tt_int_op(smartlist_len(all_entry_guards), ==, HELPER_NUMBER_OF_DESCRIPTORS);
 
   /* Now get a random test entry that we will use for this unit test. */
   which_node = 3;  /* (chosen by fair dice roll) */
diff --git a/src/test/testhelper.c b/src/test/testhelper.c
index 4e23f0c..8bbc192 100644
--- a/src/test/testhelper.c
+++ b/src/test/testhelper.c
@@ -24,9 +24,9 @@ router_descriptor_is_older_than_replacement(const 
routerinfo_t *router,
 
 /** Parse a file containing router descriptors and load them to our
     routerlist. This function is used to setup an artificial network
-    so that we can conduct entry guard tests. */
-static void
-setup_fake_routerlist(void)
+    so that we can conduct tests on it. */
+void
+helper_setup_fake_routerlist(void)
 {
   int retval;
   routerlist_t *our_routerlist = NULL;
@@ -43,15 +43,16 @@ setup_fake_routerlist(void)
   retval = router_load_routers_from_string(TEST_DESCRIPTORS,
                                            NULL, SAVED_IN_JOURNAL,
                                            NULL, 0, NULL);
-  tt_int_op(retval, ==, NUMBER_OF_DESCRIPTORS);
+  tt_int_op(retval, ==, HELPER_NUMBER_OF_DESCRIPTORS);
 
   /* Sanity checking of routerlist and nodelist. */
   our_routerlist = router_get_routerlist();
-  tt_int_op(smartlist_len(our_routerlist->routers), ==, NUMBER_OF_DESCRIPTORS);
+  tt_int_op(smartlist_len(our_routerlist->routers), ==,
+              HELPER_NUMBER_OF_DESCRIPTORS);
   routerlist_assert_ok(our_routerlist);
 
   our_nodelist = nodelist_get_list();
-  tt_int_op(smartlist_len(our_nodelist), ==, NUMBER_OF_DESCRIPTORS);
+  tt_int_op(smartlist_len(our_nodelist), ==, HELPER_NUMBER_OF_DESCRIPTORS);
 
   /* Mark all routers as non-guards but up and running! */
   SMARTLIST_FOREACH_BEGIN(our_nodelist, node_t *, node) {
@@ -63,3 +64,4 @@ setup_fake_routerlist(void)
  done:
   UNMOCK(router_descriptor_is_older_than);
 }
+
diff --git a/src/test/testhelper.h b/src/test/testhelper.h
new file mode 100644
index 0000000..6b1bde6
--- /dev/null
+++ b/src/test/testhelper.h
@@ -0,0 +1,10 @@
+#ifndef TOR_TEST_HELPER_H
+#define TOR_TEST_HELPER_H
+
+/* Number of descriptors contained in test_descriptors.txt. */
+#define HELPER_NUMBER_OF_DESCRIPTORS 8
+
+void helper_setup_fake_routerlist(void);
+
+#endif
+



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

Reply via email to