From 1f48c6cd83d66c904e7339e1ff60f5e7c5f6bbf4 Mon Sep 17 00:00:00 2001 From: Mike Perry Date: Wed, 27 Feb 2019 00:27:22 +0000 Subject: Bug 29500: Attempt to fix the tokens test. Cancel the padding timer by changing order of sent vs recv (sent cancels). --- src/test/test_circuitpadding.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/test_circuitpadding.c b/src/test/test_circuitpadding.c index eee1edc50c..077529a0dc 100644 --- a/src/test/test_circuitpadding.c +++ b/src/test/test_circuitpadding.c @@ -1004,9 +1004,8 @@ test_circuitpadding_tokens(void *arg) mi = client_side->padding_info[0]; // Pretend a non-padding cell was sent - // XXX: This messes us up.. Padding gets scheduled.. - circpad_cell_event_nonpadding_sent((circuit_t*)client_side); circpad_cell_event_nonpadding_received((circuit_t*)client_side); + circpad_cell_event_nonpadding_sent((circuit_t*)client_side); /* We have to save the infinity bin because one inf delay * could have been chosen when we transition to burst */ circpad_hist_token_t inf_bin = mi->histogram[4]; @@ -1105,7 +1104,8 @@ test_circuitpadding_tokens(void *arg) /* 2.c. Bin 0 */ { - tt_int_op(mi->histogram[0], OP_EQ, 1); + tt_int_op(mi->histogram[0], OP_EQ, 0); + mi->histogram[0] = 1; circpad_machine_remove_higher_token(mi, state->start_usec/2); tt_int_op(mi->histogram[0], OP_EQ, 0); -- cgit v1.2.3-54-g00ecf From b027b06dbbbfcac6be91a9a89bda0b0949bd8b7d Mon Sep 17 00:00:00 2001 From: Mike Perry Date: Mon, 4 Mar 2019 21:54:19 +0000 Subject: Bug 29500: Start monotime at 1000 nsec. Hopefully this will stop monotime_absolute_usec() from returning 0 on some platforms in the tests. --- src/test/test_circuitpadding.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/test/test_circuitpadding.c b/src/test/test_circuitpadding.c index 077529a0dc..cd150b0646 100644 --- a/src/test/test_circuitpadding.c +++ b/src/test/test_circuitpadding.c @@ -300,9 +300,9 @@ test_circuitpadding_rtt(void *arg) monotime_init(); monotime_enable_test_mocking(); - monotime_set_mock_time_nsec(1*TOR_NSEC_PER_USEC); - monotime_coarse_set_mock_time_nsec(1*TOR_NSEC_PER_USEC); - curr_mocked_time = 1*TOR_NSEC_PER_USEC; + monotime_set_mock_time_nsec(1000*TOR_NSEC_PER_USEC); + monotime_coarse_set_mock_time_nsec(1000*TOR_NSEC_PER_USEC); + curr_mocked_time = 1000*TOR_NSEC_PER_USEC; timers_initialize(); circpad_machines_init(); @@ -990,9 +990,9 @@ test_circuitpadding_tokens(void *arg) monotime_init(); monotime_enable_test_mocking(); - monotime_set_mock_time_nsec(1*TOR_NSEC_PER_USEC); - monotime_coarse_set_mock_time_nsec(1*TOR_NSEC_PER_USEC); - curr_mocked_time = 1*TOR_NSEC_PER_USEC; + monotime_set_mock_time_nsec(1000*TOR_NSEC_PER_USEC); + monotime_coarse_set_mock_time_nsec(1000*TOR_NSEC_PER_USEC); + curr_mocked_time = 1000*TOR_NSEC_PER_USEC; timers_initialize(); @@ -1254,9 +1254,9 @@ test_circuitpadding_wronghop(void *arg) monotime_init(); monotime_enable_test_mocking(); - monotime_set_mock_time_nsec(1*TOR_NSEC_PER_USEC); - monotime_coarse_set_mock_time_nsec(1*TOR_NSEC_PER_USEC); - curr_mocked_time = 1*TOR_NSEC_PER_USEC; + monotime_set_mock_time_nsec(1000*TOR_NSEC_PER_USEC); + monotime_coarse_set_mock_time_nsec(1000*TOR_NSEC_PER_USEC); + curr_mocked_time = 1000*TOR_NSEC_PER_USEC; timers_initialize(); circpad_machines_init(); @@ -1441,9 +1441,9 @@ test_circuitpadding_negotiation(void *arg) monotime_init(); monotime_enable_test_mocking(); - monotime_set_mock_time_nsec(1*TOR_NSEC_PER_USEC); - monotime_coarse_set_mock_time_nsec(1*TOR_NSEC_PER_USEC); - curr_mocked_time = 1*TOR_NSEC_PER_USEC; + monotime_set_mock_time_nsec(1000*TOR_NSEC_PER_USEC); + monotime_coarse_set_mock_time_nsec(1000*TOR_NSEC_PER_USEC); + curr_mocked_time = 1000*TOR_NSEC_PER_USEC; timers_initialize(); circpad_machines_init(); @@ -1716,9 +1716,9 @@ test_circuitpadding_conditions(void *arg) monotime_init(); monotime_enable_test_mocking(); - monotime_set_mock_time_nsec(1*TOR_NSEC_PER_USEC); - monotime_coarse_set_mock_time_nsec(1*TOR_NSEC_PER_USEC); - curr_mocked_time = 1*TOR_NSEC_PER_USEC; + monotime_set_mock_time_nsec(1000*TOR_NSEC_PER_USEC); + monotime_coarse_set_mock_time_nsec(1000*TOR_NSEC_PER_USEC); + curr_mocked_time = 1000*TOR_NSEC_PER_USEC; timers_initialize(); helper_create_conditional_machines(); @@ -2261,9 +2261,9 @@ test_circuitpadding_global_rate_limiting(void *arg) monotime_init(); monotime_enable_test_mocking(); - monotime_set_mock_time_nsec(1*TOR_NSEC_PER_USEC); - monotime_coarse_set_mock_time_nsec(1*TOR_NSEC_PER_USEC); - curr_mocked_time = 1*TOR_NSEC_PER_USEC; + monotime_set_mock_time_nsec(1000*TOR_NSEC_PER_USEC); + monotime_coarse_set_mock_time_nsec(1000*TOR_NSEC_PER_USEC); + curr_mocked_time = 1000*TOR_NSEC_PER_USEC; timers_initialize(); client_side = (circuit_t *)origin_circuit_new(); -- cgit v1.2.3-54-g00ecf From 28db7646ba64673188be95d3204abb94ce890b86 Mon Sep 17 00:00:00 2001 From: Mike Perry Date: Mon, 4 Mar 2019 21:54:56 +0000 Subject: Changes file for bug 29500. --- changes/bug29500 | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changes/bug29500 diff --git a/changes/bug29500 b/changes/bug29500 new file mode 100644 index 0000000000..16550935b2 --- /dev/null +++ b/changes/bug29500 @@ -0,0 +1,3 @@ + o Minor bugfixes (circuitpadding testing): + - Minor tweaks to avoid very rare test failures related to timers and + monotime. Fixes bug 29500; bugfix on 0.4.0.1-alpha -- cgit v1.2.3-54-g00ecf From b733044f7a41d65b6f3937056e9499613218ab0b Mon Sep 17 00:00:00 2001 From: Mike Perry Date: Fri, 5 Apr 2019 00:21:07 +0000 Subject: Bug #29500: Fix monotime mocking in circpad unittests. Our monotime mocking forces us to call monotime_init() *before* we set the mocked time value. monotime_init() thus stores the first ratchet value at whatever the platform is at, and then we set fake mocked time to some later value. If monotime_init() gets a value from the host that is greater than what we choose to mock time at for our unittests, all subsequent monotime_abosolute() calls return zero, which breaks all unittests that depend on time moving forward by updating mocked monotime values. So, we need to adjust our mocked time to take the weird monotime_init() time into account, when we set fake time. --- src/test/test_circuitpadding.c | 62 ++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 21 deletions(-) diff --git a/src/test/test_circuitpadding.c b/src/test/test_circuitpadding.c index cd150b0646..6272c0c2ac 100644 --- a/src/test/test_circuitpadding.c +++ b/src/test/test_circuitpadding.c @@ -31,6 +31,12 @@ #include "core/or/or_circuit_st.h" #include "core/or/origin_circuit_st.h" +/* Start our monotime mocking at 1 second past whatever monotime_init() + * thought the actual wall clock time was, for platforms with bad resolution + * and weird timevalues during monotime_init() before mocking. */ +#define MONOTIME_MOCK_START (monotime_absolute_nsec()+\ + TOR_NSEC_PER_USEC*TOR_USEC_PER_SEC) + extern smartlist_t *connection_array; circid_t get_unique_circ_id_by_chan(channel_t *chan); @@ -287,6 +293,7 @@ test_circuitpadding_rtt(void *arg) * 3. Test client side circuit and non-application of RTT.. */ circpad_delay_t rtt_estimate; + int64_t actual_mocked_monotime_start; (void)arg; MOCK(circuitmux_attach_circuit, circuitmux_attach_circuit_mock); @@ -300,9 +307,10 @@ test_circuitpadding_rtt(void *arg) monotime_init(); monotime_enable_test_mocking(); - monotime_set_mock_time_nsec(1000*TOR_NSEC_PER_USEC); - monotime_coarse_set_mock_time_nsec(1000*TOR_NSEC_PER_USEC); - curr_mocked_time = 1000*TOR_NSEC_PER_USEC; + actual_mocked_monotime_start = MONOTIME_MOCK_START; + monotime_set_mock_time_nsec(actual_mocked_monotime_start); + monotime_coarse_set_mock_time_nsec(actual_mocked_monotime_start); + curr_mocked_time = actual_mocked_monotime_start; timers_initialize(); circpad_machines_init(); @@ -963,6 +971,7 @@ test_circuitpadding_tokens(void *arg) { const circpad_state_t *state; circpad_machine_state_t *mi; + int64_t actual_mocked_monotime_start; (void)arg; /** Test plan: @@ -990,9 +999,10 @@ test_circuitpadding_tokens(void *arg) monotime_init(); monotime_enable_test_mocking(); - monotime_set_mock_time_nsec(1000*TOR_NSEC_PER_USEC); - monotime_coarse_set_mock_time_nsec(1000*TOR_NSEC_PER_USEC); - curr_mocked_time = 1000*TOR_NSEC_PER_USEC; + actual_mocked_monotime_start = MONOTIME_MOCK_START; + monotime_set_mock_time_nsec(actual_mocked_monotime_start); + monotime_coarse_set_mock_time_nsec(actual_mocked_monotime_start); + curr_mocked_time = actual_mocked_monotime_start; timers_initialize(); @@ -1235,6 +1245,7 @@ test_circuitpadding_wronghop(void *arg) cell_t cell; signed_error_t ret; origin_circuit_t *orig_client; + int64_t actual_mocked_monotime_start; MOCK(circuitmux_attach_circuit, circuitmux_attach_circuit_mock); @@ -1254,9 +1265,10 @@ test_circuitpadding_wronghop(void *arg) monotime_init(); monotime_enable_test_mocking(); - monotime_set_mock_time_nsec(1000*TOR_NSEC_PER_USEC); - monotime_coarse_set_mock_time_nsec(1000*TOR_NSEC_PER_USEC); - curr_mocked_time = 1000*TOR_NSEC_PER_USEC; + actual_mocked_monotime_start = MONOTIME_MOCK_START; + monotime_set_mock_time_nsec(actual_mocked_monotime_start); + monotime_coarse_set_mock_time_nsec(actual_mocked_monotime_start); + curr_mocked_time = actual_mocked_monotime_start; timers_initialize(); circpad_machines_init(); @@ -1427,6 +1439,7 @@ test_circuitpadding_negotiation(void *arg) * a. Make sure padding negotiation is not sent * 3. Test failure to negotiate a machine due to desync. */ + int64_t actual_mocked_monotime_start; (void)arg; MOCK(circuitmux_attach_circuit, circuitmux_attach_circuit_mock); @@ -1441,9 +1454,10 @@ test_circuitpadding_negotiation(void *arg) monotime_init(); monotime_enable_test_mocking(); - monotime_set_mock_time_nsec(1000*TOR_NSEC_PER_USEC); - monotime_coarse_set_mock_time_nsec(1000*TOR_NSEC_PER_USEC); - curr_mocked_time = 1000*TOR_NSEC_PER_USEC; + actual_mocked_monotime_start = MONOTIME_MOCK_START; + monotime_set_mock_time_nsec(actual_mocked_monotime_start); + monotime_coarse_set_mock_time_nsec(actual_mocked_monotime_start); + curr_mocked_time = actual_mocked_monotime_start; timers_initialize(); circpad_machines_init(); @@ -1703,6 +1717,7 @@ test_circuitpadding_conditions(void *arg) * 2. Test marking a circuit before padding callback fires * 3. Test freeing a circuit before padding callback fires */ + int64_t actual_mocked_monotime_start; (void)arg; MOCK(circuitmux_attach_circuit, circuitmux_attach_circuit_mock); @@ -1716,9 +1731,10 @@ test_circuitpadding_conditions(void *arg) monotime_init(); monotime_enable_test_mocking(); - monotime_set_mock_time_nsec(1000*TOR_NSEC_PER_USEC); - monotime_coarse_set_mock_time_nsec(1000*TOR_NSEC_PER_USEC); - curr_mocked_time = 1000*TOR_NSEC_PER_USEC; + actual_mocked_monotime_start = MONOTIME_MOCK_START; + monotime_set_mock_time_nsec(actual_mocked_monotime_start); + monotime_coarse_set_mock_time_nsec(actual_mocked_monotime_start); + curr_mocked_time = actual_mocked_monotime_start; timers_initialize(); helper_create_conditional_machines(); @@ -1813,6 +1829,7 @@ test_circuitpadding_conditions(void *arg) void test_circuitpadding_circuitsetup_machine(void *arg) { + int64_t actual_mocked_monotime_start; /** * Test case plan: * @@ -1838,9 +1855,10 @@ test_circuitpadding_circuitsetup_machine(void *arg) monotime_init(); monotime_enable_test_mocking(); - monotime_set_mock_time_nsec(1*TOR_NSEC_PER_USEC); - monotime_coarse_set_mock_time_nsec(1*TOR_NSEC_PER_USEC); - curr_mocked_time = 1*TOR_NSEC_PER_USEC; + actual_mocked_monotime_start = MONOTIME_MOCK_START; + monotime_set_mock_time_nsec(actual_mocked_monotime_start); + monotime_coarse_set_mock_time_nsec(actual_mocked_monotime_start); + curr_mocked_time = actual_mocked_monotime_start; timers_initialize(); circpad_machines_init(); @@ -2250,6 +2268,7 @@ test_circuitpadding_global_rate_limiting(void *arg) bool retval; circpad_machine_state_t *mi; int i; + int64_t actual_mocked_monotime_start; /* Ignore machine transitions for the purposes of this function, we only * really care about padding counts */ @@ -2261,9 +2280,10 @@ test_circuitpadding_global_rate_limiting(void *arg) monotime_init(); monotime_enable_test_mocking(); - monotime_set_mock_time_nsec(1000*TOR_NSEC_PER_USEC); - monotime_coarse_set_mock_time_nsec(1000*TOR_NSEC_PER_USEC); - curr_mocked_time = 1000*TOR_NSEC_PER_USEC; + actual_mocked_monotime_start = MONOTIME_MOCK_START; + monotime_set_mock_time_nsec(actual_mocked_monotime_start); + monotime_coarse_set_mock_time_nsec(actual_mocked_monotime_start); + curr_mocked_time = actual_mocked_monotime_start; timers_initialize(); client_side = (circuit_t *)origin_circuit_new(); -- cgit v1.2.3-54-g00ecf From 387d9448de4c5044800706b4ed21b48b4426cb7e Mon Sep 17 00:00:00 2001 From: teor Date: Tue, 2 Apr 2019 19:56:38 +1000 Subject: test/circuitpadding: Delete circuitpadding_circuitsetup_machine() This test was disabled in 0.4.0 and later, but the fix in #29298 was only merged to 0.4.1. So this test will never be re-enabled in 0.4.0. Part of 29500. --- src/test/test_circuitpadding.c | 253 ----------------------------------------- 1 file changed, 253 deletions(-) diff --git a/src/test/test_circuitpadding.c b/src/test/test_circuitpadding.c index 6272c0c2ac..ed048ab968 100644 --- a/src/test/test_circuitpadding.c +++ b/src/test/test_circuitpadding.c @@ -1824,257 +1824,6 @@ test_circuitpadding_conditions(void *arg) return; } -/** Disabled unstable test until #29298 is implemented (see #29122) */ -#if 0 -void -test_circuitpadding_circuitsetup_machine(void *arg) -{ - int64_t actual_mocked_monotime_start; - /** - * Test case plan: - * - * 1. Simulate a normal circuit setup pattern - * a. Application traffic - * - * FIXME: This should focus more on exercising the machine - * features rather than actual traffic patterns. For example, - * test cancellation and bins empty/refill - */ - (void)arg; - - MOCK(circuitmux_attach_circuit, circuitmux_attach_circuit_mock); - - dummy_channel.cmux = circuitmux_alloc(); - client_side = TO_CIRCUIT(origin_circuit_new()); - relay_side = TO_CIRCUIT(new_fake_orcirc(&dummy_channel, &dummy_channel)); - - relay_side->purpose = CIRCUIT_PURPOSE_OR; - client_side->purpose = CIRCUIT_PURPOSE_C_GENERAL; - - nodes_init(); - - monotime_init(); - monotime_enable_test_mocking(); - actual_mocked_monotime_start = MONOTIME_MOCK_START; - monotime_set_mock_time_nsec(actual_mocked_monotime_start); - monotime_coarse_set_mock_time_nsec(actual_mocked_monotime_start); - curr_mocked_time = actual_mocked_monotime_start; - - timers_initialize(); - circpad_machines_init(); - - MOCK(circuit_package_relay_cell, - circuit_package_relay_cell_mock); - MOCK(node_get_by_id, - node_get_by_id_mock); - - /* Test case #1: Build a 3 hop circuit, then wait and let pad */ - simulate_single_hop_extend(client_side, relay_side, 1); - simulate_single_hop_extend(client_side, relay_side, 1); - simulate_single_hop_extend(client_side, relay_side, 1); - - tt_int_op(n_client_cells, OP_EQ, 1); - tt_int_op(n_relay_cells, OP_EQ, 1); - tt_int_op(client_side->padding_info[0]->current_state, OP_EQ, - CIRCPAD_STATE_BURST); - tt_int_op(relay_side->padding_info[0]->current_state, OP_EQ, - CIRCPAD_STATE_BURST); - - tt_u64_op(client_side->padding_info[0]->padding_scheduled_at_usec, - OP_NE, 0); - tt_int_op(relay_side->padding_info[0]->is_padding_timer_scheduled, - OP_EQ, 0); - timers_advance_and_run(2000); - tt_int_op(n_client_cells, OP_EQ, 2); - tt_int_op(n_relay_cells, OP_EQ, 1); - - tt_int_op(relay_side->padding_info[0]->current_state, OP_EQ, - CIRCPAD_STATE_GAP); - - tt_u64_op(client_side->padding_info[0]->padding_scheduled_at_usec, - OP_EQ, 0); - tt_u64_op(relay_side->padding_info[0]->padding_scheduled_at_usec, - OP_NE, 0); - timers_advance_and_run(5000); - tt_int_op(n_client_cells, OP_EQ, 2); - tt_int_op(n_relay_cells, OP_EQ, 2); - - tt_u64_op(client_side->padding_info[0]->padding_scheduled_at_usec, - OP_NE, 0); - tt_u64_op(relay_side->padding_info[0]->padding_scheduled_at_usec, - OP_EQ, 0); - timers_advance_and_run(2000); - tt_int_op(n_client_cells, OP_EQ, 3); - tt_int_op(n_relay_cells, OP_EQ, 2); - - tt_u64_op(client_side->padding_info[0]->padding_scheduled_at_usec, - OP_EQ, 0); - tt_u64_op(relay_side->padding_info[0]->padding_scheduled_at_usec, - OP_NE, 0); - timers_advance_and_run(5000); - tt_int_op(n_client_cells, OP_EQ, 3); - tt_int_op(n_relay_cells, OP_EQ, 3); - - tt_u64_op(client_side->padding_info[0]->padding_scheduled_at_usec, - OP_NE, 0); - tt_u64_op(relay_side->padding_info[0]->padding_scheduled_at_usec, - OP_EQ, 0); - timers_advance_and_run(2000); - tt_int_op(n_client_cells, OP_EQ, 4); - tt_int_op(n_relay_cells, OP_EQ, 3); - - tt_u64_op(client_side->padding_info[0]->padding_scheduled_at_usec, - OP_EQ, 0); - tt_u64_op(relay_side->padding_info[0]->padding_scheduled_at_usec, - OP_NE, 0); - timers_advance_and_run(5000); - tt_int_op(n_client_cells, OP_EQ, 4); - tt_int_op(n_relay_cells, OP_EQ, 4); - - tt_u64_op(client_side->padding_info[0]->padding_scheduled_at_usec, - OP_NE, 0); - tt_u64_op(relay_side->padding_info[0]->padding_scheduled_at_usec, - OP_EQ, 0); - timers_advance_and_run(2000); - tt_int_op(n_client_cells, OP_EQ, 5); - tt_int_op(n_relay_cells, OP_EQ, 4); - - tt_u64_op(client_side->padding_info[0]->padding_scheduled_at_usec, - OP_EQ, 0); - tt_u64_op(relay_side->padding_info[0]->padding_scheduled_at_usec, - OP_NE, 0); - timers_advance_and_run(5000); - tt_int_op(n_client_cells, OP_EQ, 5); - tt_int_op(n_relay_cells, OP_EQ, 5); - - tt_u64_op(client_side->padding_info[0]->padding_scheduled_at_usec, - OP_NE, 0); - tt_u64_op(relay_side->padding_info[0]->padding_scheduled_at_usec, - OP_EQ, 0); - timers_advance_and_run(2000); - tt_int_op(n_client_cells, OP_EQ, 6); - tt_int_op(n_relay_cells, OP_EQ, 5); - - tt_u64_op(client_side->padding_info[0]->padding_scheduled_at_usec, - OP_EQ, 0); - tt_u64_op(relay_side->padding_info[0]->padding_scheduled_at_usec, - OP_NE, 0); - timers_advance_and_run(5000); - tt_int_op(n_client_cells, OP_EQ, 6); - tt_int_op(n_relay_cells, OP_EQ, 6); - - tt_int_op(client_side->padding_info[0]->current_state, - OP_EQ, CIRCPAD_STATE_END); - tt_u64_op(client_side->padding_info[0]->padding_scheduled_at_usec, - OP_EQ, 0); - tt_int_op(relay_side->padding_info[0]->current_state, - OP_EQ, CIRCPAD_STATE_GAP); - tt_u64_op(relay_side->padding_info[0]->padding_scheduled_at_usec, - OP_EQ, 0); - - /* Verify we can't schedule padding in END state */ - circpad_decision_t ret = - circpad_machine_schedule_padding(client_side->padding_info[0]); - tt_int_op(ret, OP_EQ, CIRCPAD_STATE_UNCHANGED); - - /* Simulate application traffic */ - circpad_cell_event_nonpadding_sent(client_side); - circpad_deliver_unrecognized_cell_events(relay_side, CELL_DIRECTION_OUT); - circpad_deliver_unrecognized_cell_events(relay_side, CELL_DIRECTION_IN); - circpad_deliver_recognized_relay_cell_events(client_side, RELAY_COMMAND_DATA, - TO_ORIGIN_CIRCUIT(client_side)->cpath->next); - - tt_ptr_op(client_side->padding_info[0], OP_EQ, NULL); - tt_ptr_op(client_side->padding_machine[0], OP_EQ, NULL); - - tt_ptr_op(relay_side->padding_info[0], OP_EQ, NULL); - tt_ptr_op(relay_side->padding_machine[0], OP_EQ, NULL); - tt_int_op(n_client_cells, OP_EQ, 6); - tt_int_op(n_relay_cells, OP_EQ, 7); - - // Test timer cancellation - simulate_single_hop_extend(client_side, relay_side, 1); - simulate_single_hop_extend(client_side, relay_side, 1); - timers_advance_and_run(5000); - circpad_cell_event_padding_received(client_side); - - tt_int_op(client_side->padding_info[0]->current_state, OP_EQ, - CIRCPAD_STATE_BURST); - tt_int_op(relay_side->padding_info[0]->current_state, OP_EQ, - CIRCPAD_STATE_GAP); - - tt_int_op(n_client_cells, OP_EQ, 8); - tt_int_op(n_relay_cells, OP_EQ, 8); - tt_u64_op(client_side->padding_info[0]->padding_scheduled_at_usec, - OP_NE, 0); - tt_u64_op(relay_side->padding_info[0]->padding_scheduled_at_usec, - OP_NE, 0); - - /* Test timer cancel due to state rules */ - circpad_cell_event_nonpadding_sent(client_side); - tt_u64_op(client_side->padding_info[0]->padding_scheduled_at_usec, - OP_EQ, 0); - circpad_cell_event_padding_received(client_side); - tt_u64_op(client_side->padding_info[0]->padding_scheduled_at_usec, - OP_NE, 0); - - /* Simulate application traffic to cancel timer */ - circpad_cell_event_nonpadding_sent(client_side); - circpad_deliver_unrecognized_cell_events(relay_side, CELL_DIRECTION_OUT); - circpad_deliver_unrecognized_cell_events(relay_side, CELL_DIRECTION_IN); - circpad_deliver_recognized_relay_cell_events(client_side, RELAY_COMMAND_DATA, - TO_ORIGIN_CIRCUIT(client_side)->cpath->next); - - tt_ptr_op(client_side->padding_info[0], OP_EQ, NULL); - tt_ptr_op(client_side->padding_machine[0], OP_EQ, NULL); - - tt_ptr_op(relay_side->padding_info[0], OP_EQ, NULL); - tt_ptr_op(relay_side->padding_machine[0], OP_EQ, NULL); - - /* No cells sent, except negotiate end from relay */ - tt_int_op(n_client_cells, OP_EQ, 8); - tt_int_op(n_relay_cells, OP_EQ, 9); - - /* Test mark for close and free */ - simulate_single_hop_extend(client_side, relay_side, 1); - simulate_single_hop_extend(client_side, relay_side, 1); - timers_advance_and_run(5000); - circpad_cell_event_padding_received(client_side); - - tt_int_op(n_client_cells, OP_EQ, 10); - tt_int_op(n_relay_cells, OP_EQ, 10); - - tt_int_op(client_side->padding_info[0]->current_state, OP_EQ, - CIRCPAD_STATE_BURST); - tt_int_op(relay_side->padding_info[0]->current_state, OP_EQ, - CIRCPAD_STATE_GAP); - - tt_u64_op(client_side->padding_info[0]->padding_scheduled_at_usec, - OP_NE, 0); - tt_u64_op(relay_side->padding_info[0]->padding_scheduled_at_usec, - OP_NE, 0); - circuit_mark_for_close(client_side, END_CIRC_REASON_FLAG_REMOTE); - free_fake_orcirc(relay_side); - timers_advance_and_run(5000); - - /* No cells sent */ - tt_int_op(n_client_cells, OP_EQ, 10); - tt_int_op(n_relay_cells, OP_EQ, 10); - - done: - free_fake_origin_circuit(TO_ORIGIN_CIRCUIT(client_side)); - - circuitmux_detach_all_circuits(dummy_channel.cmux, NULL); - circuitmux_free(dummy_channel.cmux); - timers_shutdown(); - monotime_disable_test_mocking(); - UNMOCK(circuit_package_relay_cell); - UNMOCK(circuitmux_attach_circuit); - - return; -} -#endif - /** Helper function: Initializes a padding machine where every state uses the * uniform probability distribution. */ static void @@ -2365,8 +2114,6 @@ struct testcase_t circuitpadding_tests[] = { TEST_CIRCUITPADDING(circuitpadding_tokens, TT_FORK), TEST_CIRCUITPADDING(circuitpadding_negotiation, TT_FORK), TEST_CIRCUITPADDING(circuitpadding_wronghop, TT_FORK), - /** Disabled unstable test until #29298 is implemented (see #29122) */ - // TEST_CIRCUITPADDING(circuitpadding_circuitsetup_machine, TT_FORK), TEST_CIRCUITPADDING(circuitpadding_conditions, TT_FORK), TEST_CIRCUITPADDING(circuitpadding_rtt, TT_FORK), TEST_CIRCUITPADDING(circuitpadding_sample_distribution, TT_FORK), -- cgit v1.2.3-54-g00ecf From da678213e00cfe54ccc80286bed2b36603bba115 Mon Sep 17 00:00:00 2001 From: teor Date: Wed, 3 Apr 2019 13:40:06 +1000 Subject: circuitpadding: comment fixes --- src/core/or/circuitpadding.c | 3 ++- src/test/test_circuitpadding.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/or/circuitpadding.c b/src/core/or/circuitpadding.c index ba6bfe1f53..0e3dc502ce 100644 --- a/src/core/or/circuitpadding.c +++ b/src/core/or/circuitpadding.c @@ -1466,7 +1466,8 @@ circpad_estimate_circ_rtt_on_send(circuit_t *circ, /* If the old RTT estimate is lower than this one, use this one, because * the circuit is getting longer. If this estimate is somehow - * faster than the previous, then maybe that was network jitter. + * faster than the previous, then maybe that was network jitter, or a + * bad monotonic clock source (so our ratchet returned a zero delta). * In that case, average them. */ if (mi->rtt_estimate_usec < (circpad_delay_t)rtt_time) { mi->rtt_estimate_usec = (circpad_delay_t)rtt_time; diff --git a/src/test/test_circuitpadding.c b/src/test/test_circuitpadding.c index ed048ab968..09a4c9a0ca 100644 --- a/src/test/test_circuitpadding.c +++ b/src/test/test_circuitpadding.c @@ -576,7 +576,7 @@ test_circuitpadding_token_removal_higher(void *arg) } } - /* Check that all lowe bins are not touched */ + /* Check that all lower bins are not touched */ for (i=0; i < 4 ; i++) { tt_int_op(mi->histogram[i], OP_EQ, 2); } -- cgit v1.2.3-54-g00ecf From 593b33608d6b0696e8cf29780e4881f93cbd4055 Mon Sep 17 00:00:00 2001 From: teor Date: Fri, 5 Apr 2019 12:22:18 +1000 Subject: Revert "test/circuitpadding: Delete circuitpadding_circuitsetup_machine()" This reverts commit 387d9448de4c5044800706b4ed21b48b4426cb7e. --- src/test/test_circuitpadding.c | 253 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 253 insertions(+) diff --git a/src/test/test_circuitpadding.c b/src/test/test_circuitpadding.c index 09a4c9a0ca..22fa817cd6 100644 --- a/src/test/test_circuitpadding.c +++ b/src/test/test_circuitpadding.c @@ -1824,6 +1824,257 @@ test_circuitpadding_conditions(void *arg) return; } +/** Disabled unstable test until #29298 is implemented (see #29122) */ +#if 0 +void +test_circuitpadding_circuitsetup_machine(void *arg) +{ + int64_t actual_mocked_monotime_start; + /** + * Test case plan: + * + * 1. Simulate a normal circuit setup pattern + * a. Application traffic + * + * FIXME: This should focus more on exercising the machine + * features rather than actual traffic patterns. For example, + * test cancellation and bins empty/refill + */ + (void)arg; + + MOCK(circuitmux_attach_circuit, circuitmux_attach_circuit_mock); + + dummy_channel.cmux = circuitmux_alloc(); + client_side = TO_CIRCUIT(origin_circuit_new()); + relay_side = TO_CIRCUIT(new_fake_orcirc(&dummy_channel, &dummy_channel)); + + relay_side->purpose = CIRCUIT_PURPOSE_OR; + client_side->purpose = CIRCUIT_PURPOSE_C_GENERAL; + + nodes_init(); + + monotime_init(); + monotime_enable_test_mocking(); + actual_mocked_monotime_start = MONOTIME_MOCK_START; + monotime_set_mock_time_nsec(actual_mocked_monotime_start); + monotime_coarse_set_mock_time_nsec(actual_mocked_monotime_start); + curr_mocked_time = actual_mocked_monotime_start; + + timers_initialize(); + circpad_machines_init(); + + MOCK(circuit_package_relay_cell, + circuit_package_relay_cell_mock); + MOCK(node_get_by_id, + node_get_by_id_mock); + + /* Test case #1: Build a 3 hop circuit, then wait and let pad */ + simulate_single_hop_extend(client_side, relay_side, 1); + simulate_single_hop_extend(client_side, relay_side, 1); + simulate_single_hop_extend(client_side, relay_side, 1); + + tt_int_op(n_client_cells, OP_EQ, 1); + tt_int_op(n_relay_cells, OP_EQ, 1); + tt_int_op(client_side->padding_info[0]->current_state, OP_EQ, + CIRCPAD_STATE_BURST); + tt_int_op(relay_side->padding_info[0]->current_state, OP_EQ, + CIRCPAD_STATE_BURST); + + tt_u64_op(client_side->padding_info[0]->padding_scheduled_at_usec, + OP_NE, 0); + tt_int_op(relay_side->padding_info[0]->is_padding_timer_scheduled, + OP_EQ, 0); + timers_advance_and_run(2000); + tt_int_op(n_client_cells, OP_EQ, 2); + tt_int_op(n_relay_cells, OP_EQ, 1); + + tt_int_op(relay_side->padding_info[0]->current_state, OP_EQ, + CIRCPAD_STATE_GAP); + + tt_u64_op(client_side->padding_info[0]->padding_scheduled_at_usec, + OP_EQ, 0); + tt_u64_op(relay_side->padding_info[0]->padding_scheduled_at_usec, + OP_NE, 0); + timers_advance_and_run(5000); + tt_int_op(n_client_cells, OP_EQ, 2); + tt_int_op(n_relay_cells, OP_EQ, 2); + + tt_u64_op(client_side->padding_info[0]->padding_scheduled_at_usec, + OP_NE, 0); + tt_u64_op(relay_side->padding_info[0]->padding_scheduled_at_usec, + OP_EQ, 0); + timers_advance_and_run(2000); + tt_int_op(n_client_cells, OP_EQ, 3); + tt_int_op(n_relay_cells, OP_EQ, 2); + + tt_u64_op(client_side->padding_info[0]->padding_scheduled_at_usec, + OP_EQ, 0); + tt_u64_op(relay_side->padding_info[0]->padding_scheduled_at_usec, + OP_NE, 0); + timers_advance_and_run(5000); + tt_int_op(n_client_cells, OP_EQ, 3); + tt_int_op(n_relay_cells, OP_EQ, 3); + + tt_u64_op(client_side->padding_info[0]->padding_scheduled_at_usec, + OP_NE, 0); + tt_u64_op(relay_side->padding_info[0]->padding_scheduled_at_usec, + OP_EQ, 0); + timers_advance_and_run(2000); + tt_int_op(n_client_cells, OP_EQ, 4); + tt_int_op(n_relay_cells, OP_EQ, 3); + + tt_u64_op(client_side->padding_info[0]->padding_scheduled_at_usec, + OP_EQ, 0); + tt_u64_op(relay_side->padding_info[0]->padding_scheduled_at_usec, + OP_NE, 0); + timers_advance_and_run(5000); + tt_int_op(n_client_cells, OP_EQ, 4); + tt_int_op(n_relay_cells, OP_EQ, 4); + + tt_u64_op(client_side->padding_info[0]->padding_scheduled_at_usec, + OP_NE, 0); + tt_u64_op(relay_side->padding_info[0]->padding_scheduled_at_usec, + OP_EQ, 0); + timers_advance_and_run(2000); + tt_int_op(n_client_cells, OP_EQ, 5); + tt_int_op(n_relay_cells, OP_EQ, 4); + + tt_u64_op(client_side->padding_info[0]->padding_scheduled_at_usec, + OP_EQ, 0); + tt_u64_op(relay_side->padding_info[0]->padding_scheduled_at_usec, + OP_NE, 0); + timers_advance_and_run(5000); + tt_int_op(n_client_cells, OP_EQ, 5); + tt_int_op(n_relay_cells, OP_EQ, 5); + + tt_u64_op(client_side->padding_info[0]->padding_scheduled_at_usec, + OP_NE, 0); + tt_u64_op(relay_side->padding_info[0]->padding_scheduled_at_usec, + OP_EQ, 0); + timers_advance_and_run(2000); + tt_int_op(n_client_cells, OP_EQ, 6); + tt_int_op(n_relay_cells, OP_EQ, 5); + + tt_u64_op(client_side->padding_info[0]->padding_scheduled_at_usec, + OP_EQ, 0); + tt_u64_op(relay_side->padding_info[0]->padding_scheduled_at_usec, + OP_NE, 0); + timers_advance_and_run(5000); + tt_int_op(n_client_cells, OP_EQ, 6); + tt_int_op(n_relay_cells, OP_EQ, 6); + + tt_int_op(client_side->padding_info[0]->current_state, + OP_EQ, CIRCPAD_STATE_END); + tt_u64_op(client_side->padding_info[0]->padding_scheduled_at_usec, + OP_EQ, 0); + tt_int_op(relay_side->padding_info[0]->current_state, + OP_EQ, CIRCPAD_STATE_GAP); + tt_u64_op(relay_side->padding_info[0]->padding_scheduled_at_usec, + OP_EQ, 0); + + /* Verify we can't schedule padding in END state */ + circpad_decision_t ret = + circpad_machine_schedule_padding(client_side->padding_info[0]); + tt_int_op(ret, OP_EQ, CIRCPAD_STATE_UNCHANGED); + + /* Simulate application traffic */ + circpad_cell_event_nonpadding_sent(client_side); + circpad_deliver_unrecognized_cell_events(relay_side, CELL_DIRECTION_OUT); + circpad_deliver_unrecognized_cell_events(relay_side, CELL_DIRECTION_IN); + circpad_deliver_recognized_relay_cell_events(client_side, RELAY_COMMAND_DATA, + TO_ORIGIN_CIRCUIT(client_side)->cpath->next); + + tt_ptr_op(client_side->padding_info[0], OP_EQ, NULL); + tt_ptr_op(client_side->padding_machine[0], OP_EQ, NULL); + + tt_ptr_op(relay_side->padding_info[0], OP_EQ, NULL); + tt_ptr_op(relay_side->padding_machine[0], OP_EQ, NULL); + tt_int_op(n_client_cells, OP_EQ, 6); + tt_int_op(n_relay_cells, OP_EQ, 7); + + // Test timer cancellation + simulate_single_hop_extend(client_side, relay_side, 1); + simulate_single_hop_extend(client_side, relay_side, 1); + timers_advance_and_run(5000); + circpad_cell_event_padding_received(client_side); + + tt_int_op(client_side->padding_info[0]->current_state, OP_EQ, + CIRCPAD_STATE_BURST); + tt_int_op(relay_side->padding_info[0]->current_state, OP_EQ, + CIRCPAD_STATE_GAP); + + tt_int_op(n_client_cells, OP_EQ, 8); + tt_int_op(n_relay_cells, OP_EQ, 8); + tt_u64_op(client_side->padding_info[0]->padding_scheduled_at_usec, + OP_NE, 0); + tt_u64_op(relay_side->padding_info[0]->padding_scheduled_at_usec, + OP_NE, 0); + + /* Test timer cancel due to state rules */ + circpad_cell_event_nonpadding_sent(client_side); + tt_u64_op(client_side->padding_info[0]->padding_scheduled_at_usec, + OP_EQ, 0); + circpad_cell_event_padding_received(client_side); + tt_u64_op(client_side->padding_info[0]->padding_scheduled_at_usec, + OP_NE, 0); + + /* Simulate application traffic to cancel timer */ + circpad_cell_event_nonpadding_sent(client_side); + circpad_deliver_unrecognized_cell_events(relay_side, CELL_DIRECTION_OUT); + circpad_deliver_unrecognized_cell_events(relay_side, CELL_DIRECTION_IN); + circpad_deliver_recognized_relay_cell_events(client_side, RELAY_COMMAND_DATA, + TO_ORIGIN_CIRCUIT(client_side)->cpath->next); + + tt_ptr_op(client_side->padding_info[0], OP_EQ, NULL); + tt_ptr_op(client_side->padding_machine[0], OP_EQ, NULL); + + tt_ptr_op(relay_side->padding_info[0], OP_EQ, NULL); + tt_ptr_op(relay_side->padding_machine[0], OP_EQ, NULL); + + /* No cells sent, except negotiate end from relay */ + tt_int_op(n_client_cells, OP_EQ, 8); + tt_int_op(n_relay_cells, OP_EQ, 9); + + /* Test mark for close and free */ + simulate_single_hop_extend(client_side, relay_side, 1); + simulate_single_hop_extend(client_side, relay_side, 1); + timers_advance_and_run(5000); + circpad_cell_event_padding_received(client_side); + + tt_int_op(n_client_cells, OP_EQ, 10); + tt_int_op(n_relay_cells, OP_EQ, 10); + + tt_int_op(client_side->padding_info[0]->current_state, OP_EQ, + CIRCPAD_STATE_BURST); + tt_int_op(relay_side->padding_info[0]->current_state, OP_EQ, + CIRCPAD_STATE_GAP); + + tt_u64_op(client_side->padding_info[0]->padding_scheduled_at_usec, + OP_NE, 0); + tt_u64_op(relay_side->padding_info[0]->padding_scheduled_at_usec, + OP_NE, 0); + circuit_mark_for_close(client_side, END_CIRC_REASON_FLAG_REMOTE); + free_fake_orcirc(relay_side); + timers_advance_and_run(5000); + + /* No cells sent */ + tt_int_op(n_client_cells, OP_EQ, 10); + tt_int_op(n_relay_cells, OP_EQ, 10); + + done: + free_fake_origin_circuit(TO_ORIGIN_CIRCUIT(client_side)); + + circuitmux_detach_all_circuits(dummy_channel.cmux, NULL); + circuitmux_free(dummy_channel.cmux); + timers_shutdown(); + monotime_disable_test_mocking(); + UNMOCK(circuit_package_relay_cell); + UNMOCK(circuitmux_attach_circuit); + + return; +} +#endif + /** Helper function: Initializes a padding machine where every state uses the * uniform probability distribution. */ static void @@ -2114,6 +2365,8 @@ struct testcase_t circuitpadding_tests[] = { TEST_CIRCUITPADDING(circuitpadding_tokens, TT_FORK), TEST_CIRCUITPADDING(circuitpadding_negotiation, TT_FORK), TEST_CIRCUITPADDING(circuitpadding_wronghop, TT_FORK), + /** Disabled unstable test until #29298 is implemented (see #29122) */ + // TEST_CIRCUITPADDING(circuitpadding_circuitsetup_machine, TT_FORK), TEST_CIRCUITPADDING(circuitpadding_conditions, TT_FORK), TEST_CIRCUITPADDING(circuitpadding_rtt, TT_FORK), TEST_CIRCUITPADDING(circuitpadding_sample_distribution, TT_FORK), -- cgit v1.2.3-54-g00ecf