LCOV - code coverage report
Current view: top level - test - test_btrack.c (source / functions) Hit Total Coverage
Test: lcov.info Lines: 78 78 100.0 %
Date: 2021-11-24 03:28:48 Functions: 5 5 100.0 %

          Line data    Source code
       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           3 : send_state(const orconn_state_msg_t *msg_in)
      17             : {
      18           3 :   orconn_state_msg_t *msg = tor_malloc(sizeof(*msg));
      19             : 
      20           3 :   *msg = *msg_in;
      21           3 :   orconn_state_publish(msg);
      22           3 : }
      23             : 
      24             : static void
      25           1 : send_status(const orconn_status_msg_t *msg_in)
      26             : {
      27           1 :   orconn_status_msg_t *msg = tor_malloc(sizeof(*msg));
      28             : 
      29           1 :   *msg = *msg_in;
      30           1 :   orconn_status_publish(msg);
      31           1 : }
      32             : 
      33             : static void
      34           2 : send_chan(const ocirc_chan_msg_t *msg_in)
      35             : {
      36           2 :   ocirc_chan_msg_t *msg = tor_malloc(sizeof(*msg));
      37             : 
      38           2 :   *msg = *msg_in;
      39           2 :   ocirc_chan_publish(msg);
      40           2 : }
      41             : 
      42             : static void
      43           1 : test_btrack_launch(void *arg)
      44             : {
      45           1 :   orconn_state_msg_t conn;
      46           1 :   ocirc_chan_msg_t circ;
      47           1 :   memset(&conn, 0, sizeof(conn));
      48           1 :   memset(&circ, 0, sizeof(circ));
      49             : 
      50           1 :   (void)arg;
      51           1 :   conn.gid = 1;
      52           1 :   conn.chan = 1;
      53           1 :   conn.proxy_type = PROXY_NONE;
      54           1 :   conn.state = OR_CONN_STATE_CONNECTING;
      55             : 
      56           1 :   setup_full_capture_of_logs(LOG_DEBUG);
      57           1 :   send_state(&conn);
      58           1 :   expect_log_msg_containing("ORCONN gid=1 chan=1 proxy_type=0 state=1");
      59           1 :   expect_no_log_msg_containing("ORCONN BEST_");
      60           1 :   teardown_capture_of_logs();
      61             : 
      62           1 :   circ.chan = 1;
      63           1 :   circ.onehop = true;
      64             : 
      65           1 :   setup_full_capture_of_logs(LOG_DEBUG);
      66           1 :   send_chan(&circ);
      67           1 :   expect_log_msg_containing("ORCONN LAUNCH chan=1 onehop=1");
      68           1 :   expect_log_msg_containing("ORCONN BEST_ANY state -1->1 gid=1");
      69           1 :   teardown_capture_of_logs();
      70             : 
      71           1 :   conn.gid = 2;
      72           1 :   conn.chan = 2;
      73             : 
      74           1 :   setup_full_capture_of_logs(LOG_DEBUG);
      75           1 :   send_state(&conn);
      76           1 :   expect_log_msg_containing("ORCONN gid=2 chan=2 proxy_type=0 state=1");
      77           1 :   expect_no_log_msg_containing("ORCONN BEST_");
      78           1 :   teardown_capture_of_logs();
      79             : 
      80           1 :   circ.chan = 2;
      81           1 :   circ.onehop = false;
      82             : 
      83           1 :   setup_full_capture_of_logs(LOG_DEBUG);
      84           1 :   send_chan(&circ);
      85           1 :   expect_log_msg_containing("ORCONN LAUNCH chan=2 onehop=0");
      86           1 :   expect_log_msg_containing("ORCONN BEST_AP state -1->1 gid=2");
      87           1 :   teardown_capture_of_logs();
      88             : 
      89           1 :  done:
      90           1 :   ;
      91           1 : }
      92             : 
      93             : static void
      94           1 : test_btrack_delete(void *arg)
      95             : {
      96           1 :   orconn_state_msg_t state;
      97           1 :   orconn_status_msg_t status;
      98           1 :   memset(&state, 0, sizeof(state));
      99           1 :   memset(&status, 0, sizeof(status));
     100             : 
     101           1 :   (void)arg;
     102           1 :   state.gid = 1;
     103           1 :   state.chan = 1;
     104           1 :   state.proxy_type = PROXY_NONE;
     105           1 :   state.state = OR_CONN_STATE_CONNECTING;
     106             : 
     107           1 :   setup_full_capture_of_logs(LOG_DEBUG);
     108           1 :   send_state(&state);
     109           1 :   expect_log_msg_containing("ORCONN gid=1 chan=1 proxy_type=0");
     110           1 :   teardown_capture_of_logs();
     111             : 
     112           1 :   status.gid = 1;
     113           1 :   status.status = OR_CONN_EVENT_CLOSED;
     114           1 :   status.reason = 0;
     115             : 
     116           1 :   setup_full_capture_of_logs(LOG_DEBUG);
     117           1 :   send_status(&status);
     118           1 :   expect_log_msg_containing("ORCONN DELETE gid=1 status=3 reason=0");
     119           1 :   teardown_capture_of_logs();
     120             : 
     121           1 :  done:
     122           1 :   ;
     123           1 : }
     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             : };

Generated by: LCOV version 1.14