aboutsummaryrefslogtreecommitdiff
path: root/src/statistics/test_statistics_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/statistics/test_statistics_api.c')
-rw-r--r--src/statistics/test_statistics_api.c297
1 files changed, 148 insertions, 149 deletions
diff --git a/src/statistics/test_statistics_api.c b/src/statistics/test_statistics_api.c
index 7a0756cda..b21fa5ef1 100644
--- a/src/statistics/test_statistics_api.c
+++ b/src/statistics/test_statistics_api.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file statistics/test_statistics_api.c 21 * @file statistics/test_statistics_api.c
22 * @brief testcase for statistics_api.c 22 * @brief testcase for statistics_api.c
@@ -33,220 +33,219 @@ static struct GNUNET_STATISTICS_GetHandle *g;
33 33
34 34
35static void 35static void
36do_shutdown () 36do_shutdown()
37{ 37{
38 if (NULL != g) 38 if (NULL != g)
39 { 39 {
40 GNUNET_STATISTICS_get_cancel (g); 40 GNUNET_STATISTICS_get_cancel(g);
41 g = NULL; 41 g = NULL;
42 } 42 }
43 GNUNET_STATISTICS_destroy (h, GNUNET_NO); 43 GNUNET_STATISTICS_destroy(h, GNUNET_NO);
44 h = NULL; 44 h = NULL;
45} 45}
46 46
47 47
48static int 48static int
49check_1 (void *cls, 49check_1(void *cls,
50 const char *subsystem, 50 const char *subsystem,
51 const char *name, 51 const char *name,
52 uint64_t value, 52 uint64_t value,
53 int is_persistent) 53 int is_persistent)
54{ 54{
55 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 55 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
56 "Received value %llu for `%s:%s\n", 56 "Received value %llu for `%s:%s\n",
57 (unsigned long long) value, 57 (unsigned long long)value,
58 subsystem, 58 subsystem,
59 name); 59 name);
60 GNUNET_assert (0 == strcmp (name, "test-1")); 60 GNUNET_assert(0 == strcmp(name, "test-1"));
61 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api")); 61 GNUNET_assert(0 == strcmp(subsystem, "test-statistics-api"));
62 GNUNET_assert (value == 1); 62 GNUNET_assert(value == 1);
63 GNUNET_assert (is_persistent == GNUNET_NO); 63 GNUNET_assert(is_persistent == GNUNET_NO);
64 return GNUNET_OK; 64 return GNUNET_OK;
65} 65}
66 66
67 67
68static int 68static int
69check_2 (void *cls, 69check_2(void *cls,
70 const char *subsystem, 70 const char *subsystem,
71 const char *name, 71 const char *name,
72 uint64_t value, 72 uint64_t value,
73 int is_persistent) 73 int is_persistent)
74{ 74{
75 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 75 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
76 "Received value %llu for `%s:%s\n", 76 "Received value %llu for `%s:%s\n",
77 (unsigned long long) value, 77 (unsigned long long)value,
78 subsystem, 78 subsystem,
79 name); 79 name);
80 GNUNET_assert (0 == strcmp (name, "test-2")); 80 GNUNET_assert(0 == strcmp(name, "test-2"));
81 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api")); 81 GNUNET_assert(0 == strcmp(subsystem, "test-statistics-api"));
82 GNUNET_assert (value == 2); 82 GNUNET_assert(value == 2);
83 GNUNET_assert (is_persistent == GNUNET_NO); 83 GNUNET_assert(is_persistent == GNUNET_NO);
84 return GNUNET_OK; 84 return GNUNET_OK;
85} 85}
86 86
87 87
88static int 88static int
89check_3 (void *cls, 89check_3(void *cls,
90 const char *subsystem, 90 const char *subsystem,
91 const char *name, 91 const char *name,
92 uint64_t value, 92 uint64_t value,
93 int is_persistent) 93 int is_persistent)
94{ 94{
95 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 95 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
96 "Received value %llu for `%s:%s\n", 96 "Received value %llu for `%s:%s\n",
97 (unsigned long long) value, 97 (unsigned long long)value,
98 subsystem, 98 subsystem,
99 name); 99 name);
100 GNUNET_assert (0 == strcmp (name, "test-3")); 100 GNUNET_assert(0 == strcmp(name, "test-3"));
101 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api")); 101 GNUNET_assert(0 == strcmp(subsystem, "test-statistics-api"));
102 GNUNET_assert (value == 3); 102 GNUNET_assert(value == 3);
103 GNUNET_assert (is_persistent == GNUNET_YES); 103 GNUNET_assert(is_persistent == GNUNET_YES);
104 return GNUNET_OK; 104 return GNUNET_OK;
105} 105}
106 106
107 107
108static void 108static void
109next_fin (void *cls, 109next_fin(void *cls,
110 int success) 110 int success)
111{ 111{
112 int *ok = cls; 112 int *ok = cls;
113 113
114 g = NULL; 114 g = NULL;
115 GNUNET_SCHEDULER_shutdown (); 115 GNUNET_SCHEDULER_shutdown();
116 GNUNET_assert (success == GNUNET_OK); 116 GNUNET_assert(success == GNUNET_OK);
117 *ok = 0; 117 *ok = 0;
118} 118}
119 119
120 120
121static void 121static void
122next (void *cls, int success) 122next(void *cls, int success)
123{ 123{
124 g = NULL; 124 g = NULL;
125 GNUNET_assert (success == GNUNET_OK); 125 GNUNET_assert(success == GNUNET_OK);
126 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 126 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
127 "Issuing GET request\n"); 127 "Issuing GET request\n");
128 GNUNET_break (NULL != 128 GNUNET_break(NULL !=
129 GNUNET_STATISTICS_get (h, NULL, "test-2", 129 GNUNET_STATISTICS_get(h, NULL, "test-2",
130 &next_fin, 130 &next_fin,
131 &check_2, cls)); 131 &check_2, cls));
132} 132}
133 133
134 134
135static void 135static void
136run (void *cls, 136run(void *cls,
137 char *const *args, 137 char *const *args,
138 const char *cfgfile, 138 const char *cfgfile,
139 const struct GNUNET_CONFIGURATION_Handle *cfg) 139 const struct GNUNET_CONFIGURATION_Handle *cfg)
140{ 140{
141 h = GNUNET_STATISTICS_create ("test-statistics-api", cfg); 141 h = GNUNET_STATISTICS_create("test-statistics-api", cfg);
142 if (NULL == h) 142 if (NULL == h)
143 { 143 {
144 GNUNET_break (0); 144 GNUNET_break(0);
145 return; 145 return;
146 } 146 }
147 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 147 GNUNET_SCHEDULER_add_shutdown(&do_shutdown,
148 NULL); 148 NULL);
149 GNUNET_STATISTICS_set (h, "test-1", 1, GNUNET_NO); 149 GNUNET_STATISTICS_set(h, "test-1", 1, GNUNET_NO);
150 GNUNET_STATISTICS_set (h, "test-2", 2, GNUNET_NO); 150 GNUNET_STATISTICS_set(h, "test-2", 2, GNUNET_NO);
151 GNUNET_STATISTICS_set (h, "test-3", 2, GNUNET_NO); 151 GNUNET_STATISTICS_set(h, "test-3", 2, GNUNET_NO);
152 GNUNET_STATISTICS_update (h, "test-3", 1, GNUNET_YES); 152 GNUNET_STATISTICS_update(h, "test-3", 1, GNUNET_YES);
153 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 153 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
154 "Issuing GET request\n"); 154 "Issuing GET request\n");
155 GNUNET_break (NULL != 155 GNUNET_break(NULL !=
156 (g = GNUNET_STATISTICS_get (h, NULL, "test-1", 156 (g = GNUNET_STATISTICS_get(h, NULL, "test-1",
157 &next, 157 &next,
158 &check_1, cls))); 158 &check_1, cls)));
159} 159}
160 160
161 161
162static void 162static void
163run_more (void *cls, 163run_more(void *cls,
164 char *const *args, 164 char *const *args,
165 const char *cfgfile, 165 const char *cfgfile,
166 const struct GNUNET_CONFIGURATION_Handle *cfg) 166 const struct GNUNET_CONFIGURATION_Handle *cfg)
167{ 167{
168 h = GNUNET_STATISTICS_create ("test-statistics-api", 168 h = GNUNET_STATISTICS_create("test-statistics-api",
169 cfg); 169 cfg);
170 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 170 GNUNET_SCHEDULER_add_shutdown(&do_shutdown,
171 NULL); 171 NULL);
172 GNUNET_break (NULL != 172 GNUNET_break(NULL !=
173 (g = GNUNET_STATISTICS_get (h, NULL, 173 (g = GNUNET_STATISTICS_get(h, NULL,
174 "test-3", 174 "test-3",
175 &next_fin, 175 &next_fin,
176 &check_3, cls))); 176 &check_3, cls)));
177} 177}
178 178
179 179
180int 180int
181main (int argc, char *argv_ign[]) 181main(int argc, char *argv_ign[])
182{ 182{
183 int ok = 1; 183 int ok = 1;
184 char *const argv[] = { "test-statistics-api", 184 char *const argv[] = { "test-statistics-api",
185 "-c", 185 "-c",
186 "test_statistics_api_data.conf", 186 "test_statistics_api_data.conf",
187 "-L", "WARNING", 187 "-L", "WARNING",
188 NULL 188 NULL };
189 };
190 struct GNUNET_GETOPT_CommandLineOption options[] = { 189 struct GNUNET_GETOPT_CommandLineOption options[] = {
191 GNUNET_GETOPT_OPTION_END 190 GNUNET_GETOPT_OPTION_END
192 }; 191 };
193 struct GNUNET_OS_Process *proc; 192 struct GNUNET_OS_Process *proc;
194 char *binary; 193 char *binary;
195 194
196 GNUNET_log_setup ("test_statistics_api", 195 GNUNET_log_setup("test_statistics_api",
197 "WARNING", 196 "WARNING",
198 NULL); 197 NULL);
199 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-statistics"); 198 binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-statistics");
200 proc = 199 proc =
201 GNUNET_OS_start_process (GNUNET_YES, 200 GNUNET_OS_start_process(GNUNET_YES,
202 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 201 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
203 NULL, NULL, NULL, 202 NULL, NULL, NULL,
204 binary, 203 binary,
205 "gnunet-service-statistics", 204 "gnunet-service-statistics",
206 "-c", "test_statistics_api_data.conf", NULL); 205 "-c", "test_statistics_api_data.conf", NULL);
207 GNUNET_assert (NULL != proc); 206 GNUNET_assert(NULL != proc);
208 GNUNET_PROGRAM_run (5, argv, 207 GNUNET_PROGRAM_run(5, argv,
209 "test-statistics-api", "nohelp", 208 "test-statistics-api", "nohelp",
210 options, &run, 209 options, &run,
211 &ok); 210 &ok);
212 if (0 != GNUNET_OS_process_kill (proc, 211 if (0 != GNUNET_OS_process_kill(proc,
213 GNUNET_TERM_SIG)) 212 GNUNET_TERM_SIG))
214 { 213 {
215 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 214 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "kill");
216 ok = 1; 215 ok = 1;
217 } 216 }
218 GNUNET_OS_process_wait (proc); 217 GNUNET_OS_process_wait(proc);
219 GNUNET_OS_process_destroy (proc); 218 GNUNET_OS_process_destroy(proc);
220 proc = NULL; 219 proc = NULL;
221 if (ok != 0) 220 if (ok != 0)
222 { 221 {
223 GNUNET_free (binary); 222 GNUNET_free(binary);
224 return ok; 223 return ok;
225 } 224 }
226 ok = 1; 225 ok = 1;
227 /* restart to check persistence! */ 226 /* restart to check persistence! */
228 proc = 227 proc =
229 GNUNET_OS_start_process (GNUNET_YES, 228 GNUNET_OS_start_process(GNUNET_YES,
230 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 229 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
231 NULL, NULL, NULL, 230 NULL, NULL, NULL,
232 binary, 231 binary,
233 "gnunet-service-statistics", 232 "gnunet-service-statistics",
234 "-c", "test_statistics_api_data.conf", 233 "-c", "test_statistics_api_data.conf",
235 NULL); 234 NULL);
236 GNUNET_PROGRAM_run (5, argv, 235 GNUNET_PROGRAM_run(5, argv,
237 "test-statistics-api", "nohelp", 236 "test-statistics-api", "nohelp",
238 options, 237 options,
239 &run_more, &ok); 238 &run_more, &ok);
240 if (0 != GNUNET_OS_process_kill (proc, 239 if (0 != GNUNET_OS_process_kill(proc,
241 GNUNET_TERM_SIG)) 240 GNUNET_TERM_SIG))
242 { 241 {
243 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 242 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "kill");
244 ok = 1; 243 ok = 1;
245 } 244 }
246 GNUNET_OS_process_wait (proc); 245 GNUNET_OS_process_wait(proc);
247 GNUNET_OS_process_destroy (proc); 246 GNUNET_OS_process_destroy(proc);
248 proc = NULL; 247 proc = NULL;
249 GNUNET_free (binary); 248 GNUNET_free(binary);
250 return ok; 249 return ok;
251} 250}
252 251