diff options
Diffstat (limited to 'src/util/test_scheduler_delay.c')
-rw-r--r-- | src/util/test_scheduler_delay.c | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/src/util/test_scheduler_delay.c b/src/util/test_scheduler_delay.c index 132066979..ce96213c7 100644 --- a/src/util/test_scheduler_delay.c +++ b/src/util/test_scheduler_delay.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2001, 2002, 2003, 2004, 2006 Christian Grothoff (and other contributing authors) | 3 | (C) 2001-2013 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -20,13 +20,11 @@ | |||
20 | /** | 20 | /** |
21 | * @file util/test_scheduler_delay.c | 21 | * @file util/test_scheduler_delay.c |
22 | * @brief testcase for delay of scheduler, measures how | 22 | * @brief testcase for delay of scheduler, measures how |
23 | * precise the timers are. Expect values between 10 and 20 ms on | 23 | * precise the timers are. Expect values between 0.2 and 2 ms on |
24 | * modern machines. | 24 | * modern machines. |
25 | */ | 25 | */ |
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_common.h" | 27 | #include "gnunet_util_lib.h" |
28 | #include "gnunet_scheduler_lib.h" | ||
29 | #include "gnunet_time_lib.h" | ||
30 | 28 | ||
31 | static struct GNUNET_TIME_Absolute target; | 29 | static struct GNUNET_TIME_Absolute target; |
32 | 30 | ||
@@ -36,7 +34,8 @@ static unsigned long long cumDelta; | |||
36 | 34 | ||
37 | #define INCR 47 | 35 | #define INCR 47 |
38 | 36 | ||
39 | #define MAXV 1500 | 37 | #define MAXV 5000 |
38 | |||
40 | 39 | ||
41 | /** | 40 | /** |
42 | * Signature of the main function of a task. | 41 | * Signature of the main function of a task. |
@@ -45,18 +44,19 @@ static unsigned long long cumDelta; | |||
45 | * @param tc context | 44 | * @param tc context |
46 | */ | 45 | */ |
47 | static void | 46 | static void |
48 | test_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 47 | test_task (void *cls, |
48 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
49 | { | 49 | { |
50 | struct GNUNET_TIME_Absolute now; | 50 | struct GNUNET_TIME_Absolute now; |
51 | 51 | ||
52 | now = GNUNET_TIME_absolute_get (); | 52 | now = GNUNET_TIME_absolute_get (); |
53 | if (now.abs_value > target.abs_value) | 53 | if (now.abs_value_us > target.abs_value_us) |
54 | cumDelta += (now.abs_value - target.abs_value); | 54 | cumDelta += (now.abs_value_us - target.abs_value_us); |
55 | else | 55 | else |
56 | cumDelta += (target.abs_value - now.abs_value); | 56 | cumDelta += (target.abs_value_us - now.abs_value_us); |
57 | target = | 57 | target = |
58 | GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply | 58 | GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply |
59 | (GNUNET_TIME_UNIT_MILLISECONDS, i)); | 59 | (GNUNET_TIME_UNIT_MICROSECONDS, i)); |
60 | FPRINTF (stderr, "%s", "."); | 60 | FPRINTF (stderr, "%s", "."); |
61 | if (i > MAXV) | 61 | if (i > MAXV) |
62 | { | 62 | { |
@@ -64,7 +64,7 @@ test_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
64 | return; | 64 | return; |
65 | } | 65 | } |
66 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 66 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
67 | (GNUNET_TIME_UNIT_MILLISECONDS, i), &test_task, | 67 | (GNUNET_TIME_UNIT_MICROSECONDS, i), &test_task, |
68 | NULL); | 68 | NULL); |
69 | i += INCR; | 69 | i += INCR; |
70 | } | 70 | } |
@@ -76,13 +76,14 @@ main (int argc, char *argv[]) | |||
76 | GNUNET_log_setup ("test-scheduler-delay", "WARNING", NULL); | 76 | GNUNET_log_setup ("test-scheduler-delay", "WARNING", NULL); |
77 | target = GNUNET_TIME_absolute_get (); | 77 | target = GNUNET_TIME_absolute_get (); |
78 | GNUNET_SCHEDULER_run (&test_task, NULL); | 78 | GNUNET_SCHEDULER_run (&test_task, NULL); |
79 | FPRINTF (stdout, "Sleep precision: %llu ms. ", | 79 | FPRINTF (stdout, |
80 | cumDelta / 1000 / (MAXV / INCR)); | 80 | "Sleep precision: %llu microseconds (average delta). ", |
81 | if (cumDelta <= 10 * MAXV / INCR) | 81 | cumDelta / (MAXV / INCR)); |
82 | if (cumDelta <= 500 * MAXV / INCR) | ||
82 | FPRINTF (stdout, "%s", "Timer precision is excellent.\n"); | 83 | FPRINTF (stdout, "%s", "Timer precision is excellent.\n"); |
83 | else if (cumDelta <= 50 * MAXV / INCR) /* 50 ms average deviation */ | 84 | else if (cumDelta <= 5000 * MAXV / INCR) /* 5 ms average deviation */ |
84 | FPRINTF (stdout, "%s", "Timer precision is good.\n"); | 85 | FPRINTF (stdout, "%s", "Timer precision is good.\n"); |
85 | else if (cumDelta > 250 * MAXV / INCR) | 86 | else if (cumDelta > 25000 * MAXV / INCR) |
86 | FPRINTF (stdout, "%s", "Timer precision is awful.\n"); | 87 | FPRINTF (stdout, "%s", "Timer precision is awful.\n"); |
87 | else | 88 | else |
88 | FPRINTF (stdout, "%s", "Timer precision is acceptable.\n"); | 89 | FPRINTF (stdout, "%s", "Timer precision is acceptable.\n"); |