[or-cvs] [tor/master] Fix unit tests and compile issues on Snow Leopard
arma at seul.org
arma at seul.org
Thu Sep 17 01:46:27 UTC 2009
Author: Sebastian Hahn <sebastian at torproject.org>
Date: Thu, 17 Sep 2009 00:20:25 +0200
Subject: Fix unit tests and compile issues on Snow Leopard
Commit: 1aac7de1ea8cacf2d93f25dc7a4366350035c91c
---
src/or/circuitbuild.c | 27 +++++++++++++++++----------
src/or/test.c | 4 ++--
2 files changed, 19 insertions(+), 12 deletions(-)
diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
index 1cb1fd2..c20db4b 100644
--- a/src/or/circuitbuild.c
+++ b/src/or/circuitbuild.c
@@ -368,13 +368,15 @@ circuit_build_times_parse_state(circuit_build_times_t *cbt,
uint32_t count, k;
build_time_t ms;
int ok;
- ms = tor_parse_ulong(ms_str, 0, 0, BUILD_TIME_MAX, &ok, NULL);
+ ms = (build_time_t)tor_parse_ulong(ms_str, 0, 0,
+ BUILD_TIME_MAX, &ok, NULL);
if (!ok) {
*msg = tor_strdup("Unable to parse circuit build times: "
"Unparsable bin number");
break;
}
- count = tor_parse_ulong(count_str, 0, 0, UINT32_MAX, &ok, NULL);
+ count = (uint32_t)tor_parse_ulong(count_str, 0, 0,
+ UINT32_MAX, &ok, NULL);
if (!ok) {
*msg = tor_strdup("Unable to parse circuit build times: "
"Unparsable bin count");
@@ -405,7 +407,7 @@ circuit_build_times_parse_state(circuit_build_times_t *cbt,
tor_assert(cbt->total_build_times == state->TotalBuildTimes);
tor_assert(tot_values == cbt->total_build_times);
circuit_build_times_set_timeout(cbt);
- return msg ? -1 : 0;
+ return *msg ? -1 : 0;
}
/**
@@ -516,7 +518,8 @@ circuit_build_times_generate_sample(circuit_build_times_t *cbt,
u = q_lo + ((q_hi-q_lo)*r)/(1.0*UINT64_MAX);
tor_assert(0 <= u && u < 1.0);
- ret = lround(circuit_build_times_calculate_timeout(cbt, u));
+ /* circuit_build_times_calculate_timeout returns <= INT32_MAX */
+ ret = (uint32_t)lround(circuit_build_times_calculate_timeout(cbt, u));
tor_assert(ret > 0);
return ret;
}
@@ -704,12 +707,12 @@ circuit_build_times_check_too_many_timeouts(circuit_build_times_t *cbt)
cbt->Xm = Xm;
circuit_build_times_initial_alpha(cbt, 1.0-timeout_rate,
- cbt->timeout*1000.0);
+ cbt->timeout*1000);
timeout = circuit_build_times_calculate_timeout(cbt,
BUILDTIMEOUT_QUANTILE_CUTOFF);
-
- cbt->timeout = lround(timeout/1000.0);
+ /* timeout is INT32_MAX at most */
+ cbt->timeout = (uint32_t)lround(timeout/1000.0);
if (cbt->timeout < BUILD_TIMEOUT_MIN_VALUE) {
log_warn(LD_CIRC, "Reset buildtimeout to low value %lf. Setting to %d",
@@ -779,7 +782,8 @@ circuit_build_times_set_timeout(circuit_build_times_t *cbt)
BUILDTIMEOUT_QUANTILE_CUTOFF);
cbt->have_computed_timeout = 1;
- cbt->timeout = lround(timeout/1000.0);
+ /* timeout is INT32_MAX at most */
+ cbt->timeout = (uint32_t)lround(timeout/1000.0);
if (cbt->timeout < BUILD_TIMEOUT_MIN_VALUE) {
log_warn(LD_CIRC, "Set buildtimeout to low value %lf. Setting to %d",
@@ -1376,11 +1380,14 @@ circuit_send_next_onion_skin(origin_circuit_t *circ)
hop = onion_next_hop_in_cpath(circ->cpath);
if (!hop) {
struct timeval end;
+ long timediff;
tor_gettimeofday(&end);
+ timediff = tv_mdiff(&circ->_base.highres_created, &end);
+ if (timediff > INT32_MAX)
+ timediff = INT32_MAX;
/* done building the circuit. whew. */
circuit_set_state(TO_CIRCUIT(circ), CIRCUIT_STATE_OPEN);
- circuit_build_times_add_time(&circ_times,
- tv_mdiff(&circ->_base.highres_created, &end));
+ circuit_build_times_add_time(&circ_times, (uint32_t)timediff);
circuit_build_times_set_timeout(&circ_times);
log_info(LD_CIRC,"circuit built!");
circuit_reset_failure_count(0);
diff --git a/src/or/test.c b/src/or/test.c
index 06bfcce..df7bead 100644
--- a/src/or/test.c
+++ b/src/or/test.c
@@ -3436,7 +3436,7 @@ test_circuit_timeout(void)
memset(&state, 0, sizeof(or_state_t));
circuitbuild_running_unit_tests();
-#define timeout0 (30*1000.0)
+#define timeout0 (build_time_t)(30*1000.0)
initial.Xm = 750;
circuit_build_times_initial_alpha(&initial, BUILDTIMEOUT_QUANTILE_CUTOFF,
timeout0);
@@ -3444,7 +3444,7 @@ test_circuit_timeout(void)
int n = 0;
for (i=0; i < MIN_CIRCUITS_TO_OBSERVE; i++) {
if (circuit_build_times_add_time(&estimate,
- circuit_build_times_generate_sample(&initial, 0, 1)) == 0) {
+ circuit_build_times_generate_sample(&initial, 0, .98)) == 0) {
n++;
}
}
--
1.5.6.5
More information about the tor-commits
mailing list