diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-03-28 09:32:38 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-03-28 09:32:38 +0000 |
commit | d03ca6000941d0cee31fff6469f4f1aa00b8efb3 (patch) | |
tree | 8eb9df346fb08c3059bb941a5911ba3fa1b2135b /src/arm/test_exponential_backoff.c | |
parent | 4050bda2c2f530ba392bd5473c66298602072008 (diff) | |
download | gnunet-d03ca6000941d0cee31fff6469f4f1aa00b8efb3.tar.gz gnunet-d03ca6000941d0cee31fff6469f4f1aa00b8efb3.zip |
-test cleanup
Diffstat (limited to 'src/arm/test_exponential_backoff.c')
-rw-r--r-- | src/arm/test_exponential_backoff.c | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/src/arm/test_exponential_backoff.c b/src/arm/test_exponential_backoff.c index 30d614c2f..00402b29f 100644 --- a/src/arm/test_exponential_backoff.c +++ b/src/arm/test_exponential_backoff.c | |||
@@ -23,11 +23,11 @@ | |||
23 | */ | 23 | */ |
24 | #include "platform.h" | 24 | #include "platform.h" |
25 | #include "gnunet_arm_service.h" | 25 | #include "gnunet_arm_service.h" |
26 | #include "gnunet_client_lib.h" | 26 | #include "gnunet_util_lib.h" |
27 | #include "gnunet_configuration_lib.h" | ||
28 | #include "gnunet_program_lib.h" | ||
29 | #include "gnunet_protocols.h" | 27 | #include "gnunet_protocols.h" |
30 | 28 | ||
29 | #define LOG(...) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | ||
30 | |||
31 | #define START_ARM GNUNET_YES | 31 | #define START_ARM GNUNET_YES |
32 | 32 | ||
33 | #define LOG_BACKOFF GNUNET_NO | 33 | #define LOG_BACKOFF GNUNET_NO |
@@ -165,9 +165,7 @@ write_shutdown (void *cls, size_t size, void *buf) | |||
165 | 165 | ||
166 | if (size < sizeof (struct GNUNET_MessageHeader)) | 166 | if (size < sizeof (struct GNUNET_MessageHeader)) |
167 | { | 167 | { |
168 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 168 | LOG ("Failed to send a shutdown request\n"); |
169 | _("Failed to transmit shutdown request to client.\n")); | ||
170 | FPRINTF (stderr, "%s", "Failed to send a shutdown request\n"); | ||
171 | shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_SYSERR); | 169 | shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_SYSERR); |
172 | GNUNET_CLIENT_disconnect (shutdown_ctx->sock); | 170 | GNUNET_CLIENT_disconnect (shutdown_ctx->sock); |
173 | GNUNET_free (shutdown_ctx); | 171 | GNUNET_free (shutdown_ctx); |
@@ -183,7 +181,7 @@ write_shutdown (void *cls, size_t size, void *buf) | |||
183 | msg->type = htons (GNUNET_MESSAGE_TYPE_ARM_STOP); | 181 | msg->type = htons (GNUNET_MESSAGE_TYPE_ARM_STOP); |
184 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); | 182 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); |
185 | strcpy ((char *) &msg[1], "do-nothing"); | 183 | strcpy ((char *) &msg[1], "do-nothing"); |
186 | FPRINTF (stderr, "%s", "Sent a shutdown request\n"); | 184 | LOG ("Sent a shutdown request\n"); |
187 | return sizeof (struct GNUNET_MessageHeader) + strlen ("do-nothing") + 1; | 185 | return sizeof (struct GNUNET_MessageHeader) + strlen ("do-nothing") + 1; |
188 | } | 186 | } |
189 | 187 | ||
@@ -219,23 +217,26 @@ do_nothing_service_shutdown (struct GNUNET_CLIENT_Connection *sock, | |||
219 | shutdown_ctx); | 217 | shutdown_ctx); |
220 | } | 218 | } |
221 | 219 | ||
220 | |||
222 | static void | 221 | static void |
223 | kill_task (void *cbData, const struct GNUNET_SCHEDULER_TaskContext *tc); | 222 | kill_task (void *cbData, const struct GNUNET_SCHEDULER_TaskContext *tc); |
224 | 223 | ||
224 | |||
225 | static void | 225 | static void |
226 | shutdown_cont (void *cls, int reason) | 226 | shutdown_cont (void *cls, int reason) |
227 | { | 227 | { |
228 | if (GNUNET_NO != reason) | 228 | if (GNUNET_NO != reason) |
229 | { | 229 | { |
230 | /* Re-try shutdown */ | 230 | /* Re-try shutdown */ |
231 | FPRINTF (stderr, "%s", "do-nothing didn't die, trying again\n"); | 231 | LOG ("do-nothing didn't die, trying again\n"); |
232 | GNUNET_SCHEDULER_add_now (kill_task, NULL); | 232 | GNUNET_SCHEDULER_add_now (kill_task, NULL); |
233 | return; | 233 | return; |
234 | } | 234 | } |
235 | startedWaitingAt = GNUNET_TIME_absolute_get (); | 235 | startedWaitingAt = GNUNET_TIME_absolute_get (); |
236 | FPRINTF (stderr, "%s", "do-nothing is dead, starting the countdown\n"); | 236 | LOG ("do-nothing is dead, starting the countdown\n"); |
237 | } | 237 | } |
238 | 238 | ||
239 | |||
239 | static void | 240 | static void |
240 | kill_task (void *cbData, const struct GNUNET_SCHEDULER_TaskContext *tc) | 241 | kill_task (void *cbData, const struct GNUNET_SCHEDULER_TaskContext *tc) |
241 | { | 242 | { |
@@ -244,11 +245,8 @@ kill_task (void *cbData, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
244 | if (NULL != cbData) | 245 | if (NULL != cbData) |
245 | { | 246 | { |
246 | waitedFor = GNUNET_TIME_absolute_get_duration (startedWaitingAt); | 247 | waitedFor = GNUNET_TIME_absolute_get_duration (startedWaitingAt); |
247 | FPRINTF (stderr, "Waited for: %llu ms\n", waitedFor.rel_value); | 248 | LOG ("Waited for: %s\n", |
248 | #if LOG_BACKOFF | 249 | GNUNET_STRINGS_relative_time_to_string (waitedFor, GNUNET_YES)); |
249 | FPRINTF (killLogFilePtr, "Waited for: %llu ms\n", | ||
250 | (unsigned long long) waitedFor.rel_value); | ||
251 | #endif | ||
252 | } | 250 | } |
253 | else | 251 | else |
254 | { | 252 | { |
@@ -276,6 +274,7 @@ kill_task (void *cbData, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
276 | TIMEOUT, &shutdown_cont, NULL); | 274 | TIMEOUT, &shutdown_cont, NULL); |
277 | } | 275 | } |
278 | 276 | ||
277 | |||
279 | static void | 278 | static void |
280 | trigger_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 279 | trigger_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
281 | { | 280 | { |
@@ -289,14 +288,15 @@ arm_stop_cb (void *cls, struct GNUNET_ARM_Handle *h, enum GNUNET_ARM_RequestStat | |||
289 | { | 288 | { |
290 | GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); | 289 | GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); |
291 | GNUNET_break (result == GNUNET_ARM_RESULT_STOPPING); | 290 | GNUNET_break (result == GNUNET_ARM_RESULT_STOPPING); |
292 | FPRINTF (stderr, "%s", "ARM service stopped\n"); | 291 | LOG ("ARM service stopped\n"); |
293 | GNUNET_SCHEDULER_add_now (trigger_disconnect, NULL); | 292 | GNUNET_SCHEDULER_add_now (trigger_disconnect, NULL); |
294 | } | 293 | } |
295 | 294 | ||
296 | void | 295 | |
296 | static void | ||
297 | srv_status (void *cls, struct GNUNET_ARM_MonitorHandle *mon, const char *service, enum GNUNET_ARM_ServiceStatus status) | 297 | srv_status (void *cls, struct GNUNET_ARM_MonitorHandle *mon, const char *service, enum GNUNET_ARM_ServiceStatus status) |
298 | { | 298 | { |
299 | FPRINTF (stderr, "Service %s is %u, phase %u\n", service, status, phase); | 299 | LOG ("Service %s is %u, phase %u\n", service, status, phase); |
300 | if (status == GNUNET_ARM_SERVICE_MONITORING_STARTED) | 300 | if (status == GNUNET_ARM_SERVICE_MONITORING_STARTED) |
301 | { | 301 | { |
302 | phase++; | 302 | phase++; |
@@ -309,7 +309,7 @@ srv_status (void *cls, struct GNUNET_ARM_MonitorHandle *mon, const char *service | |||
309 | GNUNET_break (status == GNUNET_ARM_SERVICE_STARTING); | 309 | GNUNET_break (status == GNUNET_ARM_SERVICE_STARTING); |
310 | GNUNET_break (0 == strcasecmp (service, "do-nothing")); | 310 | GNUNET_break (0 == strcasecmp (service, "do-nothing")); |
311 | GNUNET_break (phase == 1); | 311 | GNUNET_break (phase == 1); |
312 | FPRINTF (stderr, "%s", "do-nothing is starting\n"); | 312 | LOG ("do-nothing is starting\n"); |
313 | phase++; | 313 | phase++; |
314 | ok = 1; | 314 | ok = 1; |
315 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &kill_task, NULL); | 315 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &kill_task, NULL); |
@@ -321,7 +321,7 @@ srv_status (void *cls, struct GNUNET_ARM_MonitorHandle *mon, const char *service | |||
321 | */ | 321 | */ |
322 | if (status == GNUNET_ARM_SERVICE_STARTING) | 322 | if (status == GNUNET_ARM_SERVICE_STARTING) |
323 | { | 323 | { |
324 | FPRINTF (stderr, "%s", "do-nothing is starting\n"); | 324 | LOG ("do-nothing is starting\n"); |
325 | GNUNET_SCHEDULER_add_now (kill_task, &ok); | 325 | GNUNET_SCHEDULER_add_now (kill_task, &ok); |
326 | } | 326 | } |
327 | else if ((status == GNUNET_ARM_SERVICE_STOPPED) && (trialCount == 14)) | 327 | else if ((status == GNUNET_ARM_SERVICE_STOPPED) && (trialCount == 14)) |
@@ -332,15 +332,18 @@ srv_status (void *cls, struct GNUNET_ARM_MonitorHandle *mon, const char *service | |||
332 | } | 332 | } |
333 | } | 333 | } |
334 | 334 | ||
335 | |||
335 | static void | 336 | static void |
336 | arm_start_cb (void *cls, struct GNUNET_ARM_Handle *h, enum GNUNET_ARM_RequestStatus status, const char *servicename, enum GNUNET_ARM_Result result) | 337 | arm_start_cb (void *cls, struct GNUNET_ARM_Handle *h, enum GNUNET_ARM_RequestStatus status, const char *servicename, enum GNUNET_ARM_Result result) |
337 | { | 338 | { |
338 | GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); | 339 | GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); |
339 | GNUNET_break (result == GNUNET_ARM_RESULT_STARTING); | 340 | GNUNET_break (result == GNUNET_ARM_RESULT_STARTING); |
340 | GNUNET_break (phase == 0); | 341 | GNUNET_break (phase == 0); |
341 | FPRINTF (stderr, "Sent 'START' request for arm to ARM %s\n", (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); | 342 | LOG ("Sent 'START' request for arm to ARM %s\n", |
343 | (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); | ||
342 | } | 344 | } |
343 | 345 | ||
346 | |||
344 | static void | 347 | static void |
345 | task (void *cls, char *const *args, const char *cfgfile, | 348 | task (void *cls, char *const *args, const char *cfgfile, |
346 | const struct GNUNET_CONFIGURATION_Handle *c) | 349 | const struct GNUNET_CONFIGURATION_Handle *c) |
@@ -381,6 +384,7 @@ task (void *cls, char *const *args, const char *cfgfile, | |||
381 | } | 384 | } |
382 | } | 385 | } |
383 | 386 | ||
387 | |||
384 | static int | 388 | static int |
385 | check () | 389 | check () |
386 | { | 390 | { |
@@ -403,6 +407,7 @@ check () | |||
403 | return ok; | 407 | return ok; |
404 | } | 408 | } |
405 | 409 | ||
410 | |||
406 | static int | 411 | static int |
407 | init () | 412 | init () |
408 | { | 413 | { |