diff options
author | Nick Mathewson <nickm@torproject.org> | 2015-08-18 08:56:31 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2015-08-18 08:56:31 -0400 |
commit | eafae7f677364175e384d0e2c79f05e7d300049d (patch) | |
tree | c91e6744961a2c38cdec3ce559199b4834c548c5 /src/test | |
parent | fe4c0a187dcc6ec8a14175dfc4c62334221d4239 (diff) | |
parent | 087cf882c6a9ef6b9617d21ef26c19c47a4fc660 (diff) | |
download | tor-eafae7f677364175e384d0e2c79f05e7d300049d.tar.gz tor-eafae7f677364175e384d0e2c79f05e7d300049d.zip |
Merge branch 'decouple_controller_events_squashed'
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/test_controller_events.c | 12 | ||||
-rw-r--r-- | src/test/test_hs.c | 12 | ||||
-rw-r--r-- | src/test/test_pt.c | 12 | ||||
-rw-r--r-- | src/test/test_threads.c | 14 | ||||
-rw-r--r-- | src/test/testing_common.c | 2 |
5 files changed, 26 insertions, 26 deletions
diff --git a/src/test/test_controller_events.c b/src/test/test_controller_events.c index bd91aecd94..7b439d490d 100644 --- a/src/test/test_controller_events.c +++ b/src/test/test_controller_events.c @@ -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 }; diff --git a/src/test/test_hs.c b/src/test/test_hs.c index 6d01798a63..126e211858 100644 --- a/src/test/test_hs.c +++ b/src/test/test_hs.c @@ -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); } diff --git a/src/test/test_pt.c b/src/test/test_pt.c index 996ef8666b..6c9aefc487 100644 --- a/src/test/test_pt.c +++ b/src/test/test_pt.c @@ -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); diff --git a/src/test/test_threads.c b/src/test/test_threads.c index 2ac08d4d28..35f5dc8ea3 100644 --- a/src/test/test_threads.c +++ b/src/test/test_threads.c @@ -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); diff --git a/src/test/testing_common.c b/src/test/testing_common.c index 7f387c0b3d..441024bd7d 100644 --- a/src/test/testing_common.c +++ b/src/test/testing_common.c @@ -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()); |