mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-11 05:33:47 +01:00
Use reproducible RNG logic in circuitpadding tests.
This commit is contained in:
parent
72e9c427b8
commit
536ba09ad1
@ -34,6 +34,8 @@
|
||||
#include "core/or/or_circuit_st.h"
|
||||
#include "core/or/origin_circuit_st.h"
|
||||
|
||||
#include "test/rng_test_helpers.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. */
|
||||
@ -300,6 +302,7 @@ test_circuitpadding_rtt(void *arg)
|
||||
|
||||
MOCK(circuitmux_attach_circuit, circuitmux_attach_circuit_mock);
|
||||
MOCK(circpad_send_command_to_hop, circpad_send_command_to_hop_mock);
|
||||
testing_enable_reproducible_rng();
|
||||
|
||||
dummy_channel.cmux = circuitmux_alloc();
|
||||
relay_side = TO_CIRCUIT(new_fake_orcirc(&dummy_channel, &dummy_channel));
|
||||
@ -403,6 +406,7 @@ test_circuitpadding_rtt(void *arg)
|
||||
UNMOCK(circuit_package_relay_cell);
|
||||
UNMOCK(circuitmux_attach_circuit);
|
||||
tor_free(circ_client_machine.states);
|
||||
testing_disable_reproducible_rng();
|
||||
|
||||
return;
|
||||
}
|
||||
@ -524,6 +528,7 @@ test_circuitpadding_token_removal_higher(void *arg)
|
||||
/* Mock it up */
|
||||
MOCK(monotime_absolute_usec, mock_monotime_absolute_usec);
|
||||
MOCK(circpad_machine_schedule_padding,circpad_machine_schedule_padding_mock);
|
||||
testing_enable_reproducible_rng();
|
||||
|
||||
/* Setup test environment (time etc.) */
|
||||
client_side = (circuit_t *)origin_circuit_new();
|
||||
@ -617,6 +622,7 @@ test_circuitpadding_token_removal_higher(void *arg)
|
||||
free_fake_origin_circuit(TO_ORIGIN_CIRCUIT(client_side));
|
||||
monotime_disable_test_mocking();
|
||||
tor_free(circ_client_machine.states);
|
||||
testing_disable_reproducible_rng();
|
||||
}
|
||||
|
||||
/** Test lower token removal strategy by bin */
|
||||
@ -629,6 +635,7 @@ test_circuitpadding_token_removal_lower(void *arg)
|
||||
/* Mock it up */
|
||||
MOCK(monotime_absolute_usec, mock_monotime_absolute_usec);
|
||||
MOCK(circpad_machine_schedule_padding,circpad_machine_schedule_padding_mock);
|
||||
testing_enable_reproducible_rng();
|
||||
|
||||
/* Setup test environment (time etc.) */
|
||||
client_side = (circuit_t *)origin_circuit_new();
|
||||
@ -715,6 +722,7 @@ test_circuitpadding_token_removal_lower(void *arg)
|
||||
free_fake_origin_circuit(TO_ORIGIN_CIRCUIT(client_side));
|
||||
monotime_disable_test_mocking();
|
||||
tor_free(circ_client_machine.states);
|
||||
testing_disable_reproducible_rng();
|
||||
}
|
||||
|
||||
/** Test closest token removal strategy by bin */
|
||||
@ -727,6 +735,7 @@ test_circuitpadding_closest_token_removal(void *arg)
|
||||
/* Mock it up */
|
||||
MOCK(monotime_absolute_usec, mock_monotime_absolute_usec);
|
||||
MOCK(circpad_machine_schedule_padding,circpad_machine_schedule_padding_mock);
|
||||
testing_enable_reproducible_rng();
|
||||
|
||||
/* Setup test environment (time etc.) */
|
||||
client_side = (circuit_t *)origin_circuit_new();
|
||||
@ -821,6 +830,7 @@ test_circuitpadding_closest_token_removal(void *arg)
|
||||
free_fake_origin_circuit(TO_ORIGIN_CIRCUIT(client_side));
|
||||
monotime_disable_test_mocking();
|
||||
tor_free(circ_client_machine.states);
|
||||
testing_disable_reproducible_rng();
|
||||
}
|
||||
|
||||
/** Test closest token removal strategy with usec */
|
||||
@ -833,6 +843,7 @@ test_circuitpadding_closest_token_removal_usec(void *arg)
|
||||
/* Mock it up */
|
||||
MOCK(monotime_absolute_usec, mock_monotime_absolute_usec);
|
||||
MOCK(circpad_machine_schedule_padding,circpad_machine_schedule_padding_mock);
|
||||
testing_enable_reproducible_rng();
|
||||
|
||||
/* Setup test environment (time etc.) */
|
||||
client_side = (circuit_t *)origin_circuit_new();
|
||||
@ -932,6 +943,7 @@ test_circuitpadding_closest_token_removal_usec(void *arg)
|
||||
free_fake_origin_circuit(TO_ORIGIN_CIRCUIT(client_side));
|
||||
monotime_disable_test_mocking();
|
||||
tor_free(circ_client_machine.states);
|
||||
testing_disable_reproducible_rng();
|
||||
}
|
||||
|
||||
/** Test closest token removal strategy with usec */
|
||||
@ -944,6 +956,7 @@ test_circuitpadding_token_removal_exact(void *arg)
|
||||
/* Mock it up */
|
||||
MOCK(monotime_absolute_usec, mock_monotime_absolute_usec);
|
||||
MOCK(circpad_machine_schedule_padding,circpad_machine_schedule_padding_mock);
|
||||
testing_enable_reproducible_rng();
|
||||
|
||||
/* Setup test environment (time etc.) */
|
||||
client_side = (circuit_t *)origin_circuit_new();
|
||||
@ -991,6 +1004,7 @@ test_circuitpadding_token_removal_exact(void *arg)
|
||||
free_fake_origin_circuit(TO_ORIGIN_CIRCUIT(client_side));
|
||||
monotime_disable_test_mocking();
|
||||
tor_free(circ_client_machine.states);
|
||||
testing_disable_reproducible_rng();
|
||||
}
|
||||
|
||||
#undef BIG_HISTOGRAM_LEN
|
||||
@ -1003,6 +1017,8 @@ test_circuitpadding_tokens(void *arg)
|
||||
int64_t actual_mocked_monotime_start;
|
||||
(void)arg;
|
||||
|
||||
testing_enable_reproducible_rng();
|
||||
|
||||
/** Test plan:
|
||||
*
|
||||
* 1. Test symmetry between bin_to_usec and usec_to_bin
|
||||
@ -1256,6 +1272,7 @@ test_circuitpadding_tokens(void *arg)
|
||||
free_fake_origin_circuit(TO_ORIGIN_CIRCUIT(client_side));
|
||||
monotime_disable_test_mocking();
|
||||
tor_free(circ_client_machine.states);
|
||||
testing_disable_reproducible_rng();
|
||||
}
|
||||
|
||||
void
|
||||
@ -1283,6 +1300,7 @@ test_circuitpadding_wronghop(void *arg)
|
||||
/* Mock this function so that our cell counting tests don't get confused by
|
||||
* padding that gets sent by scheduled timers. */
|
||||
MOCK(circpad_machine_schedule_padding,circpad_machine_schedule_padding_mock);
|
||||
testing_enable_reproducible_rng();
|
||||
|
||||
client_side = (circuit_t *)origin_circuit_new();
|
||||
dummy_channel.cmux = circuitmux_alloc();
|
||||
@ -1456,6 +1474,7 @@ test_circuitpadding_wronghop(void *arg)
|
||||
UNMOCK(circuit_package_relay_cell);
|
||||
UNMOCK(circuitmux_attach_circuit);
|
||||
nodes_free();
|
||||
testing_disable_reproducible_rng();
|
||||
}
|
||||
|
||||
void
|
||||
@ -1758,6 +1777,7 @@ test_circuitpadding_conditions(void *arg)
|
||||
int64_t actual_mocked_monotime_start;
|
||||
(void)arg;
|
||||
MOCK(circuitmux_attach_circuit, circuitmux_attach_circuit_mock);
|
||||
testing_enable_reproducible_rng();
|
||||
|
||||
nodes_init();
|
||||
dummy_channel.cmux = circuitmux_alloc();
|
||||
@ -1862,6 +1882,7 @@ test_circuitpadding_conditions(void *arg)
|
||||
|
||||
done:
|
||||
/* XXX: Free everything */
|
||||
testing_disable_reproducible_rng();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -2191,6 +2212,7 @@ test_circuitpadding_sample_distribution(void *arg)
|
||||
/* mock this function so that we dont actually schedule any padding */
|
||||
MOCK(circpad_machine_schedule_padding,
|
||||
circpad_machine_schedule_padding_mock);
|
||||
testing_enable_reproducible_rng();
|
||||
|
||||
/* Initialize a machine with multiple probability distributions */
|
||||
circpad_machines_init();
|
||||
@ -2223,6 +2245,7 @@ test_circuitpadding_sample_distribution(void *arg)
|
||||
done:
|
||||
free_fake_origin_circuit(TO_ORIGIN_CIRCUIT(client_side));
|
||||
UNMOCK(circpad_machine_schedule_padding);
|
||||
testing_disable_reproducible_rng();
|
||||
}
|
||||
|
||||
static circpad_decision_t
|
||||
@ -2248,6 +2271,7 @@ test_circuitpadding_machine_rate_limiting(void *arg)
|
||||
* really care about padding counts */
|
||||
MOCK(circpad_machine_spec_transition, circpad_machine_spec_transition_mock);
|
||||
MOCK(circpad_send_command_to_hop, circpad_send_command_to_hop_mock);
|
||||
testing_enable_reproducible_rng();
|
||||
|
||||
/* Setup machine and circuits */
|
||||
client_side = TO_CIRCUIT(origin_circuit_new());
|
||||
@ -2301,6 +2325,7 @@ test_circuitpadding_machine_rate_limiting(void *arg)
|
||||
|
||||
done:
|
||||
free_fake_origin_circuit(TO_ORIGIN_CIRCUIT(client_side));
|
||||
testing_disable_reproducible_rng();
|
||||
}
|
||||
|
||||
/* Test global padding rate limits */
|
||||
@ -2320,6 +2345,7 @@ test_circuitpadding_global_rate_limiting(void *arg)
|
||||
MOCK(circuit_package_relay_cell,
|
||||
circuit_package_relay_cell_mock);
|
||||
MOCK(monotime_absolute_usec, mock_monotime_absolute_usec);
|
||||
testing_enable_reproducible_rng();
|
||||
|
||||
monotime_init();
|
||||
monotime_enable_test_mocking();
|
||||
@ -2399,6 +2425,7 @@ test_circuitpadding_global_rate_limiting(void *arg)
|
||||
circuitmux_free(dummy_channel.cmux);
|
||||
SMARTLIST_FOREACH(vote1.net_params, char *, cp, tor_free(cp));
|
||||
smartlist_free(vote1.net_params);
|
||||
testing_disable_reproducible_rng();
|
||||
}
|
||||
|
||||
/* Test reduced and disabled padding */
|
||||
@ -2409,6 +2436,7 @@ test_circuitpadding_reduce_disable(void *arg)
|
||||
int64_t actual_mocked_monotime_start;
|
||||
|
||||
MOCK(circuitmux_attach_circuit, circuitmux_attach_circuit_mock);
|
||||
testing_enable_reproducible_rng();
|
||||
|
||||
nodes_init();
|
||||
dummy_channel.cmux = circuitmux_alloc();
|
||||
@ -2548,6 +2576,7 @@ test_circuitpadding_reduce_disable(void *arg)
|
||||
free_fake_orcirc(relay_side);
|
||||
circuitmux_detach_all_circuits(dummy_channel.cmux, NULL);
|
||||
circuitmux_free(dummy_channel.cmux);
|
||||
testing_disable_reproducible_rng();
|
||||
}
|
||||
|
||||
#define TEST_CIRCUITPADDING(name, flags) \
|
||||
|
Loading…
Reference in New Issue
Block a user