From: Nick Mathewson Date: Fri, 14 Sep 2018 12:40:10 +0000 (-0400) Subject: Make circuitmux ewma timing test more tolerant on 32bit osx X-Git-Tag: tor-0.3.5.2-alpha~15^2^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6e5e1be7375e6e8de38af1f8c2c13e35d745edea;p=thirdparty%2Ftor.git Make circuitmux ewma timing test more tolerant on 32bit osx Since we use a 32-bit approximation for millisecond conversion here, we can't expect so much precision. Fixes part of bug 27139; bugfix on 0.3.4.1-alpha. --- diff --git a/src/common/compat_time.h b/src/common/compat_time.h index 57ab20ab11..f241aa5eba 100644 --- a/src/common/compat_time.h +++ b/src/common/compat_time.h @@ -196,6 +196,7 @@ monotime_coarse_diff_msec32(const monotime_coarse_t *start, // on a 64-bit platform, let's assume 64/64 division is cheap. return (int32_t) monotime_coarse_diff_msec(start, end); #else +#define USING_32BIT_MSEC_HACK return monotime_coarse_diff_msec32_(start, end); #endif } diff --git a/src/test/test_circuitmux.c b/src/test/test_circuitmux.c index 14c7598703..c81d53ae51 100644 --- a/src/test/test_circuitmux.c +++ b/src/test/test_circuitmux.c @@ -13,6 +13,8 @@ #include "scheduler.h" #include "test.h" +#include + /* XXXX duplicated function from test_circuitlist.c */ static channel_t * new_fake_channel(void) @@ -103,16 +105,19 @@ test_cmux_compute_ticks(void *arg) monotime_coarse_set_mock_time_nsec(now); tick = cell_ewma_get_current_tick_and_fraction(&rem); tt_uint_op(tick, OP_EQ, tick_zero); - tt_double_op(rem, OP_GT, .149999999); - tt_double_op(rem, OP_LT, .150000001); +#ifdef USING_32BIT_MSEC_HACK + const double tolerance = .0005; +#else + const double tolerance = .00000001; +#endif + tt_double_op(fabs(rem - .15), OP_LT, tolerance); /* 25 second later and we should be in another tick. */ now = START_NS + NS_PER_S * 25; monotime_coarse_set_mock_time_nsec(now); tick = cell_ewma_get_current_tick_and_fraction(&rem); tt_uint_op(tick, OP_EQ, tick_zero + 2); - tt_double_op(rem, OP_GT, .499999999); - tt_double_op(rem, OP_LT, .500000001); + tt_double_op(fabs(rem - .5), OP_LT, tolerance); done: ;