2 This file is part of GNUnet.
3 Copyright (C) 2001-2013 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * @file util/test_scheduler_delay.c
20 * @brief testcase for delay of scheduler, measures how
21 * precise the timers are. Expect values between 0.2 and 2 ms on
25 #include "gnunet_util_lib.h"
27 static struct GNUNET_TIME_Absolute target;
31 static unsigned long long cumDelta;
39 * Signature of the main function of a task.
46 struct GNUNET_TIME_Absolute now;
48 now = GNUNET_TIME_absolute_get ();
49 if (now.abs_value_us > target.abs_value_us)
50 cumDelta += (now.abs_value_us - target.abs_value_us);
52 cumDelta += (target.abs_value_us - now.abs_value_us);
54 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply
55 (GNUNET_TIME_UNIT_MICROSECONDS, i));
56 FPRINTF (stderr, "%s", ".");
59 FPRINTF (stderr, "%s", "\n");
62 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
63 (GNUNET_TIME_UNIT_MICROSECONDS, i),
71 main (int argc, char *argv[])
73 GNUNET_log_setup ("test-scheduler-delay",
76 target = GNUNET_TIME_absolute_get ();
77 GNUNET_SCHEDULER_run (&test_task, NULL);
79 "Sleep precision: %llu microseconds (average delta). ",
80 cumDelta / (MAXV / INCR));
81 if (cumDelta <= 500 * MAXV / INCR)
82 FPRINTF (stdout, "%s", "Timer precision is excellent.\n");
83 else if (cumDelta <= 5000 * MAXV / INCR) /* 5 ms average deviation */
84 FPRINTF (stdout, "%s", "Timer precision is good.\n");
85 else if (cumDelta > 25000 * MAXV / INCR)
86 FPRINTF (stdout, "%s", "Timer precision is awful.\n");
88 FPRINTF (stdout, "%s", "Timer precision is acceptable.\n");
92 /* end of test_scheduler_delay.c */