test_controller_events.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. /* Copyright (c) 2013-2019, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. #define CONNECTION_PRIVATE
  4. #define TOR_CHANNEL_INTERNAL_
  5. #define CONTROL_PRIVATE
  6. #define CONTROL_EVENTS_PRIVATE
  7. #define OCIRC_EVENT_PRIVATE
  8. #define ORCONN_EVENT_PRIVATE
  9. #include "core/or/or.h"
  10. #include "core/or/channel.h"
  11. #include "core/or/channeltls.h"
  12. #include "core/or/circuitlist.h"
  13. #include "core/or/ocirc_event.h"
  14. #include "core/or/orconn_event.h"
  15. #include "core/mainloop/connection.h"
  16. #include "feature/control/control_events.h"
  17. #include "test/test.h"
  18. #include "core/or/or_circuit_st.h"
  19. #include "core/or/origin_circuit_st.h"
  20. static void
  21. add_testing_cell_stats_entry(circuit_t *circ, uint8_t command,
  22. unsigned int waiting_time,
  23. unsigned int removed, unsigned int exitward)
  24. {
  25. testing_cell_stats_entry_t *ent = tor_malloc_zero(
  26. sizeof(testing_cell_stats_entry_t));
  27. ent->command = command;
  28. ent->waiting_time = waiting_time;
  29. ent->removed = removed;
  30. ent->exitward = exitward;
  31. if (!circ->testing_cell_stats)
  32. circ->testing_cell_stats = smartlist_new();
  33. smartlist_add(circ->testing_cell_stats, ent);
  34. }
  35. static void
  36. test_cntev_sum_up_cell_stats(void *arg)
  37. {
  38. or_circuit_t *or_circ;
  39. circuit_t *circ;
  40. cell_stats_t *cell_stats = NULL;
  41. (void)arg;
  42. /* This circuit is fake. */
  43. or_circ = tor_malloc_zero(sizeof(or_circuit_t));
  44. or_circ->base_.magic = OR_CIRCUIT_MAGIC;
  45. or_circ->base_.purpose = CIRCUIT_PURPOSE_OR;
  46. circ = TO_CIRCUIT(or_circ);
  47. /* A single RELAY cell was added to the appward queue. */
  48. cell_stats = tor_malloc_zero(sizeof(cell_stats_t));
  49. add_testing_cell_stats_entry(circ, CELL_RELAY, 0, 0, 0);
  50. sum_up_cell_stats_by_command(circ, cell_stats);
  51. tt_u64_op(1, OP_EQ, cell_stats->added_cells_appward[CELL_RELAY]);
  52. /* A single RELAY cell was added to the exitward queue. */
  53. add_testing_cell_stats_entry(circ, CELL_RELAY, 0, 0, 1);
  54. sum_up_cell_stats_by_command(circ, cell_stats);
  55. tt_u64_op(1, OP_EQ, cell_stats->added_cells_exitward[CELL_RELAY]);
  56. /* A single RELAY cell was removed from the appward queue where it spent
  57. * 20 msec. */
  58. add_testing_cell_stats_entry(circ, CELL_RELAY, 2, 1, 0);
  59. sum_up_cell_stats_by_command(circ, cell_stats);
  60. tt_u64_op(20, OP_EQ, cell_stats->total_time_appward[CELL_RELAY]);
  61. tt_u64_op(1, OP_EQ, cell_stats->removed_cells_appward[CELL_RELAY]);
  62. /* A single RELAY cell was removed from the exitward queue where it
  63. * spent 30 msec. */
  64. add_testing_cell_stats_entry(circ, CELL_RELAY, 3, 1, 1);
  65. sum_up_cell_stats_by_command(circ, cell_stats);
  66. tt_u64_op(30, OP_EQ, cell_stats->total_time_exitward[CELL_RELAY]);
  67. tt_u64_op(1, OP_EQ, cell_stats->removed_cells_exitward[CELL_RELAY]);
  68. done:
  69. tor_free(cell_stats);
  70. tor_free(or_circ);
  71. }
  72. static void
  73. test_cntev_append_cell_stats(void *arg)
  74. {
  75. smartlist_t *event_parts;
  76. char *cp = NULL;
  77. const char *key = "Z";
  78. uint64_t include_if_non_zero[CELL_COMMAND_MAX_ + 1],
  79. number_to_include[CELL_COMMAND_MAX_ + 1];
  80. (void)arg;
  81. event_parts = smartlist_new();
  82. memset(include_if_non_zero, 0,
  83. (CELL_COMMAND_MAX_ + 1) * sizeof(uint64_t));
  84. memset(number_to_include, 0,
  85. (CELL_COMMAND_MAX_ + 1) * sizeof(uint64_t));
  86. /* All array entries empty. */
  87. append_cell_stats_by_command(event_parts, key,
  88. include_if_non_zero,
  89. number_to_include);
  90. tt_int_op(0, OP_EQ, smartlist_len(event_parts));
  91. /* There's a RELAY cell to include, but the corresponding field in
  92. * include_if_non_zero is still zero. */
  93. number_to_include[CELL_RELAY] = 1;
  94. append_cell_stats_by_command(event_parts, key,
  95. include_if_non_zero,
  96. number_to_include);
  97. tt_int_op(0, OP_EQ, smartlist_len(event_parts));
  98. /* Now include single RELAY cell. */
  99. include_if_non_zero[CELL_RELAY] = 2;
  100. append_cell_stats_by_command(event_parts, key,
  101. include_if_non_zero,
  102. number_to_include);
  103. cp = smartlist_pop_last(event_parts);
  104. tt_str_op("Z=relay:1", OP_EQ, cp);
  105. tor_free(cp);
  106. /* Add four CREATE cells. */
  107. include_if_non_zero[CELL_CREATE] = 3;
  108. number_to_include[CELL_CREATE] = 4;
  109. append_cell_stats_by_command(event_parts, key,
  110. include_if_non_zero,
  111. number_to_include);
  112. cp = smartlist_pop_last(event_parts);
  113. tt_str_op("Z=create:4,relay:1", OP_EQ, cp);
  114. done:
  115. tor_free(cp);
  116. smartlist_free(event_parts);
  117. }
  118. static void
  119. test_cntev_format_cell_stats(void *arg)
  120. {
  121. char *event_string = NULL;
  122. origin_circuit_t *ocirc = NULL;
  123. or_circuit_t *or_circ = NULL;
  124. cell_stats_t *cell_stats = NULL;
  125. channel_tls_t *n_chan=NULL, *p_chan=NULL;
  126. (void)arg;
  127. n_chan = tor_malloc_zero(sizeof(channel_tls_t));
  128. n_chan->base_.global_identifier = 1;
  129. ocirc = tor_malloc_zero(sizeof(origin_circuit_t));
  130. ocirc->base_.magic = ORIGIN_CIRCUIT_MAGIC;
  131. ocirc->base_.purpose = CIRCUIT_PURPOSE_C_GENERAL;
  132. ocirc->global_identifier = 2;
  133. ocirc->base_.n_circ_id = 3;
  134. ocirc->base_.n_chan = &(n_chan->base_);
  135. /* Origin circuit was completely idle. */
  136. cell_stats = tor_malloc_zero(sizeof(cell_stats_t));
  137. format_cell_stats(&event_string, TO_CIRCUIT(ocirc), cell_stats);
  138. tt_str_op("ID=2 OutboundQueue=3 OutboundConn=1", OP_EQ, event_string);
  139. tor_free(event_string);
  140. /* Origin circuit had 4 RELAY cells added to its exitward queue. */
  141. cell_stats->added_cells_exitward[CELL_RELAY] = 4;
  142. format_cell_stats(&event_string, TO_CIRCUIT(ocirc), cell_stats);
  143. tt_str_op("ID=2 OutboundQueue=3 OutboundConn=1 OutboundAdded=relay:4",
  144. OP_EQ, event_string);
  145. tor_free(event_string);
  146. /* Origin circuit also had 5 CREATE2 cells added to its exitward
  147. * queue. */
  148. cell_stats->added_cells_exitward[CELL_CREATE2] = 5;
  149. format_cell_stats(&event_string, TO_CIRCUIT(ocirc), cell_stats);
  150. tt_str_op("ID=2 OutboundQueue=3 OutboundConn=1 OutboundAdded=relay:4,"
  151. "create2:5", OP_EQ, event_string);
  152. tor_free(event_string);
  153. /* Origin circuit also had 7 RELAY cells removed from its exitward queue
  154. * which together spent 6 msec in the queue. */
  155. cell_stats->total_time_exitward[CELL_RELAY] = 6;
  156. cell_stats->removed_cells_exitward[CELL_RELAY] = 7;
  157. format_cell_stats(&event_string, TO_CIRCUIT(ocirc), cell_stats);
  158. tt_str_op("ID=2 OutboundQueue=3 OutboundConn=1 OutboundAdded=relay:4,"
  159. "create2:5 OutboundRemoved=relay:7 OutboundTime=relay:6",
  160. OP_EQ, event_string);
  161. tor_free(event_string);
  162. p_chan = tor_malloc_zero(sizeof(channel_tls_t));
  163. p_chan->base_.global_identifier = 2;
  164. or_circ = tor_malloc_zero(sizeof(or_circuit_t));
  165. or_circ->base_.magic = OR_CIRCUIT_MAGIC;
  166. or_circ->base_.purpose = CIRCUIT_PURPOSE_OR;
  167. or_circ->p_circ_id = 8;
  168. or_circ->p_chan = &(p_chan->base_);
  169. or_circ->base_.n_circ_id = 9;
  170. or_circ->base_.n_chan = &(n_chan->base_);
  171. tor_free(cell_stats);
  172. /* OR circuit was idle. */
  173. cell_stats = tor_malloc_zero(sizeof(cell_stats_t));
  174. format_cell_stats(&event_string, TO_CIRCUIT(or_circ), cell_stats);
  175. tt_str_op("InboundQueue=8 InboundConn=2 OutboundQueue=9 OutboundConn=1",
  176. OP_EQ, event_string);
  177. tor_free(event_string);
  178. /* OR circuit had 3 RELAY cells added to its appward queue. */
  179. cell_stats->added_cells_appward[CELL_RELAY] = 3;
  180. format_cell_stats(&event_string, TO_CIRCUIT(or_circ), cell_stats);
  181. tt_str_op("InboundQueue=8 InboundConn=2 InboundAdded=relay:3 "
  182. "OutboundQueue=9 OutboundConn=1", OP_EQ, event_string);
  183. tor_free(event_string);
  184. /* OR circuit had 7 RELAY cells removed from its appward queue which
  185. * together spent 6 msec in the queue. */
  186. cell_stats->total_time_appward[CELL_RELAY] = 6;
  187. cell_stats->removed_cells_appward[CELL_RELAY] = 7;
  188. format_cell_stats(&event_string, TO_CIRCUIT(or_circ), cell_stats);
  189. tt_str_op("InboundQueue=8 InboundConn=2 InboundAdded=relay:3 "
  190. "InboundRemoved=relay:7 InboundTime=relay:6 "
  191. "OutboundQueue=9 OutboundConn=1", OP_EQ, event_string);
  192. done:
  193. tor_free(cell_stats);
  194. tor_free(event_string);
  195. tor_free(or_circ);
  196. tor_free(ocirc);
  197. tor_free(p_chan);
  198. tor_free(n_chan);
  199. }
  200. static void
  201. test_cntev_event_mask(void *arg)
  202. {
  203. unsigned int test_event, selected_event;
  204. (void)arg;
  205. /* Check that nothing is interesting when no events are set */
  206. control_testing_set_global_event_mask(EVENT_MASK_NONE_);
  207. /* Check that nothing is interesting between EVENT_MIN_ and EVENT_MAX_ */
  208. for (test_event = EVENT_MIN_; test_event <= EVENT_MAX_; test_event++)
  209. tt_assert(!control_event_is_interesting(test_event));
  210. /* Check that nothing is interesting outside EVENT_MIN_ to EVENT_MAX_
  211. * This will break if control_event_is_interesting() checks its arguments */
  212. for (test_event = 0; test_event < EVENT_MIN_; test_event++)
  213. tt_assert(!control_event_is_interesting(test_event));
  214. for (test_event = EVENT_MAX_ + 1;
  215. test_event < EVENT_CAPACITY_;
  216. test_event++)
  217. tt_assert(!control_event_is_interesting(test_event));
  218. /* Check that all valid events are interesting when all events are set */
  219. control_testing_set_global_event_mask(EVENT_MASK_ALL_);
  220. /* Check that everything is interesting between EVENT_MIN_ and EVENT_MAX_ */
  221. for (test_event = EVENT_MIN_; test_event <= EVENT_MAX_; test_event++)
  222. tt_assert(control_event_is_interesting(test_event));
  223. /* Check that nothing is interesting outside EVENT_MIN_ to EVENT_MAX_
  224. * This will break if control_event_is_interesting() checks its arguments */
  225. for (test_event = 0; test_event < EVENT_MIN_; test_event++)
  226. tt_assert(!control_event_is_interesting(test_event));
  227. for (test_event = EVENT_MAX_ + 1;
  228. test_event < EVENT_CAPACITY_;
  229. test_event++)
  230. tt_assert(!control_event_is_interesting(test_event));
  231. /* Check that only that event is interesting when a single event is set */
  232. for (selected_event = EVENT_MIN_;
  233. selected_event <= EVENT_MAX_;
  234. selected_event++) {
  235. control_testing_set_global_event_mask(EVENT_MASK_(selected_event));
  236. /* Check that only this event is interesting
  237. * between EVENT_MIN_ and EVENT_MAX_ */
  238. for (test_event = EVENT_MIN_; test_event <= EVENT_MAX_; test_event++) {
  239. if (test_event == selected_event) {
  240. tt_assert(control_event_is_interesting(test_event));
  241. } else {
  242. tt_assert(!control_event_is_interesting(test_event));
  243. }
  244. }
  245. /* Check that nothing is interesting outside EVENT_MIN_ to EVENT_MAX_
  246. * This will break if control_event_is_interesting checks its arguments */
  247. for (test_event = 0; test_event < EVENT_MIN_; test_event++)
  248. tt_assert(!control_event_is_interesting(test_event));
  249. for (test_event = EVENT_MAX_ + 1;
  250. test_event < EVENT_CAPACITY_;
  251. test_event++)
  252. tt_assert(!control_event_is_interesting(test_event));
  253. }
  254. /* Check that only that event is not-interesting
  255. * when a single event is un-set */
  256. for (selected_event = EVENT_MIN_;
  257. selected_event <= EVENT_MAX_;
  258. selected_event++) {
  259. control_testing_set_global_event_mask(
  260. EVENT_MASK_ALL_
  261. & ~(EVENT_MASK_(selected_event))
  262. );
  263. /* Check that only this event is not-interesting
  264. * between EVENT_MIN_ and EVENT_MAX_ */
  265. for (test_event = EVENT_MIN_; test_event <= EVENT_MAX_; test_event++) {
  266. if (test_event == selected_event) {
  267. tt_assert(!control_event_is_interesting(test_event));
  268. } else {
  269. tt_assert(control_event_is_interesting(test_event));
  270. }
  271. }
  272. /* Check that nothing is interesting outside EVENT_MIN_ to EVENT_MAX_
  273. * This will break if control_event_is_interesting checks its arguments */
  274. for (test_event = 0; test_event < EVENT_MIN_; test_event++)
  275. tt_assert(!control_event_is_interesting(test_event));
  276. for (test_event = EVENT_MAX_ + 1;
  277. test_event < EVENT_CAPACITY_;
  278. test_event++)
  279. tt_assert(!control_event_is_interesting(test_event));
  280. }
  281. done:
  282. ;
  283. }
  284. static char *saved_event_str = NULL;
  285. static void
  286. mock_queue_control_event_string(uint16_t event, char *msg)
  287. {
  288. (void)event;
  289. tor_free(saved_event_str);
  290. saved_event_str = msg;
  291. }
  292. /* Helper macro for checking bootstrap control event strings */
  293. #define assert_bootmsg(s) \
  294. tt_ptr_op(strstr(saved_event_str, "650 STATUS_CLIENT NOTICE " \
  295. "BOOTSTRAP PROGRESS=" s), OP_EQ, saved_event_str)
  296. /* Test deferral of directory bootstrap messages (requesting_descriptors) */
  297. static void
  298. test_cntev_dirboot_defer_desc(void *arg)
  299. {
  300. (void)arg;
  301. MOCK(queue_control_event_string, mock_queue_control_event_string);
  302. control_testing_set_global_event_mask(EVENT_MASK_(EVENT_STATUS_CLIENT));
  303. control_event_bootstrap(BOOTSTRAP_STATUS_STARTING, 0);
  304. assert_bootmsg("0 TAG=starting");
  305. /* This event should get deferred */
  306. control_event_boot_dir(BOOTSTRAP_STATUS_REQUESTING_DESCRIPTORS, 0);
  307. assert_bootmsg("0 TAG=starting");
  308. control_event_bootstrap(BOOTSTRAP_STATUS_CONN, 0);
  309. assert_bootmsg("5 TAG=conn");
  310. control_event_bootstrap(BOOTSTRAP_STATUS_HANDSHAKE, 0);
  311. assert_bootmsg("14 TAG=handshake");
  312. /* The deferred event should appear */
  313. control_event_boot_first_orconn();
  314. assert_bootmsg("45 TAG=requesting_descriptors");
  315. done:
  316. tor_free(saved_event_str);
  317. UNMOCK(queue_control_event_string);
  318. }
  319. /* Test deferral of directory bootstrap messages (conn_or) */
  320. static void
  321. test_cntev_dirboot_defer_orconn(void *arg)
  322. {
  323. (void)arg;
  324. MOCK(queue_control_event_string, mock_queue_control_event_string);
  325. control_testing_set_global_event_mask(EVENT_MASK_(EVENT_STATUS_CLIENT));
  326. control_event_bootstrap(BOOTSTRAP_STATUS_STARTING, 0);
  327. assert_bootmsg("0 TAG=starting");
  328. /* This event should get deferred */
  329. control_event_boot_dir(BOOTSTRAP_STATUS_ENOUGH_DIRINFO, 0);
  330. assert_bootmsg("0 TAG=starting");
  331. control_event_bootstrap(BOOTSTRAP_STATUS_CONN, 0);
  332. assert_bootmsg("5 TAG=conn");
  333. control_event_bootstrap(BOOTSTRAP_STATUS_HANDSHAKE, 0);
  334. assert_bootmsg("14 TAG=handshake");
  335. /* The deferred event should appear */
  336. control_event_boot_first_orconn();
  337. assert_bootmsg("75 TAG=enough_dirinfo");
  338. done:
  339. tor_free(saved_event_str);
  340. UNMOCK(queue_control_event_string);
  341. }
  342. static void
  343. setup_orconn_state(orconn_event_msg_t *msg, uint64_t gid, uint64_t chan,
  344. int proxy_type)
  345. {
  346. msg->type = ORCONN_MSGTYPE_STATE;
  347. msg->u.state.gid = gid;
  348. msg->u.state.chan = chan;
  349. msg->u.state.proxy_type = proxy_type;
  350. }
  351. static void
  352. send_orconn_state(orconn_event_msg_t *msg, uint8_t state)
  353. {
  354. msg->u.state.state = state;
  355. orconn_event_publish(msg);
  356. }
  357. static void
  358. send_ocirc_chan(uint32_t gid, uint64_t chan, bool onehop)
  359. {
  360. ocirc_event_msg_t msg;
  361. msg.type = OCIRC_MSGTYPE_CHAN;
  362. msg.u.chan.gid = gid;
  363. msg.u.chan.chan = chan;
  364. msg.u.chan.onehop = onehop;
  365. ocirc_event_publish(&msg);
  366. }
  367. static void
  368. test_cntev_orconn_state(void *arg)
  369. {
  370. orconn_event_msg_t conn;
  371. (void)arg;
  372. MOCK(queue_control_event_string, mock_queue_control_event_string);
  373. control_testing_set_global_event_mask(EVENT_MASK_(EVENT_STATUS_CLIENT));
  374. setup_orconn_state(&conn, 1, 1, PROXY_NONE);
  375. send_orconn_state(&conn, OR_CONN_STATE_CONNECTING);
  376. send_ocirc_chan(1, 1, true);
  377. assert_bootmsg("5 TAG=conn");
  378. send_orconn_state(&conn, OR_CONN_STATE_TLS_HANDSHAKING);
  379. assert_bootmsg("10 TAG=conn_done");
  380. send_orconn_state(&conn, OR_CONN_STATE_OR_HANDSHAKING_V3);
  381. assert_bootmsg("14 TAG=handshake");
  382. send_orconn_state(&conn, OR_CONN_STATE_OPEN);
  383. assert_bootmsg("15 TAG=handshake_done");
  384. conn.u.state.gid = 2;
  385. conn.u.state.chan = 2;
  386. send_orconn_state(&conn, OR_CONN_STATE_CONNECTING);
  387. /* It doesn't know it's an origin circuit yet */
  388. assert_bootmsg("15 TAG=handshake_done");
  389. send_ocirc_chan(2, 2, false);
  390. assert_bootmsg("80 TAG=ap_conn");
  391. send_orconn_state(&conn, OR_CONN_STATE_TLS_HANDSHAKING);
  392. assert_bootmsg("85 TAG=ap_conn_done");
  393. send_orconn_state(&conn, OR_CONN_STATE_OR_HANDSHAKING_V3);
  394. assert_bootmsg("89 TAG=ap_handshake");
  395. send_orconn_state(&conn, OR_CONN_STATE_OPEN);
  396. assert_bootmsg("90 TAG=ap_handshake_done");
  397. done:
  398. tor_free(saved_event_str);
  399. UNMOCK(queue_control_event_string);
  400. }
  401. static void
  402. test_cntev_orconn_state_pt(void *arg)
  403. {
  404. orconn_event_msg_t conn;
  405. (void)arg;
  406. MOCK(queue_control_event_string, mock_queue_control_event_string);
  407. control_testing_set_global_event_mask(EVENT_MASK_(EVENT_STATUS_CLIENT));
  408. setup_orconn_state(&conn, 1, 1, PROXY_PLUGGABLE);
  409. send_ocirc_chan(1, 1, true);
  410. send_orconn_state(&conn, OR_CONN_STATE_CONNECTING);
  411. assert_bootmsg("1 TAG=conn_pt");
  412. send_orconn_state(&conn, OR_CONN_STATE_PROXY_HANDSHAKING);
  413. assert_bootmsg("2 TAG=conn_done_pt");
  414. send_orconn_state(&conn, OR_CONN_STATE_TLS_HANDSHAKING);
  415. assert_bootmsg("10 TAG=conn_done");
  416. send_orconn_state(&conn, OR_CONN_STATE_OR_HANDSHAKING_V3);
  417. assert_bootmsg("14 TAG=handshake");
  418. send_orconn_state(&conn, OR_CONN_STATE_OPEN);
  419. assert_bootmsg("15 TAG=handshake_done");
  420. send_ocirc_chan(2, 2, false);
  421. conn.u.state.gid = 2;
  422. conn.u.state.chan = 2;
  423. send_orconn_state(&conn, OR_CONN_STATE_CONNECTING);
  424. assert_bootmsg("76 TAG=ap_conn_pt");
  425. send_orconn_state(&conn, OR_CONN_STATE_PROXY_HANDSHAKING);
  426. assert_bootmsg("77 TAG=ap_conn_done_pt");
  427. done:
  428. tor_free(saved_event_str);
  429. UNMOCK(queue_control_event_string);
  430. }
  431. static void
  432. test_cntev_orconn_state_proxy(void *arg)
  433. {
  434. orconn_event_msg_t conn;
  435. (void)arg;
  436. MOCK(queue_control_event_string, mock_queue_control_event_string);
  437. control_testing_set_global_event_mask(EVENT_MASK_(EVENT_STATUS_CLIENT));
  438. setup_orconn_state(&conn, 1, 1, PROXY_CONNECT);
  439. send_ocirc_chan(1, 1, true);
  440. send_orconn_state(&conn, OR_CONN_STATE_CONNECTING);
  441. assert_bootmsg("3 TAG=conn_proxy");
  442. send_orconn_state(&conn, OR_CONN_STATE_PROXY_HANDSHAKING);
  443. assert_bootmsg("4 TAG=conn_done_proxy");
  444. send_orconn_state(&conn, OR_CONN_STATE_TLS_HANDSHAKING);
  445. assert_bootmsg("10 TAG=conn_done");
  446. send_orconn_state(&conn, OR_CONN_STATE_OR_HANDSHAKING_V3);
  447. assert_bootmsg("14 TAG=handshake");
  448. send_orconn_state(&conn, OR_CONN_STATE_OPEN);
  449. assert_bootmsg("15 TAG=handshake_done");
  450. send_ocirc_chan(2, 2, false);
  451. conn.u.state.gid = 2;
  452. conn.u.state.chan = 2;
  453. send_orconn_state(&conn, OR_CONN_STATE_CONNECTING);
  454. assert_bootmsg("78 TAG=ap_conn_proxy");
  455. send_orconn_state(&conn, OR_CONN_STATE_PROXY_HANDSHAKING);
  456. assert_bootmsg("79 TAG=ap_conn_done_proxy");
  457. done:
  458. tor_free(saved_event_str);
  459. UNMOCK(queue_control_event_string);
  460. }
  461. #define TEST(name, flags) \
  462. { #name, test_cntev_ ## name, flags, 0, NULL }
  463. struct testcase_t controller_event_tests[] = {
  464. TEST(sum_up_cell_stats, TT_FORK),
  465. TEST(append_cell_stats, TT_FORK),
  466. TEST(format_cell_stats, TT_FORK),
  467. TEST(event_mask, TT_FORK),
  468. TEST(dirboot_defer_desc, TT_FORK),
  469. TEST(dirboot_defer_orconn, TT_FORK),
  470. TEST(orconn_state, TT_FORK),
  471. TEST(orconn_state_pt, TT_FORK),
  472. TEST(orconn_state_proxy, TT_FORK),
  473. END_OF_TESTCASES
  474. };