aboutsummaryrefslogtreecommitdiff
path: root/src/util/test_speedup.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-05-30 14:47:45 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-05-30 14:47:45 +0000
commit8f654f30c3c4987c9ca1b564d6e6f2d75ae24862 (patch)
tree5930e87f3e34c36610bc707e04a594f9b47432c2 /src/util/test_speedup.c
parentf3285213446b9d75720621711de099e26ea83506 (diff)
downloadgnunet-8f654f30c3c4987c9ca1b564d6e6f2d75ae24862.tar.gz
gnunet-8f654f30c3c4987c9ca1b564d6e6f2d75ae24862.zip
speedup mechanism to manipulate gnunet time
Diffstat (limited to 'src/util/test_speedup.c')
-rw-r--r--src/util/test_speedup.c101
1 files changed, 101 insertions, 0 deletions
diff --git a/src/util/test_speedup.c b/src/util/test_speedup.c
new file mode 100644
index 000000000..849505c24
--- /dev/null
+++ b/src/util/test_speedup.c
@@ -0,0 +1,101 @@
1/*
2 This file is part of GNUnet.
3 (C) 2001, 2002, 2003, 2004, 2006, 2009 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 3, 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_speedup.c
22 * @brief testcase for speedup.c
23 */
24#include "platform.h"
25#include "gnunet_common.h"
26#include "gnunet_program_lib.h"
27#include "gnunet_time_lib.h"
28#include "gnunet_strings_lib.h"
29
30
31#define VERBOSE GNUNET_NO
32
33static struct GNUNET_TIME_Absolute start;
34static struct GNUNET_TIME_Absolute end;
35static int cycles;
36
37static void
38run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
39{
40
41 cycles ++;
42 printf ("..%u", cycles);
43 fflush(stdout);
44 if (cycles <= 5)
45 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &run, NULL);
46 else
47 {
48 end = GNUNET_TIME_absolute_get();
49 printf ("\n");
50 fflush(stdout);
51 }
52}
53
54void check (void *cls, char *const *args,
55 const char *cfgfile,
56 const struct GNUNET_CONFIGURATION_Handle *
57 cfg)
58{
59 printf ("0");
60 fflush(stdout);
61 GNUNET_SCHEDULER_add_now(&run, NULL);
62}
63
64
65int
66main (int argc, char *argv[])
67{
68 time_t start_real;
69 time_t end_real;
70 struct GNUNET_TIME_Relative delta;
71
72 static char *const argvn[] = { "test-speedup",
73 "-c",
74 "test_speedup_data.conf",
75#if VERBOSE
76 "-L", "DEBUG",
77#endif
78 NULL
79 };
80 start_real = time (NULL);
81 start = GNUNET_TIME_absolute_get();
82 static struct GNUNET_GETOPT_CommandLineOption options[] = {
83 GNUNET_GETOPT_OPTION_END
84 };
85
86 GNUNET_PROGRAM_run ((sizeof (argvn) / sizeof (char *)) - 1, argvn, "test-speedup",
87 "nohelp", options, &check, NULL);
88
89 end_real = time (NULL);
90 delta = GNUNET_TIME_absolute_get_difference(start, end);
91
92 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Execution time in GNUnet time: %llu ms\n", delta.rel_value);
93 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Execution time in system time: %llu ms\n", (end_real - start_real) * 1000);
94
95 if (delta.rel_value > ((end_real - start_real) * 1500))
96 return 0;
97 else
98 return 1;
99}
100
101/* end of test_speedup.c */