test_controller_events.c 19 KB

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