diff options
author | Mike Perry <mikeperry-git@fscked.org> | 2010-05-12 15:31:22 -0700 |
---|---|---|
committer | Mike Perry <mikeperry-git@fscked.org> | 2010-05-12 15:31:22 -0700 |
commit | d9be6f38450fd4c20f5c3711e68676547997b23c (patch) | |
tree | 4083408446228ba747216e40d46eb6b37b77de66 /src | |
parent | 8ada0011f9a019ecabffc1d154447e6cb34c7567 (diff) | |
download | tor-d9be6f38450fd4c20f5c3711e68676547997b23c.tar tor-d9be6f38450fd4c20f5c3711e68676547997b23c.tar.gz |
Fix CBT unit tests.
Diffstat (limited to 'src')
-rw-r--r-- | src/or/circuitbuild.c | 40 | ||||
-rw-r--r-- | src/test/test.c | 4 |
2 files changed, 27 insertions, 17 deletions
diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c index 1d4d267b7..97e7c1c0f 100644 --- a/src/or/circuitbuild.c +++ b/src/or/circuitbuild.c @@ -84,22 +84,26 @@ static void entry_guards_changed(void); static int circuit_build_times_disabled(void) { - int consensus_disabled = networkstatus_get_param(NULL, "cbtdisabled", - 0); - int config_disabled = !get_options()->LearnCircuitBuildTimeout; - int dirauth_disabled = get_options()->AuthoritativeDir; - int state_disabled = (get_or_state()->LastWritten == -1); - - if (consensus_disabled || config_disabled || dirauth_disabled || - state_disabled) { - log_info(LD_CIRC, - "CircuitBuildTime learning is disabled. " - "Consensus=%d, Config=%d, AuthDir=%d, StateFile=%d", - consensus_disabled, config_disabled, dirauth_disabled, - state_disabled); - return 1; - } else { + if (unit_tests) { return 0; + } else { + int consensus_disabled = networkstatus_get_param(NULL, "cbtdisabled", + 0); + int config_disabled = !get_options()->LearnCircuitBuildTimeout; + int dirauth_disabled = get_options()->AuthoritativeDir; + int state_disabled = (get_or_state()->LastWritten == -1); + + if (consensus_disabled || config_disabled || dirauth_disabled || + state_disabled) { + log_info(LD_CIRC, + "CircuitBuildTime learning is disabled. " + "Consensus=%d, Config=%d, AuthDir=%d, StateFile=%d", + consensus_disabled, config_disabled, dirauth_disabled, + state_disabled); + return 1; + } else { + return 0; + } } } @@ -1104,6 +1108,12 @@ circuit_build_times_filter_timeouts(circuit_build_times_t *cbt) return 0; } + /* Do not filter for unit tests. They expect the distribution to be + * unchanged from run to run. */ + if (unit_tests) { + return 0; + } + timeout_rate = circuit_build_times_timeout_rate(cbt); max_timeout = (build_time_t)tor_lround(circuit_build_times_calculate_timeout(cbt, circuit_build_times_max_synthetic_quantile())); diff --git a/src/test/test.c b/src/test/test.c index 8d596981e..eb06c762d 100644 --- a/src/test/test.c +++ b/src/test/test.c @@ -494,7 +494,7 @@ test_circuit_timeout(void) timeout1 = circuit_build_times_calculate_timeout(&estimate, CBT_DEFAULT_QUANTILE_CUTOFF/100.0); circuit_build_times_set_timeout(&estimate); - log_warn(LD_CIRC, "Timeout is %lf, Xm is %d", timeout1, estimate.Xm); + log_warn(LD_CIRC, "Timeout1 is %lf, Xm is %d", timeout1, estimate.Xm); /* XXX: 5% distribution error may not be the right metric */ } while (fabs(circuit_build_times_cdf(&initial, timeout0) - circuit_build_times_cdf(&initial, timeout1)) > 0.05 @@ -511,7 +511,7 @@ test_circuit_timeout(void) CBT_DEFAULT_QUANTILE_CUTOFF/100.0); circuit_build_times_set_timeout(&final); - log_warn(LD_CIRC, "Timeout is %lf, Xm is %d", timeout2, final.Xm); + log_warn(LD_CIRC, "Timeout2 is %lf, Xm is %d", timeout2, final.Xm); test_assert(fabs(circuit_build_times_cdf(&initial, timeout0) - circuit_build_times_cdf(&initial, timeout2)) < 0.05); |