aboutsummaryrefslogtreecommitdiff
path: root/src/util/test_scheduler_delay.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2009-05-29 00:46:26 +0000
committerChristian Grothoff <christian@grothoff.org>2009-05-29 00:46:26 +0000
commit0a217a8df1657b4334b55b0e4a6c7837a8dbcfd9 (patch)
tree6b552f40eb089db96409a312a98d9b12bd669102 /src/util/test_scheduler_delay.c
downloadgnunet-0a217a8df1657b4334b55b0e4a6c7837a8dbcfd9.tar.gz
gnunet-0a217a8df1657b4334b55b0e4a6c7837a8dbcfd9.zip
ng
Diffstat (limited to 'src/util/test_scheduler_delay.c')
-rw-r--r--src/util/test_scheduler_delay.c107
1 files changed, 107 insertions, 0 deletions
diff --git a/src/util/test_scheduler_delay.c b/src/util/test_scheduler_delay.c
new file mode 100644
index 000000000..76cbf94d8
--- /dev/null
+++ b/src/util/test_scheduler_delay.c
@@ -0,0 +1,107 @@
1/*
2 This file is part of GNUnet.
3 (C) 2001, 2002, 2003, 2004, 2006 Christian Grothoff (and other contributing authors)
4
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 2, or (at your
8 option) any later version.
9
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.
14
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.
19*/
20/**
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
24 * modern machines.
25 */
26#include "platform.h"
27#include "gnunet_common.h"
28#include "gnunet_scheduler_lib.h"
29#include "gnunet_time_lib.h"
30
31#define VERBOSE GNUNET_NO
32
33static struct GNUNET_TIME_Absolute target;
34
35static int i;
36
37static unsigned long long cumDelta;
38
39#define INCR 47
40
41#define MAXV 1500
42
43/**
44 * Signature of the main function of a task.
45 *
46 * @param cls closure
47 * @param tc context
48 */
49static void
50test_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
51{
52 struct GNUNET_TIME_Absolute now;
53
54 now = GNUNET_TIME_absolute_get ();
55 if (now.value > target.value)
56 cumDelta += (now.value - target.value);
57 else
58 cumDelta += (target.value - now.value);
59 target =
60 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply
61 (GNUNET_TIME_UNIT_MILLISECONDS, i));
62 fprintf (stderr, ".");
63 if (i > MAXV)
64 {
65 fprintf (stderr, "\n");
66 return;
67 }
68 GNUNET_SCHEDULER_add_delayed (tc->sched,
69 GNUNET_NO,
70 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
71 GNUNET_SCHEDULER_NO_PREREQUISITE_TASK,
72 GNUNET_TIME_relative_multiply
73 (GNUNET_TIME_UNIT_MILLISECONDS, i),
74 &test_task, NULL);
75 i += INCR;
76}
77
78static int
79check ()
80{
81 target = GNUNET_TIME_absolute_get ();
82 GNUNET_SCHEDULER_run (&test_task, NULL);
83 FPRINTF (stdout,
84 "Sleep precision: %llu ms. ", cumDelta / 1000 / (MAXV / INCR));
85 if (cumDelta <= 10 * MAXV / INCR)
86 fprintf (stdout, "Timer precision is excellent.\n");
87 else if (cumDelta <= 50 * MAXV / INCR) /* 50 ms average deviation */
88 fprintf (stdout, "Timer precision is good.\n");
89 else if (cumDelta > 250 * MAXV / INCR)
90 fprintf (stdout, "Timer precision is awful.\n");
91 else
92 fprintf (stdout, "Timer precision is acceptable.\n");
93 return 0;
94}
95
96int
97main (int argc, char *argv[])
98{
99 int ret;
100
101 GNUNET_log_setup ("test-scheduler-delay", "WARNING", NULL);
102 ret = check ();
103
104 return ret;
105}
106
107/* end of test_scheduler_delay.c */