test_btrack.c 2.7 KB

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