test_controller_events.c 19 KB

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