test_scheduler_delay.c | test_scheduler_delay.c | |||
---|---|---|---|---|
skipping to change at line 31 | skipping to change at line 31 | |||
* @file util/test_scheduler_delay.c | * @file util/test_scheduler_delay.c | |||
* @brief testcase for delay of scheduler, measures how | * @brief testcase for delay of scheduler, measures how | |||
* precise the timers are. Expect values between 10 and 20 ms on | * precise the timers are. Expect values between 10 and 20 ms on | |||
* modern machines. | * modern machines. | |||
*/ | */ | |||
#include "platform.h" | #include "platform.h" | |||
#include "gnunet_common.h" | #include "gnunet_common.h" | |||
#include "gnunet_scheduler_lib.h" | #include "gnunet_scheduler_lib.h" | |||
#include "gnunet_time_lib.h" | #include "gnunet_time_lib.h" | |||
#define VERBOSE GNUNET_EXTRA_LOGGING | #define VERBOSE GNUNET_NO | |||
static struct GNUNET_TIME_Absolute target; | static struct GNUNET_TIME_Absolute target; | |||
static int i; | static int i; | |||
static unsigned long long cumDelta; | static unsigned long long cumDelta; | |||
#define INCR 47 | #define INCR 47 | |||
#define MAXV 1500 | #define MAXV 1500 | |||
skipping to change at line 62 | skipping to change at line 62 | |||
struct GNUNET_TIME_Absolute now; | struct GNUNET_TIME_Absolute now; | |||
now = GNUNET_TIME_absolute_get (); | now = GNUNET_TIME_absolute_get (); | |||
if (now.abs_value > target.abs_value) | if (now.abs_value > target.abs_value) | |||
cumDelta += (now.abs_value - target.abs_value); | cumDelta += (now.abs_value - target.abs_value); | |||
else | else | |||
cumDelta += (target.abs_value - now.abs_value); | cumDelta += (target.abs_value - now.abs_value); | |||
target = | target = | |||
GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply | GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply | |||
(GNUNET_TIME_UNIT_MILLISECONDS, i)) ; | (GNUNET_TIME_UNIT_MILLISECONDS, i)) ; | |||
fprintf (stderr, "."); | FPRINTF (stderr, "%s", "."); | |||
if (i > MAXV) | if (i > MAXV) | |||
{ | { | |||
fprintf (stderr, "\n"); | FPRINTF (stderr, "%s", "\n"); | |||
return; | return; | |||
} | } | |||
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | |||
(GNUNET_TIME_UNIT_MILLISECONDS, i), &test_t ask, | (GNUNET_TIME_UNIT_MILLISECONDS, i), &test_t ask, | |||
NULL); | NULL); | |||
i += INCR; | i += INCR; | |||
} | } | |||
static int | static int | |||
check () | check () | |||
{ | { | |||
target = GNUNET_TIME_absolute_get (); | target = GNUNET_TIME_absolute_get (); | |||
GNUNET_SCHEDULER_run (&test_task, NULL); | GNUNET_SCHEDULER_run (&test_task, NULL); | |||
FPRINTF (stdout, "Sleep precision: %llu ms. ", | FPRINTF (stdout, "Sleep precision: %llu ms. ", | |||
cumDelta / 1000 / (MAXV / INCR)); | cumDelta / 1000 / (MAXV / INCR)); | |||
if (cumDelta <= 10 * MAXV / INCR) | if (cumDelta <= 10 * MAXV / INCR) | |||
fprintf (stdout, "Timer precision is excellent.\n"); | FPRINTF (stdout, "%s", "Timer precision is excellent.\n"); | |||
else if (cumDelta <= 50 * MAXV / INCR) /* 50 ms average deviation */ | else if (cumDelta <= 50 * MAXV / INCR) /* 50 ms average deviation */ | |||
fprintf (stdout, "Timer precision is good.\n"); | FPRINTF (stdout, "%s", "Timer precision is good.\n"); | |||
else if (cumDelta > 250 * MAXV / INCR) | else if (cumDelta > 250 * MAXV / INCR) | |||
fprintf (stdout, "Timer precision is awful.\n"); | FPRINTF (stdout, "%s", "Timer precision is awful.\n"); | |||
else | else | |||
fprintf (stdout, "Timer precision is acceptable.\n"); | FPRINTF (stdout, "%s", "Timer precision is acceptable.\n"); | |||
return 0; | return 0; | |||
} | } | |||
int | int | |||
main (int argc, char *argv[]) | main (int argc, char *argv[]) | |||
{ | { | |||
int ret; | int ret; | |||
GNUNET_log_setup ("test-scheduler-delay", "WARNING", NULL); | GNUNET_log_setup ("test-scheduler-delay", "WARNING", NULL); | |||
ret = check (); | ret = check (); | |||
End of changes. 7 change blocks. | ||||
7 lines changed or deleted | 7 lines changed or added | |||
This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/ |