#define TOR_CHANNEL_INTERNAL_
#define MAIN_PRIVATE
#define NETWORKSTATUS_PRIVATE
+#define TOR_TIMERS_PRIVATE
#include "or.h"
#include "test.h"
#include "testsupport.h"
void dummy_nop_timer(void);
+#define NSEC_PER_MSEC (1000*1000)
+
/* Thing to cast to fake tor_tls_t * to appease assert_connection_ok() */
static int fake_tortls = 0; /* Bleh... */
channelpadding_decision_t decision;
or_options_t *options = get_options_mutable();
int64_t val;
+ int64_t new_time;
(void)arg;
tor_libevent_postfork();
*/
channel_t *chan;
routerstatus_t *relay = tor_malloc_zero(sizeof(routerstatus_t));
- monotime_init();
+ monotime_enable_test_mocking();
+ monotime_set_mock_time_nsec(1);
+ monotime_coarse_set_mock_time_nsec(1);
timers_initialize();
connection_array = smartlist_new();
tt_int_op(decision, OP_EQ, CHANNELPADDING_PADDING_ALREADY_SCHEDULED);
// Wait for the timer
- event_base_loop(tor_libevent_get_base(), 0);
+ new_time = (monotime_coarse_absolute_msec()+101)*NSEC_PER_MSEC;
+ monotime_coarse_set_mock_time_nsec(new_time);
+ monotime_set_mock_time_nsec(new_time);
+ timers_run_pending();
tt_int_op(tried_to_write_cell, OP_EQ, 1);
tt_assert(!chan->pending_padding_callback);
tt_i64_op(val, OP_LE, 200);
// Wait for the timer
- event_base_loop(tor_libevent_get_base(), 0);
+ new_time = (monotime_coarse_absolute_msec()+201)*NSEC_PER_MSEC;
+ monotime_set_mock_time_nsec(new_time);
+ monotime_coarse_set_mock_time_nsec(new_time);
+ timers_run_pending();
tt_int_op(tried_to_write_cell, OP_EQ, 1);
tt_assert(!chan->pending_padding_callback);
tor_free(current_ns_consensus);
timers_shutdown();
+ monotime_disable_test_mocking();
channel_free_all();
return;
* + We should not send padding
*/
channel_t *chan;
+ int64_t new_time;
connection_array = smartlist_new();
(void)arg;
tor_libevent_postfork();
monotime_init();
+ monotime_enable_test_mocking();
+ monotime_set_mock_time_nsec(1);
+ monotime_coarse_set_mock_time_nsec(1);
timers_initialize();
setup_full_capture_of_logs(LOG_WARN);
channelpadding_new_consensus_params(NULL);
tt_int_op(tried_to_write_cell, OP_EQ, 0);
// Wait for the timer from case #2b
- event_base_loop(tor_libevent_get_base(), 0);
+ new_time = (monotime_coarse_absolute_msec() + 1000)*NSEC_PER_MSEC;
+ monotime_set_mock_time_nsec(new_time);
+ monotime_coarse_set_mock_time_nsec(new_time);
+ timers_run_pending();
tt_int_op(tried_to_write_cell, OP_EQ, 1);
tt_assert(!chan->pending_padding_callback);
tt_int_op(decision, OP_EQ, CHANNELPADDING_PADDING_ALREADY_SCHEDULED);
// Wait for the timer
- event_base_loop(tor_libevent_get_base(), 0);
+ new_time = (monotime_coarse_absolute_msec()+101)*NSEC_PER_MSEC;
+ monotime_coarse_set_mock_time_nsec(new_time);
+ monotime_set_mock_time_nsec(new_time);
+ timers_run_pending();
tt_int_op(tried_to_write_cell, OP_EQ, 1);
tt_assert(!chan->pending_padding_callback);
channel_timestamp_active(chan);
// We don't expect any timer callbacks here. Make a dummy one to be sure.
- dummy_nop_timer();
+ // Wait for the timer
+ new_time = (monotime_coarse_absolute_msec()+101)*NSEC_PER_MSEC;
+ monotime_coarse_set_mock_time_nsec(new_time);
+ monotime_set_mock_time_nsec(new_time);
+ timers_run_pending();
tt_int_op(tried_to_write_cell, OP_EQ, 0);
tt_assert(!chan->pending_padding_callback);
chan->state = CHANNEL_STATE_MAINT;
// We don't expect any timer callbacks here. Make a dummy one to be sure.
- dummy_nop_timer();
+ new_time = (monotime_coarse_absolute_msec()+101)*NSEC_PER_MSEC;
+ monotime_coarse_set_mock_time_nsec(new_time);
+ monotime_set_mock_time_nsec(new_time);
+ timers_run_pending();
tt_int_op(tried_to_write_cell, OP_EQ, 0);
tt_assert(!chan->pending_padding_callback);
tt_int_op(tried_to_write_cell, OP_EQ, 0);
// Wait for the timer
- event_base_loop(tor_libevent_get_base(), 0);
+ new_time = (monotime_coarse_absolute_msec()+101)*NSEC_PER_MSEC;
+ monotime_coarse_set_mock_time_nsec(new_time);
+ monotime_set_mock_time_nsec(new_time);
+ timers_run_pending();
+
tt_int_op(tried_to_write_cell, OP_EQ, 1);
tt_assert(!chan->pending_padding_callback);
free_fake_channeltls((channel_tls_t*)chan);
// We don't expect any timer callbacks here. Make a dummy one to be sure.
- dummy_nop_timer();
+ new_time = (monotime_coarse_absolute_msec()+101)*NSEC_PER_MSEC;
+ monotime_coarse_set_mock_time_nsec(new_time);
+ monotime_set_mock_time_nsec(new_time);
+ timers_run_pending();
tt_int_op(tried_to_write_cell, OP_EQ, 0);
smartlist_free(connection_array);
teardown_capture_of_logs();
+ monotime_disable_test_mocking();
timers_shutdown();
channel_free_all();