test_btrack.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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/log_test_helpers.h"
  6. #define OCIRC_EVENT_PRIVATE
  7. #define ORCONN_EVENT_PRIVATE
  8. #include "core/or/ocirc_event.h"
  9. #include "core/or/orconn_event.h"
  10. static void
  11. test_btrack_launch(void *arg)
  12. {
  13. orconn_event_msg_t conn;
  14. ocirc_event_msg_t circ;
  15. (void)arg;
  16. conn.type = ORCONN_MSGTYPE_STATE;
  17. conn.u.state.gid = 1;
  18. conn.u.state.chan = 1;
  19. conn.u.state.proxy_type = PROXY_NONE;
  20. conn.u.state.state = OR_CONN_STATE_CONNECTING;
  21. setup_full_capture_of_logs(LOG_DEBUG);
  22. orconn_event_publish(&conn);
  23. expect_log_msg_containing("ORCONN gid=1 chan=1 proxy_type=0 state=1");
  24. expect_no_log_msg_containing("ORCONN BEST_");
  25. teardown_capture_of_logs();
  26. circ.type = OCIRC_MSGTYPE_CHAN;
  27. circ.u.chan.chan = 1;
  28. circ.u.chan.onehop = true;
  29. setup_full_capture_of_logs(LOG_DEBUG);
  30. ocirc_event_publish(&circ);
  31. expect_log_msg_containing("ORCONN LAUNCH chan=1 onehop=1");
  32. expect_log_msg_containing("ORCONN BEST_ANY state -1->1 gid=1");
  33. teardown_capture_of_logs();
  34. conn.u.state.gid = 2;
  35. conn.u.state.chan = 2;
  36. setup_full_capture_of_logs(LOG_DEBUG);
  37. orconn_event_publish(&conn);
  38. expect_log_msg_containing("ORCONN gid=2 chan=2 proxy_type=0 state=1");
  39. expect_no_log_msg_containing("ORCONN BEST_");
  40. teardown_capture_of_logs();
  41. circ.u.chan.chan = 2;
  42. circ.u.chan.onehop = false;
  43. setup_full_capture_of_logs(LOG_DEBUG);
  44. ocirc_event_publish(&circ);
  45. expect_log_msg_containing("ORCONN LAUNCH chan=2 onehop=0");
  46. expect_log_msg_containing("ORCONN BEST_AP state -1->1 gid=2");
  47. teardown_capture_of_logs();
  48. done:
  49. ;
  50. }
  51. static void
  52. test_btrack_delete(void *arg)
  53. {
  54. orconn_event_msg_t conn;
  55. (void)arg;
  56. conn.type = ORCONN_MSGTYPE_STATE;
  57. conn.u.state.gid = 1;
  58. conn.u.state.chan = 1;
  59. conn.u.state.proxy_type = PROXY_NONE;
  60. conn.u.state.state = OR_CONN_STATE_CONNECTING;
  61. setup_full_capture_of_logs(LOG_DEBUG);
  62. orconn_event_publish(&conn);
  63. expect_log_msg_containing("ORCONN gid=1 chan=1 proxy_type=0");
  64. teardown_capture_of_logs();
  65. conn.type = ORCONN_MSGTYPE_STATUS;
  66. conn.u.status.gid = 1;
  67. conn.u.status.status = OR_CONN_EVENT_CLOSED;
  68. conn.u.status.reason = 0;
  69. setup_full_capture_of_logs(LOG_DEBUG);
  70. orconn_event_publish(&conn);
  71. expect_log_msg_containing("ORCONN DELETE gid=1 status=3 reason=0");
  72. teardown_capture_of_logs();
  73. done:
  74. ;
  75. }
  76. struct testcase_t btrack_tests[] = {
  77. { "launch", test_btrack_launch, TT_FORK, 0, NULL },
  78. { "delete", test_btrack_delete, TT_FORK, 0, NULL },
  79. END_OF_TESTCASES
  80. };