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