aboutsummaryrefslogtreecommitdiff
path: root/src/test/test-timers.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2016-04-25 14:34:02 -0400
committerNick Mathewson <nickm@torproject.org>2016-05-09 14:04:54 -0400
commitaf132fc299f837f8749278099e6257cea3795e8e (patch)
tree338bfd1984a55745b6079fedd8c23d4b65d72f29 /src/test/test-timers.c
parent0a2f59aaa640d45e9b321cdfd33496ec68c7cc0a (diff)
downloadtor-af132fc299f837f8749278099e6257cea3795e8e.tar.gz
tor-af132fc299f837f8749278099e6257cea3795e8e.zip
timer tests: differences in timing accuracy can be negative.
Also, use symbolic names for good-enough thresholds for timer accuracy.
Diffstat (limited to 'src/test/test-timers.c')
-rw-r--r--src/test/test-timers.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/test/test-timers.c b/src/test/test-timers.c
index 10db20fbfc..8f5ba7b78a 100644
--- a/src/test/test-timers.c
+++ b/src/test/test-timers.c
@@ -83,7 +83,7 @@ main(int argc, char **argv)
event_base_loop(tor_libevent_get_base(), 0);
- uint64_t total_difference = 0;
+ int64_t total_difference = 0;
uint64_t total_square_difference = 0;
tor_assert(n_fired == n_active_timers);
for (i = 0; i < N_TIMERS; ++i) {
@@ -92,11 +92,11 @@ main(int argc, char **argv)
continue;
}
tor_assert(fired[i] == 1);
- uint64_t diff = difference[i].tv_usec + difference[i].tv_sec * 1000000;
+ int64_t diff = difference[i].tv_usec + difference[i].tv_sec * 1000000;
total_difference += diff;
total_square_difference += diff*diff;
}
- const uint64_t mean_diff = total_difference / n_active_timers;
+ const int64_t mean_diff = total_difference / n_active_timers;
printf("mean difference: "U64_FORMAT" usec\n",
U64_PRINTF_ARG(mean_diff));
@@ -105,11 +105,16 @@ main(int argc, char **argv)
const double stddev = sqrt(mean_sq - sq_mean);
printf("standard deviation: %lf usec\n", stddev);
- if (mean_diff > 500*1000 || stddev > 500*1000) {
+#define MAX_DIFF_USEC (500*1000)
+#define MAX_STDDEV_USEC (500*1000)
+#define ODD_DIFF_USEC (2000)
+#define ODD_STDDEV_USEC (2000)
+
+ if (mean_diff < 0 || mean_diff > MAX_DIFF_USEC || stddev > MAX_STDDEV_USEC) {
printf("Either your system is under ridiculous load, or the "
"timer backend is broken.\n");
ret = 1;
- } else if (mean_diff > 2000 || stddev > 2000) {
+ } else if (mean_diff > ODD_DIFF_USEC || stddev > ODD_STDDEV_USEC) {
printf("Either your system is a bit slow or the "
"timer backend is odd.\n");
ret = 0;