Merge branch 'decouple_controller_events_squashed'

This commit is contained in:
Nick Mathewson
2015-08-18 08:56:31 -04:00
13 changed files with 472 additions and 135 deletions
+6 -6
View File
@@ -395,12 +395,12 @@ test_cntev_event_mask(void *arg)
{ #name, test_cntev_ ## name, flags, 0, NULL }
struct testcase_t controller_event_tests[] = {
TEST(bucket_note_empty, 0),
TEST(bucket_millis_empty, 0),
TEST(sum_up_cell_stats, 0),
TEST(append_cell_stats, 0),
TEST(format_cell_stats, 0),
TEST(event_mask, 0),
TEST(bucket_note_empty, TT_FORK),
TEST(bucket_millis_empty, TT_FORK),
TEST(sum_up_cell_stats, TT_FORK),
TEST(append_cell_stats, TT_FORK),
TEST(format_cell_stats, TT_FORK),
TEST(event_mask, TT_FORK),
END_OF_TESTCASES
};
+5 -7
View File
@@ -102,13 +102,11 @@ static char *received_msg = NULL;
/** Mock function for send_control_event_string
*/
static void
send_control_event_string_replacement(uint16_t event, event_format_t which,
const char *msg)
queue_control_event_string_replacement(uint16_t event, char *msg)
{
(void) event;
(void) which;
tor_free(received_msg);
received_msg = tor_strdup(msg);
received_msg = msg;
}
/** Mock function for node_describe_longname_by_id, it returns either
@@ -141,8 +139,8 @@ test_hs_desc_event(void *arg)
char desc_id_base32[REND_DESC_ID_V2_LEN_BASE32 + 1];
(void) arg;
MOCK(send_control_event_string,
send_control_event_string_replacement);
MOCK(queue_control_event_string,
queue_control_event_string_replacement);
MOCK(node_describe_longname_by_id,
node_describe_longname_by_id_replacement);
@@ -225,7 +223,7 @@ test_hs_desc_event(void *arg)
smartlist_free(rend_query.hsdirs_fp);
done:
UNMOCK(send_control_event_string);
UNMOCK(queue_control_event_string);
UNMOCK(node_describe_longname_by_id);
tor_free(received_msg);
}
+5 -7
View File
@@ -333,15 +333,13 @@ static uint16_t controlevent_event = 0;
static smartlist_t *controlevent_msgs = NULL;
static void
send_control_event_string_replacement(uint16_t event, event_format_t which,
const char *msg)
queue_control_event_string_replacement(uint16_t event, char *msg)
{
(void) which;
++controlevent_n;
controlevent_event = event;
if (!controlevent_msgs)
controlevent_msgs = smartlist_new();
smartlist_add(controlevent_msgs, tor_strdup(msg));
smartlist_add(controlevent_msgs, msg);
}
/* Test the configure_proxy() function. */
@@ -360,8 +358,8 @@ test_pt_configure_proxy(void *arg)
tor_process_handle_destroy_replacement);
MOCK(get_or_state,
get_or_state_replacement);
MOCK(send_control_event_string,
send_control_event_string_replacement);
MOCK(queue_control_event_string,
queue_control_event_string_replacement);
control_testing_set_global_event_mask(EVENT_TRANSPORT_LAUNCHED);
@@ -435,7 +433,7 @@ test_pt_configure_proxy(void *arg)
UNMOCK(tor_get_lines_from_handle);
UNMOCK(tor_process_handle_destroy);
UNMOCK(get_or_state);
UNMOCK(send_control_event_string);
UNMOCK(queue_control_event_string);
if (controlevent_msgs) {
SMARTLIST_FOREACH(controlevent_msgs, char *, cp, tor_free(cp));
smartlist_free(controlevent_msgs);
+8 -6
View File
@@ -28,7 +28,7 @@ static unsigned long thread_fn_tid1, thread_fn_tid2;
static void thread_test_func_(void* _s) ATTR_NORETURN;
/** How many iterations have the threads in the unit test run? */
static int t1_count = 0, t2_count = 0;
static tor_threadlocal_t count;
/** Helper function for threading unit tests: This function runs in a
* subthread. It grabs its own mutex (start1 or start2) to make sure that it
@@ -38,19 +38,19 @@ static void
thread_test_func_(void* _s)
{
char *s = _s;
int i, *count;
int i;
tor_mutex_t *m;
char buf[64];
char **cp;
int *mycount = tor_malloc_zero(sizeof(int));
tor_threadlocal_set(&count, mycount);
if (!strcmp(s, "thread 1")) {
m = thread_test_start1_;
cp = &thread1_name_;
count = &t1_count;
thread_fn_tid1 = tor_get_thread_id();
} else {
m = thread_test_start2_;
cp = &thread2_name_;
count = &t2_count;
thread_fn_tid2 = tor_get_thread_id();
}
@@ -62,8 +62,10 @@ thread_test_func_(void* _s)
for (i=0; i<10000; ++i) {
tor_mutex_acquire(thread_test_mutex_);
strmap_set(thread_test_strmap_, "last to run", *cp);
++*count;
tor_mutex_release(thread_test_mutex_);
int *tls_count = tor_threadlocal_get(&count);
tor_assert(tls_count == mycount);
++*tls_count;
}
tor_mutex_acquire(thread_test_mutex_);
strmap_set(thread_test_strmap_, s, *cp);
@@ -89,6 +91,7 @@ test_threads_basic(void *arg)
tv.tv_usec=100*1000;
#endif
(void) arg;
tt_int_op(tor_threadlocal_init(&count), OP_EQ, 0);
set_main_thread();
@@ -128,7 +131,6 @@ test_threads_basic(void *arg)
tor_mutex_free(thread_test_mutex_);
if (timedout) {
printf("\nTimed out: %d %d", t1_count, t2_count);
tt_assert(strmap_get(thread_test_strmap_, "thread 1"));
tt_assert(strmap_get(thread_test_strmap_, "thread 2"));
tt_assert(!timedout);
+2
View File
@@ -14,6 +14,7 @@ const char tor_git_revision[] = "";
#include "orconfig.h"
#include "or.h"
#include "control.h"
#include "config.h"
#include "rephist.h"
#include "backtrace.h"
@@ -237,6 +238,7 @@ main(int c, const char **v)
update_approx_time(time(NULL));
options = options_new();
tor_threads_init();
control_initialize_event_queue();
init_logging(1);
configure_backtrace_handler(get_version());