aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_controller_events.c
diff options
context:
space:
mode:
authorTaylor Yu <catalyst@torproject.org>2019-03-08 09:41:43 -0600
committerDavid Goulet <dgoulet@torproject.org>2019-06-11 11:59:30 -0400
commita8c0f4ddfe3f0a63bd499959c8d921346aa9766e (patch)
tree50793b2860d2ce1532cf23197957c2c22e10aa96 /src/test/test_controller_events.c
parenta8a0144d1183a3598bffe6c552507c9dcbdcd474 (diff)
downloadtor-a8c0f4ddfe3f0a63bd499959c8d921346aa9766e.tar.gz
tor-a8c0f4ddfe3f0a63bd499959c8d921346aa9766e.zip
Rework orconn tracking to use pubsub
Part of ticket 29976.
Diffstat (limited to 'src/test/test_controller_events.c')
-rw-r--r--src/test/test_controller_events.c51
1 files changed, 29 insertions, 22 deletions
diff --git a/src/test/test_controller_events.c b/src/test/test_controller_events.c
index 910aacace3..14fe4fd661 100644
--- a/src/test/test_controller_events.c
+++ b/src/test/test_controller_events.c
@@ -7,6 +7,7 @@
#define CONTROL_EVENTS_PRIVATE
#define OCIRC_EVENT_PRIVATE
#define ORCONN_EVENT_PRIVATE
+#include "app/main/subsysmgr.h"
#include "core/or/or.h"
#include "core/or/channel.h"
#include "core/or/channeltls.h"
@@ -16,6 +17,7 @@
#include "core/mainloop/connection.h"
#include "feature/control/control_events.h"
#include "test/test.h"
+#include "test/test_helpers.h"
#include "core/or/or_circuit_st.h"
#include "core/or/origin_circuit_st.h"
@@ -394,20 +396,22 @@ test_cntev_dirboot_defer_orconn(void *arg)
}
static void
-setup_orconn_state(orconn_event_msg_t *msg, uint64_t gid, uint64_t chan,
+setup_orconn_state(orconn_state_msg_t *msg, uint64_t gid, uint64_t chan,
int proxy_type)
{
- msg->type = ORCONN_MSGTYPE_STATE;
- msg->u.state.gid = gid;
- msg->u.state.chan = chan;
- msg->u.state.proxy_type = proxy_type;
+ msg->gid = gid;
+ msg->chan = chan;
+ msg->proxy_type = proxy_type;
}
static void
-send_orconn_state(orconn_event_msg_t *msg, uint8_t state)
+send_orconn_state(const orconn_state_msg_t *msg_in, uint8_t state)
{
- msg->u.state.state = state;
- orconn_event_publish(msg);
+ orconn_state_msg_t *msg = tor_malloc(sizeof(*msg));
+
+ *msg = *msg_in;
+ msg->state = state;
+ orconn_state_publish(msg);
}
static void
@@ -425,7 +429,7 @@ send_ocirc_chan(uint32_t gid, uint64_t chan, bool onehop)
static void
test_cntev_orconn_state(void *arg)
{
- orconn_event_msg_t conn;
+ orconn_state_msg_t conn;
(void)arg;
MOCK(queue_control_event_string, mock_queue_control_event_string);
@@ -442,8 +446,8 @@ test_cntev_orconn_state(void *arg)
send_orconn_state(&conn, OR_CONN_STATE_OPEN);
assert_bootmsg("15 TAG=handshake_done");
- conn.u.state.gid = 2;
- conn.u.state.chan = 2;
+ conn.gid = 2;
+ conn.chan = 2;
send_orconn_state(&conn, OR_CONN_STATE_CONNECTING);
/* It doesn't know it's an origin circuit yet */
assert_bootmsg("15 TAG=handshake_done");
@@ -464,7 +468,7 @@ test_cntev_orconn_state(void *arg)
static void
test_cntev_orconn_state_pt(void *arg)
{
- orconn_event_msg_t conn;
+ orconn_state_msg_t conn;
(void)arg;
MOCK(queue_control_event_string, mock_queue_control_event_string);
@@ -484,8 +488,8 @@ test_cntev_orconn_state_pt(void *arg)
assert_bootmsg("15 TAG=handshake_done");
send_ocirc_chan(2, 2, false);
- conn.u.state.gid = 2;
- conn.u.state.chan = 2;
+ conn.gid = 2;
+ conn.chan = 2;
send_orconn_state(&conn, OR_CONN_STATE_CONNECTING);
assert_bootmsg("76 TAG=ap_conn_pt");
send_orconn_state(&conn, OR_CONN_STATE_PROXY_HANDSHAKING);
@@ -499,7 +503,7 @@ test_cntev_orconn_state_pt(void *arg)
static void
test_cntev_orconn_state_proxy(void *arg)
{
- orconn_event_msg_t conn;
+ orconn_state_msg_t conn;
(void)arg;
MOCK(queue_control_event_string, mock_queue_control_event_string);
@@ -519,8 +523,8 @@ test_cntev_orconn_state_proxy(void *arg)
assert_bootmsg("15 TAG=handshake_done");
send_ocirc_chan(2, 2, false);
- conn.u.state.gid = 2;
- conn.u.state.chan = 2;
+ conn.gid = 2;
+ conn.chan = 2;
send_orconn_state(&conn, OR_CONN_STATE_CONNECTING);
assert_bootmsg("78 TAG=ap_conn_proxy");
send_orconn_state(&conn, OR_CONN_STATE_PROXY_HANDSHAKING);
@@ -534,15 +538,18 @@ test_cntev_orconn_state_proxy(void *arg)
#define TEST(name, flags) \
{ #name, test_cntev_ ## name, flags, 0, NULL }
+#define T_PUBSUB(name, setup) \
+ { #name, test_cntev_ ## name, TT_FORK, &helper_pubsub_setup, NULL }
+
struct testcase_t controller_event_tests[] = {
TEST(sum_up_cell_stats, TT_FORK),
TEST(append_cell_stats, TT_FORK),
TEST(format_cell_stats, TT_FORK),
TEST(event_mask, TT_FORK),
- TEST(dirboot_defer_desc, TT_FORK),
- TEST(dirboot_defer_orconn, TT_FORK),
- TEST(orconn_state, TT_FORK),
- TEST(orconn_state_pt, TT_FORK),
- TEST(orconn_state_proxy, TT_FORK),
+ T_PUBSUB(dirboot_defer_desc, TT_FORK),
+ T_PUBSUB(dirboot_defer_orconn, TT_FORK),
+ T_PUBSUB(orconn_state, TT_FORK),
+ T_PUBSUB(orconn_state_pt, TT_FORK),
+ T_PUBSUB(orconn_state_proxy, TT_FORK),
END_OF_TESTCASES
};