aboutsummaryrefslogtreecommitdiff
path: root/src/arm/test_exponential_backoff.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-09-16 19:47:40 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-09-16 19:47:40 +0000
commit74f512e8e6a235cae77ba1a1049f08cac38192ce (patch)
tree6d3679202f0a078c5c5d1b3ac1be80fd33691dc1 /src/arm/test_exponential_backoff.c
parent5a1cfab1ad8ca25be6e74f981da36a9afa0f6f60 (diff)
downloadgnunet-74f512e8e6a235cae77ba1a1049f08cac38192ce.tar.gz
gnunet-74f512e8e6a235cae77ba1a1049f08cac38192ce.zip
- do not install mockup-service into libexecdir
Diffstat (limited to 'src/arm/test_exponential_backoff.c')
-rw-r--r--src/arm/test_exponential_backoff.c48
1 files changed, 38 insertions, 10 deletions
diff --git a/src/arm/test_exponential_backoff.c b/src/arm/test_exponential_backoff.c
index e218e1aae..6dc9adf77 100644
--- a/src/arm/test_exponential_backoff.c
+++ b/src/arm/test_exponential_backoff.c
@@ -38,6 +38,12 @@
38 38
39#define FIVE_MILLISECONDS GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 5) 39#define FIVE_MILLISECONDS GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 5)
40 40
41#define SERVICE "do-nothing"
42
43#define BINARY "mockup-service"
44
45#define CFGFILENAME "test_arm_api_data.conf"
46
41 47
42static const struct GNUNET_CONFIGURATION_Handle *cfg; 48static const struct GNUNET_CONFIGURATION_Handle *cfg;
43 49
@@ -182,9 +188,9 @@ write_shutdown (void *cls, size_t size, void *buf)
182 msg = (struct GNUNET_MessageHeader *) buf; 188 msg = (struct GNUNET_MessageHeader *) buf;
183 msg->type = htons (GNUNET_MESSAGE_TYPE_ARM_STOP); 189 msg->type = htons (GNUNET_MESSAGE_TYPE_ARM_STOP);
184 msg->size = htons (sizeof (struct GNUNET_MessageHeader)); 190 msg->size = htons (sizeof (struct GNUNET_MessageHeader));
185 strcpy ((char *) &msg[1], "do-nothing"); 191 strcpy ((char *) &msg[1], SERVICE);
186 LOG ("Sent a shutdown request\n"); 192 LOG ("Sent a shutdown request\n");
187 return sizeof (struct GNUNET_MessageHeader) + strlen ("do-nothing") + 1; 193 return sizeof (struct GNUNET_MessageHeader) + strlen (SERVICE) + 1;
188} 194}
189 195
190 196
@@ -214,7 +220,7 @@ do_nothing_service_shutdown (struct GNUNET_CLIENT_Connection *sock,
214 shutdown_ctx->sock = sock; 220 shutdown_ctx->sock = sock;
215 shutdown_ctx->timeout = GNUNET_TIME_relative_to_absolute (timeout); 221 shutdown_ctx->timeout = GNUNET_TIME_relative_to_absolute (timeout);
216 GNUNET_CLIENT_notify_transmit_ready (sock, 222 GNUNET_CLIENT_notify_transmit_ready (sock,
217 sizeof (struct GNUNET_MessageHeader) + strlen ("do-nothing") + 1, 223 sizeof (struct GNUNET_MessageHeader) + strlen (SERVICE) + 1,
218 timeout, GNUNET_NO, &write_shutdown, 224 timeout, GNUNET_NO, &write_shutdown,
219 shutdown_ctx); 225 shutdown_ctx);
220} 226}
@@ -255,14 +261,14 @@ kill_task (void *cbData, const struct GNUNET_SCHEDULER_TaskContext *tc)
255 waitedFor.rel_value_us = 0; 261 waitedFor.rel_value_us = 0;
256 } 262 }
257 /* Connect to the doNothing task */ 263 /* Connect to the doNothing task */
258 doNothingConnection = GNUNET_CLIENT_connect ("do-nothing", cfg); 264 doNothingConnection = GNUNET_CLIENT_connect (SERVICE, cfg);
259 GNUNET_assert (doNothingConnection != NULL); 265 GNUNET_assert (doNothingConnection != NULL);
260 if (trialCount == 12) 266 if (trialCount == 12)
261 waitedFor_prev = waitedFor; 267 waitedFor_prev = waitedFor;
262 else if (trialCount == 13) 268 else if (trialCount == 13)
263 { 269 {
264 GNUNET_CLIENT_disconnect (doNothingConnection); 270 GNUNET_CLIENT_disconnect (doNothingConnection);
265 GNUNET_ARM_request_service_stop (arm, "do-nothing", TIMEOUT, NULL, NULL); 271 GNUNET_ARM_request_service_stop (arm, SERVICE, TIMEOUT, NULL, NULL);
266 if (waitedFor_prev.rel_value_us >= waitedFor.rel_value_us) 272 if (waitedFor_prev.rel_value_us >= waitedFor.rel_value_us)
267 ok = 9; 273 ok = 9;
268 else 274 else
@@ -302,21 +308,21 @@ srv_status (void *cls, const char *service, enum GNUNET_ARM_ServiceStatus status
302 if (status == GNUNET_ARM_SERVICE_MONITORING_STARTED) 308 if (status == GNUNET_ARM_SERVICE_MONITORING_STARTED)
303 { 309 {
304 phase++; 310 phase++;
305 GNUNET_ARM_request_service_start (arm, "do-nothing", 311 GNUNET_ARM_request_service_start (arm, SERVICE,
306 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, TIMEOUT, NULL, NULL); 312 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, TIMEOUT, NULL, NULL);
307 return; 313 return;
308 } 314 }
309 if (phase == 1) 315 if (phase == 1)
310 { 316 {
311 GNUNET_break (status == GNUNET_ARM_SERVICE_STARTING); 317 GNUNET_break (status == GNUNET_ARM_SERVICE_STARTING);
312 GNUNET_break (0 == strcasecmp (service, "do-nothing")); 318 GNUNET_break (0 == strcasecmp (service, SERVICE));
313 GNUNET_break (phase == 1); 319 GNUNET_break (phase == 1);
314 LOG ("do-nothing is starting\n"); 320 LOG ("do-nothing is starting\n");
315 phase++; 321 phase++;
316 ok = 1; 322 ok = 1;
317 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &kill_task, NULL); 323 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &kill_task, NULL);
318 } 324 }
319 else if ((phase == 2) && (strcasecmp ("do-nothing", service) == 0)) 325 else if ((phase == 2) && (strcasecmp (SERVICE, service) == 0))
320 { 326 {
321 /* We passively monitor ARM for status updates. ARM should tell us 327 /* We passively monitor ARM for status updates. ARM should tell us
322 * when do-nothing dies (no need to run a service upness test ourselves). 328 * when do-nothing dies (no need to run a service upness test ourselves).
@@ -392,7 +398,7 @@ check ()
392{ 398{
393 char *const argv[] = { 399 char *const argv[] = {
394 "test-exponential-backoff", 400 "test-exponential-backoff",
395 "-c", "test_arm_api_data.conf", 401 "-c", CFGFILENAME,
396 NULL 402 NULL
397 }; 403 };
398 struct GNUNET_GETOPT_CommandLineOption options[] = { 404 struct GNUNET_GETOPT_CommandLineOption options[] = {
@@ -413,6 +419,26 @@ check ()
413static int 419static int
414init () 420init ()
415{ 421{
422 struct GNUNET_CONFIGURATION_Handle *cfg;
423 char pwd[PATH_MAX];
424 char *binary;
425
426 cfg = GNUNET_CONFIGURATION_create ();
427 if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg,
428 "test_arm_api_data.conf.in"))
429 return GNUNET_SYSERR;
430 if (NULL == getcwd (pwd, PATH_MAX))
431 return GNUNET_SYSERR;
432 GNUNET_assert (0 < GNUNET_asprintf (&binary, "%s/%s", pwd, BINARY));
433 GNUNET_CONFIGURATION_set_value_string (cfg, SERVICE, "BINARY", binary);
434 GNUNET_free (binary);
435 if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, CFGFILENAME))
436 {
437 GNUNET_CONFIGURATION_destroy (cfg);
438 return GNUNET_SYSERR;
439 }
440 GNUNET_CONFIGURATION_destroy (cfg);
441
416#if LOG_BACKOFF 442#if LOG_BACKOFF
417 killLogFileName = GNUNET_DISK_mktemp ("exponential-backoff-waiting.log"); 443 killLogFileName = GNUNET_DISK_mktemp ("exponential-backoff-waiting.log");
418 if (NULL == (killLogFilePtr = FOPEN (killLogFileName, "w"))) 444 if (NULL == (killLogFilePtr = FOPEN (killLogFileName, "w")))
@@ -434,6 +460,7 @@ houseKeep ()
434 GNUNET_assert (0 == fclose (killLogFilePtr)); 460 GNUNET_assert (0 == fclose (killLogFilePtr));
435 GNUNET_free (killLogFileName); 461 GNUNET_free (killLogFileName);
436#endif 462#endif
463 (void) unlink (CFGFILENAME);
437} 464}
438 465
439 466
@@ -446,7 +473,8 @@ main (int argc, char *argv[])
446 "WARNING", 473 "WARNING",
447 NULL); 474 NULL);
448 475
449 init (); 476 if (GNUNET_OK != init ())
477 return 1;
450 ret = check (); 478 ret = check ();
451 houseKeep (); 479 houseKeep ();
452 return ret; 480 return ret;