tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

test_btrack.c (3033B)


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