test_btrack.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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_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. (void)arg;
  38. conn.gid = 1;
  39. conn.chan = 1;
  40. conn.proxy_type = PROXY_NONE;
  41. conn.state = OR_CONN_STATE_CONNECTING;
  42. setup_full_capture_of_logs(LOG_DEBUG);
  43. send_state(&conn);
  44. expect_log_msg_containing("ORCONN gid=1 chan=1 proxy_type=0 state=1");
  45. expect_no_log_msg_containing("ORCONN BEST_");
  46. teardown_capture_of_logs();
  47. circ.chan = 1;
  48. circ.onehop = true;
  49. setup_full_capture_of_logs(LOG_DEBUG);
  50. send_chan(&circ);
  51. expect_log_msg_containing("ORCONN LAUNCH chan=1 onehop=1");
  52. expect_log_msg_containing("ORCONN BEST_ANY state -1->1 gid=1");
  53. teardown_capture_of_logs();
  54. conn.gid = 2;
  55. conn.chan = 2;
  56. setup_full_capture_of_logs(LOG_DEBUG);
  57. send_state(&conn);
  58. expect_log_msg_containing("ORCONN gid=2 chan=2 proxy_type=0 state=1");
  59. expect_no_log_msg_containing("ORCONN BEST_");
  60. teardown_capture_of_logs();
  61. circ.chan = 2;
  62. circ.onehop = false;
  63. setup_full_capture_of_logs(LOG_DEBUG);
  64. send_chan(&circ);
  65. expect_log_msg_containing("ORCONN LAUNCH chan=2 onehop=0");
  66. expect_log_msg_containing("ORCONN BEST_AP state -1->1 gid=2");
  67. teardown_capture_of_logs();
  68. done:
  69. ;
  70. }
  71. static void
  72. test_btrack_delete(void *arg)
  73. {
  74. orconn_state_msg_t state;
  75. orconn_status_msg_t status;
  76. (void)arg;
  77. state.gid = 1;
  78. state.chan = 1;
  79. state.proxy_type = PROXY_NONE;
  80. state.state = OR_CONN_STATE_CONNECTING;
  81. setup_full_capture_of_logs(LOG_DEBUG);
  82. send_state(&state);
  83. expect_log_msg_containing("ORCONN gid=1 chan=1 proxy_type=0");
  84. teardown_capture_of_logs();
  85. status.gid = 1;
  86. status.status = OR_CONN_EVENT_CLOSED;
  87. status.reason = 0;
  88. setup_full_capture_of_logs(LOG_DEBUG);
  89. send_status(&status);
  90. expect_log_msg_containing("ORCONN DELETE gid=1 status=3 reason=0");
  91. teardown_capture_of_logs();
  92. done:
  93. ;
  94. }
  95. struct testcase_t btrack_tests[] = {
  96. { "launch", test_btrack_launch, TT_FORK, &helper_pubsub_setup, NULL },
  97. { "delete", test_btrack_delete, TT_FORK, &helper_pubsub_setup, NULL },
  98. END_OF_TESTCASES
  99. };