[tor-commits] [tor/master] timer tests: differences in timing accuracy can be negative.
nickm at torproject.org
nickm at torproject.org
Mon May 9 18:08:56 UTC 2016
commit af132fc299f837f8749278099e6257cea3795e8e
Author: Nick Mathewson <nickm at torproject.org>
Date: Mon Apr 25 14:34:02 2016 -0400
timer tests: differences in timing accuracy can be negative.
Also, use symbolic names for good-enough thresholds for timer accuracy.
---
src/test/test-timers.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/src/test/test-timers.c b/src/test/test-timers.c
index 10db20f..8f5ba7b 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;
More information about the tor-commits
mailing list