paragraph for gnunet devs that don't know how to use the web
[oweals/gnunet.git] / src / util / test_speedup.c
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2011-2013 GNUnet e.V.
4
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.
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      Affero General Public License for more details.
14     
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/>.
17 */
18 /**
19  * @file util/test_speedup.c
20  * @brief testcase for speedup.c
21  */
22 #include "platform.h"
23 #include "gnunet_util_lib.h"
24
25 /**
26  * Start time of the testcase
27  */
28 static struct GNUNET_TIME_Absolute start;
29
30 /**
31  * End-time of the testcase (affected by speed-up)
32  */
33 static struct GNUNET_TIME_Absolute end;
34
35 /**
36  * Number of cycles we have spent in 'run'.
37  */
38 static unsigned int cycles;
39
40
41 /**
42  * Main task that is scheduled with the speed-up.
43  *
44  * @param cls NULL
45  * @param tc scheduler context, unused
46  */
47 static void
48 run (void *cls)
49 {
50   cycles++;
51   fprintf (stderr, "..%u", cycles);
52   if (cycles <= 5)
53   {
54     GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
55                                   &run,
56                                   NULL);
57     return;
58   }
59   end = GNUNET_TIME_absolute_get();
60   fprintf (stderr, "\n");
61   fflush(stdout);
62 }
63
64
65 /**
66  *
67  */
68 static void
69 check (void *cls,
70        char *const *args,
71        const char *cfgfile,
72        const struct GNUNET_CONFIGURATION_Handle *cfg)
73 {
74   fprintf (stderr, "0");
75   fflush (stdout);
76   GNUNET_SCHEDULER_add_now (&run, NULL);
77 }
78
79
80 int
81 main (int argc, char *argv[])
82 {
83   static char *const argvn[] = {
84     "test-speedup",
85     "-c",  "test_speedup_data.conf",
86     NULL
87   };
88   static struct GNUNET_GETOPT_CommandLineOption options[] = {
89     GNUNET_GETOPT_OPTION_END
90   };
91   time_t start_real;
92   time_t end_real;
93   struct GNUNET_TIME_Relative delta;
94
95   start_real = time (NULL);
96   start = GNUNET_TIME_absolute_get();
97   GNUNET_PROGRAM_run ((sizeof (argvn) / sizeof (char *)) - 1, argvn, "test-speedup",
98                       "nohelp", options, &check, NULL);
99
100   end_real = time (NULL);
101   delta = GNUNET_TIME_absolute_get_difference (start, end);
102
103   if (delta.rel_value_us >  ((end_real - start_real) * 1500LL * 1000LL))
104   {
105     GNUNET_log  (GNUNET_ERROR_TYPE_DEBUG,
106                  "Execution time in GNUnet time: %s\n",
107                  GNUNET_STRINGS_relative_time_to_string (delta, GNUNET_YES));
108     GNUNET_log  (GNUNET_ERROR_TYPE_DEBUG,
109                  "Execution time in system time: %llu ms\n",
110                  (unsigned long long) ((end_real - start_real) * 1000LL));
111     return 0;
112   }
113   GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
114               "Execution time in GNUnet time: %s\n",
115               GNUNET_STRINGS_relative_time_to_string (delta, GNUNET_YES));
116   GNUNET_log  (GNUNET_ERROR_TYPE_ERROR,
117                "Execution time in system time: %llu ms\n",
118                (unsigned long long) ((end_real - start_real) * 1000LL));
119   return 1;
120 }
121
122 /* end of test_speedup.c */