[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] Some unit tests now require that periodic events be initialized.
commit 70f337fdb20f5ce378e1bfb936aa63a40cdcacaa
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Tue Nov 17 09:26:50 2015 -0500
Some unit tests now require that periodic events be initialized.
---
src/or/main.c | 9 +++++++--
src/or/main.h | 2 ++
src/or/periodic.c | 18 ++++++++++++++----
src/or/periodic.h | 1 +
src/test/test.c | 5 +++++
5 files changed, 29 insertions(+), 6 deletions(-)
diff --git a/src/or/main.c b/src/or/main.c
index afcb313..b63b81e 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -1352,12 +1352,17 @@ initialize_periodic_events_cb(evutil_socket_t fd, short events, void *data)
/** Set up all the members of periodic_events[], and configure them all to be
* launched from a callback. */
-static void
+STATIC void
initialize_periodic_events(void)
{
tor_assert(periodic_events_initialized == 0);
periodic_events_initialized = 1;
+ int i;
+ for (i = 0; periodic_events[i].name; ++i) {
+ periodic_event_setup(&periodic_events[i]);
+ }
+
#define NAMED_CALLBACK(name) \
STMT_BEGIN name ## _event = find_periodic_event( #name ); STMT_END
@@ -1372,7 +1377,7 @@ initialize_periodic_events(void)
&one_second);
}
-static void
+STATIC void
teardown_periodic_events(void)
{
int i;
diff --git a/src/or/main.h b/src/or/main.h
index 447d3f4..37e93d7 100644
--- a/src/or/main.h
+++ b/src/or/main.h
@@ -78,6 +78,8 @@ int tor_init(int argc, char **argv);
#ifdef MAIN_PRIVATE
STATIC void init_connection_lists(void);
STATIC void close_closeable_connections(void);
+STATIC void initialize_periodic_events(void);
+STATIC void teardown_periodic_events(void);
#endif
#endif
diff --git a/src/or/periodic.c b/src/or/periodic.c
index e21b1af..109717f 100644
--- a/src/or/periodic.c
+++ b/src/or/periodic.c
@@ -78,12 +78,11 @@ periodic_event_reschedule(periodic_event_item_t *event)
periodic_event_set_interval(event, 1);
}
-/** Handles initial dispatch for periodic events. It should happen 1 second
- * after the events are created to mimic behaviour before #3199's refactor */
+/** Initializes the libevent backend for a periodic event. */
void
-periodic_event_launch(periodic_event_item_t *event)
+periodic_event_setup(periodic_event_item_t *event)
{
- if (event->ev) { /** Already setup? This is a bug */
+ if (event->ev) { /* Already setup? This is a bug */
log_err(LD_BUG, "Initial dispatch should only be done once.");
tor_assert(0);
}
@@ -93,6 +92,17 @@ periodic_event_launch(periodic_event_item_t *event)
periodic_event_dispatch,
event);
tor_assert(event->ev);
+}
+
+/** Handles initial dispatch for periodic events. It should happen 1 second
+ * after the events are created to mimic behaviour before #3199's refactor */
+void
+periodic_event_launch(periodic_event_item_t *event)
+{
+ if (! event->ev) { /* Not setup? This is a bug */
+ log_err(LD_BUG, "periodic_event_launch without periodic_event_setup");
+ tor_assert(0);
+ }
// Initial dispatch
periodic_event_dispatch(-1, EV_TIMEOUT, event);
diff --git a/src/or/periodic.h b/src/or/periodic.h
index a77f411..bab0c91 100644
--- a/src/or/periodic.h
+++ b/src/or/periodic.h
@@ -29,6 +29,7 @@ typedef struct periodic_event_item_t {
#define END_OF_PERIODIC_EVENTS { NULL, 0, NULL, NULL }
void periodic_event_launch(periodic_event_item_t *event);
+void periodic_event_setup(periodic_event_item_t *event);
void periodic_event_destroy(periodic_event_item_t *event);
void periodic_event_reschedule(periodic_event_item_t *event);
diff --git a/src/test/test.c b/src/test/test.c
index 44171b5..0bc6292 100644
--- a/src/test/test.c
+++ b/src/test/test.c
@@ -28,6 +28,7 @@
#define ROUTER_PRIVATE
#define CIRCUITSTATS_PRIVATE
#define CIRCUITLIST_PRIVATE
+#define MAIN_PRIVATE
#define STATEFILE_PRIVATE
/*
@@ -50,6 +51,7 @@ double fabs(double x);
#include "rendcache.h"
#include "test.h"
#include "torgzip.h"
+#include "main.h"
#include "memarea.h"
#include "onion.h"
#include "onion_ntor.h"
@@ -317,6 +319,8 @@ test_circuit_timeout(void *arg)
int i, runs;
double close_ms;
(void)arg;
+ initialize_periodic_events();
+
circuit_build_times_init(&initial);
circuit_build_times_init(&estimate);
circuit_build_times_init(&final);
@@ -456,6 +460,7 @@ test_circuit_timeout(void *arg)
circuit_build_times_free_timeouts(&estimate);
circuit_build_times_free_timeouts(&final);
or_state_free(state);
+ teardown_periodic_events();
}
/** Test encoding and parsing of rendezvous service descriptors. */
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits