2 This file is part of GNUnet.
3 (C) 2001, 2002, 2003, 2004, 2006 Christian Grothoff (and other contributing authors)
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
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file util/test_scheduler_delay.c
22 * @brief testcase for delay of scheduler, measures how
23 * precise the timers are. Expect values between 10 and 20 ms on
27 #include "gnunet_common.h"
28 #include "gnunet_scheduler_lib.h"
29 #include "gnunet_time_lib.h"
31 #define VERBOSE GNUNET_NO
33 static struct GNUNET_TIME_Absolute target;
37 static unsigned long long cumDelta;
44 * Signature of the main function of a task.
50 test_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
52 struct GNUNET_TIME_Absolute now;
54 now = GNUNET_TIME_absolute_get ();
55 if (now.abs_value > target.abs_value)
56 cumDelta += (now.abs_value - target.abs_value);
58 cumDelta += (target.abs_value - now.abs_value);
60 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply
61 (GNUNET_TIME_UNIT_MILLISECONDS, i));
62 fprintf (stderr, ".");
65 fprintf (stderr, "\n");
68 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
69 (GNUNET_TIME_UNIT_MILLISECONDS, i),
77 target = GNUNET_TIME_absolute_get ();
78 GNUNET_SCHEDULER_run (&test_task, NULL);
80 "Sleep precision: %llu ms. ", cumDelta / 1000 / (MAXV / INCR));
81 if (cumDelta <= 10 * MAXV / INCR)
82 fprintf (stdout, "Timer precision is excellent.\n");
83 else if (cumDelta <= 50 * MAXV / INCR) /* 50 ms average deviation */
84 fprintf (stdout, "Timer precision is good.\n");
85 else if (cumDelta > 250 * MAXV / INCR)
86 fprintf (stdout, "Timer precision is awful.\n");
88 fprintf (stdout, "Timer precision is acceptable.\n");
93 main (int argc, char *argv[])
97 GNUNET_log_setup ("test-scheduler-delay", "WARNING", NULL);
103 /* end of test_scheduler_delay.c */