test_btrack.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* Copyright (c) 2013-2019, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. #include "core/or/or.h"
  4. #include "test/test.h"
  5. #include "test/test_helpers.h"
  6. #include "test/log_test_helpers.h"
  7. #define OCIRC_EVENT_PRIVATE
  8. #define ORCONN_EVENT_PRIVATE
  9. #include "core/or/ocirc_event.h"
  10. #include "core/or/orconn_event.h"
  11. static void
  12. send_state(const orconn_state_msg_t *msg_in)
  13. {
  14. orconn_state_msg_t *msg = tor_malloc(sizeof(*msg));
  15. *msg = *msg_in;
  16. orconn_state_publish(msg);
  17. }
  18. static void
  19. send_status(const orconn_status_msg_t *msg_in)
  20. {
  21. orconn_status_msg_t *msg = tor_malloc(sizeof(*msg));
  22. *msg = *msg_in;
  23. orconn_status_publish(msg);
  24. }
  25. static void
  26. send_chan(const ocirc_chan_msg_t *msg_in)
  27. {
  28. ocirc_chan_msg_t *msg = tor_malloc(sizeof(*msg));
  29. *msg = *msg_in;
  30. ocirc_chan_publish(msg);
  31. }
  32. static void
  33. test_btrack_launch(void *arg)
  34. {
  35. orconn_state_msg_t conn;
  36. ocirc_chan_msg_t circ;
  37. memset(&conn, 0, sizeof(conn));
  38. memset(&circ, 0, sizeof(circ));
  39. (void)arg;
  40. conn.gid = 1;
  41. conn.chan = 1;
  42. conn.proxy_type = PROXY_NONE;
  43. conn.state = OR_CONN_STATE_CONNECTING;
  44. setup_full_capture_of_logs(LOG_DEBUG);
  45. send_state(&conn);
  46. expect_log_msg_containing("ORCONN gid=1 chan=1 proxy_type=0 state=1");
  47. expect_no_log_msg_containing("ORCONN BEST_");
  48. teardown_capture_of_logs();
  49. circ.chan = 1;
  50. circ.onehop = true;
  51. setup_full_capture_of_logs(LOG_DEBUG);
  52. send_chan(&circ);
  53. expect_log_msg_containing("ORCONN LAUNCH chan=1 onehop=1");
  54. expect_log_msg_containing("ORCONN BEST_ANY state -1->1 gid=1");
  55. teardown_capture_of_logs();
  56. conn.gid = 2;
  57. conn.chan = 2;
  58. setup_full_capture_of_logs(LOG_DEBUG);
  59. send_state(&conn);
  60. expect_log_msg_containing("ORCONN gid=2 chan=2 proxy_type=0 state=1");
  61. expect_no_log_msg_containing("ORCONN BEST_");
  62. teardown_capture_of_logs();
  63. circ.chan = 2;
  64. circ.onehop = false;
  65. setup_full_capture_of_logs(LOG_DEBUG);
  66. send_chan(&circ);
  67. expect_log_msg_containing("ORCONN LAUNCH chan=2 onehop=0");
  68. expect_log_msg_containing("ORCONN BEST_AP state -1->1 gid=2");
  69. teardown_capture_of_logs();
  70. done:
  71. ;
  72. }
  73. static void
  74. test_btrack_delete(void *arg)
  75. {
  76. orconn_state_msg_t state;
  77. orconn_status_msg_t status;
  78. memset(&state, 0, sizeof(state));
  79. memset(&status, 0, sizeof(status));
  80. (void)arg;
  81. state.gid = 1;
  82. state.chan = 1;
  83. state.proxy_type = PROXY_NONE;
  84. state.state = OR_CONN_STATE_CONNECTING;
  85. setup_full_capture_of_logs(LOG_DEBUG);
  86. send_state(&state);
  87. expect_log_msg_containing("ORCONN gid=1 chan=1 proxy_type=0");
  88. teardown_capture_of_logs();
  89. status.gid = 1;
  90. status.status = OR_CONN_EVENT_CLOSED;
  91. status.reason = 0;
  92. setup_full_capture_of_logs(LOG_DEBUG);
  93. send_status(&status);
  94. expect_log_msg_containing("ORCONN DELETE gid=1 status=3 reason=0");
  95. teardown_capture_of_logs();
  96. done:
  97. ;
  98. }
  99. struct testcase_t btrack_tests[] = {
  100. { "launch", test_btrack_launch, TT_FORK, &helper_pubsub_setup, NULL },
  101. { "delete", test_btrack_delete, TT_FORK, &helper_pubsub_setup, NULL },
  102. END_OF_TESTCASES
  103. };