aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/test_testbed_api_controllerlink.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-08-31 10:36:28 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-08-31 10:36:28 +0000
commita94a1861d123fe850d2ab5ae74cbb59b132a15ea (patch)
treea16d2518067d13f2463e83cd9dc66bdd6b733621 /src/testbed/test_testbed_api_controllerlink.c
parentd0c55c3ee57913977b1497ea0e6f20573820b206 (diff)
downloadgnunet-a94a1861d123fe850d2ab5ae74cbb59b132a15ea.tar.gz
gnunet-a94a1861d123fe850d2ab5ae74cbb59b132a15ea.zip
adhering to indentation standard
Diffstat (limited to 'src/testbed/test_testbed_api_controllerlink.c')
-rw-r--r--src/testbed/test_testbed_api_controllerlink.c152
1 files changed, 79 insertions, 73 deletions
diff --git a/src/testbed/test_testbed_api_controllerlink.c b/src/testbed/test_testbed_api_controllerlink.c
index a5f84b6ce..b10e454de 100644
--- a/src/testbed/test_testbed_api_controllerlink.c
+++ b/src/testbed/test_testbed_api_controllerlink.c
@@ -21,7 +21,7 @@
21/** 21/**
22 * @file testbed/test_testbed_api_controllerlink.c 22 * @file testbed/test_testbed_api_controllerlink.c
23 * @brief testcase for testing controller to subcontroller linking 23 * @brief testcase for testing controller to subcontroller linking
24 * @author Sree Harsha Totakura <sreeharsha@totakura.in> 24 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
25 */ 25 */
26 26
27#include "platform.h" 27#include "platform.h"
@@ -45,78 +45,78 @@
45 * Different stages in testing 45 * Different stages in testing
46 */ 46 */
47enum Stage 47enum Stage
48 { 48{
49 49
50 /** 50 /**
51 * Initial stage 51 * Initial stage
52 */ 52 */
53 INIT, 53 INIT,
54 54
55 /** 55 /**
56 * Master controller has started 56 * Master controller has started
57 */ 57 */
58 MASTER_STARTED, 58 MASTER_STARTED,
59 59
60 /** 60 /**
61 * The first slave has been registered at master controller 61 * The first slave has been registered at master controller
62 */ 62 */
63 SLAVE1_REGISTERED, 63 SLAVE1_REGISTERED,
64 64
65 /** 65 /**
66 * The second slave has been registered at the master controller 66 * The second slave has been registered at the master controller
67 */ 67 */
68 SLAVE2_REGISTERED, 68 SLAVE2_REGISTERED,
69 69
70 /** 70 /**
71 * Link from master to slave 1 has been successfully created 71 * Link from master to slave 1 has been successfully created
72 */ 72 */
73 SLAVE1_LINK_SUCCESS, 73 SLAVE1_LINK_SUCCESS,
74 74
75 /** 75 /**
76 * Link from slave 1 to slave 2 has been successfully created. 76 * Link from slave 1 to slave 2 has been successfully created.
77 */ 77 */
78 SLAVE2_LINK_SUCCESS, 78 SLAVE2_LINK_SUCCESS,
79 79
80 /** 80 /**
81 * Peer create on slave 1 successful 81 * Peer create on slave 1 successful
82 */ 82 */
83 SLAVE1_PEER_CREATE_SUCCESS, 83 SLAVE1_PEER_CREATE_SUCCESS,
84 84
85 /** 85 /**
86 * Peer create on slave 2 successful 86 * Peer create on slave 2 successful
87 */ 87 */
88 SLAVE2_PEER_CREATE_SUCCESS, 88 SLAVE2_PEER_CREATE_SUCCESS,
89 89
90 /** 90 /**
91 * Peer startup on slave 1 successful 91 * Peer startup on slave 1 successful
92 */ 92 */
93 SLAVE1_PEER_START_SUCCESS, 93 SLAVE1_PEER_START_SUCCESS,
94 94
95 /** 95 /**
96 * Peer on slave 1 successfully stopped 96 * Peer on slave 1 successfully stopped
97 */ 97 */
98 SLAVE1_PEER_STOP_SUCCESS, 98 SLAVE1_PEER_STOP_SUCCESS,
99 99
100 /** 100 /**
101 * Peer startup on slave 2 successful 101 * Peer startup on slave 2 successful
102 */ 102 */
103 SLAVE2_PEER_START_SUCCESS, 103 SLAVE2_PEER_START_SUCCESS,
104 104
105 /** 105 /**
106 * Peer on slave 2 successfully stopped 106 * Peer on slave 2 successfully stopped
107 */ 107 */
108 SLAVE2_PEER_STOP_SUCCESS, 108 SLAVE2_PEER_STOP_SUCCESS,
109 109
110 /** 110 /**
111 * Peer destroy on slave 1 successful 111 * Peer destroy on slave 1 successful
112 */ 112 */
113 SLAVE1_PEER_DESTROY_SUCCESS, 113 SLAVE1_PEER_DESTROY_SUCCESS,
114 114
115 /** 115 /**
116 * Peer destory on slave 2 successful; Marks test as successful 116 * Peer destory on slave 2 successful; Marks test as successful
117 */ 117 */
118 SUCCESS 118 SUCCESS
119 }; 119};
120 120
121/** 121/**
122 * Host for running master controller 122 * Host for running master controller
@@ -197,7 +197,7 @@ do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
197 GNUNET_SCHEDULER_cancel (abort_task); 197 GNUNET_SCHEDULER_cancel (abort_task);
198 if (NULL != slave2) 198 if (NULL != slave2)
199 GNUNET_TESTBED_host_destroy (slave2); 199 GNUNET_TESTBED_host_destroy (slave2);
200 if (NULL != slave) 200 if (NULL != slave)
201 GNUNET_TESTBED_host_destroy (slave); 201 GNUNET_TESTBED_host_destroy (slave);
202 if (NULL != host) 202 if (NULL != host)
203 GNUNET_TESTBED_host_destroy (host); 203 GNUNET_TESTBED_host_destroy (host);
@@ -209,7 +209,7 @@ do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
209 GNUNET_TESTBED_controller_stop (cp); 209 GNUNET_TESTBED_controller_stop (cp);
210 if (NULL != rh) 210 if (NULL != rh)
211 GNUNET_TESTBED_cancel_registration (rh); 211 GNUNET_TESTBED_cancel_registration (rh);
212 212
213} 213}
214 214
215 215
@@ -231,8 +231,8 @@ do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
231/** 231/**
232 * Task for inserting delay between tests 232 * Task for inserting delay between tests
233 * 233 *
234 * @param 234 * @param
235 * @return 235 * @return
236 */ 236 */
237static void 237static void
238delay_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 238delay_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
@@ -241,15 +241,15 @@ delay_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
241 { 241 {
242 case SLAVE1_PEER_START_SUCCESS: 242 case SLAVE1_PEER_START_SUCCESS:
243 op = GNUNET_TESTBED_peer_stop (slave1_peer); 243 op = GNUNET_TESTBED_peer_stop (slave1_peer);
244 GNUNET_assert (NULL != op); 244 GNUNET_assert (NULL != op);
245 break; 245 break;
246 case SLAVE2_PEER_START_SUCCESS: 246 case SLAVE2_PEER_START_SUCCESS:
247 op = GNUNET_TESTBED_peer_stop (slave2_peer); 247 op = GNUNET_TESTBED_peer_stop (slave2_peer);
248 GNUNET_assert (NULL != op); 248 GNUNET_assert (NULL != op);
249 break; 249 break;
250 default: 250 default:
251 GNUNET_assert (0); 251 GNUNET_assert (0);
252 } 252 }
253} 253}
254 254
255 255
@@ -262,7 +262,7 @@ delay_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
262 * creation 262 * creation
263 * @param emsg NULL if peer is not NULL; else MAY contain the error description 263 * @param emsg NULL if peer is not NULL; else MAY contain the error description
264 */ 264 */
265static void 265static void
266peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) 266peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
267{ 267{
268 switch (result) 268 switch (result)
@@ -270,9 +270,9 @@ peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
270 case SLAVE2_LINK_SUCCESS: 270 case SLAVE2_LINK_SUCCESS:
271 GNUNET_assert (NULL != peer); 271 GNUNET_assert (NULL != peer);
272 GNUNET_assert (NULL == emsg); 272 GNUNET_assert (NULL == emsg);
273 result = SLAVE1_PEER_CREATE_SUCCESS; 273 result = SLAVE1_PEER_CREATE_SUCCESS;
274 slave1_peer = peer; 274 slave1_peer = peer;
275 GNUNET_TESTBED_operation_done (op); 275 GNUNET_TESTBED_operation_done (op);
276 op = GNUNET_TESTBED_peer_create (mc, slave2, cfg, peer_create_cb, NULL); 276 op = GNUNET_TESTBED_peer_create (mc, slave2, cfg, peer_create_cb, NULL);
277 GNUNET_assert (NULL != op); 277 GNUNET_assert (NULL != op);
278 break; 278 break;
@@ -280,13 +280,13 @@ peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
280 GNUNET_assert (NULL != peer); 280 GNUNET_assert (NULL != peer);
281 GNUNET_assert (NULL == emsg); 281 GNUNET_assert (NULL == emsg);
282 result = SLAVE2_PEER_CREATE_SUCCESS; 282 result = SLAVE2_PEER_CREATE_SUCCESS;
283 slave2_peer = peer; 283 slave2_peer = peer;
284 GNUNET_TESTBED_operation_done (op); 284 GNUNET_TESTBED_operation_done (op);
285 op = GNUNET_TESTBED_peer_start (slave1_peer); 285 op = GNUNET_TESTBED_peer_start (slave1_peer);
286 GNUNET_assert (NULL != op); 286 GNUNET_assert (NULL != op);
287 break; 287 break;
288 default: 288 default:
289 GNUNET_assert (0); 289 GNUNET_assert (0);
290 } 290 }
291} 291}
292 292
@@ -318,13 +318,13 @@ check_operation_success (const struct GNUNET_TESTBED_EventInformation *event)
318 * @param cls closure 318 * @param cls closure
319 * @param event information about the event 319 * @param event information about the event
320 */ 320 */
321static void 321static void
322controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event) 322controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
323{ 323{
324 switch (result) 324 switch (result)
325 { 325 {
326 case SLAVE2_REGISTERED: 326 case SLAVE2_REGISTERED:
327 check_operation_success (event); 327 check_operation_success (event);
328 GNUNET_TESTBED_operation_done (op); 328 GNUNET_TESTBED_operation_done (op);
329 op = NULL; 329 op = NULL;
330 result = SLAVE1_LINK_SUCCESS; 330 result = SLAVE1_LINK_SUCCESS;
@@ -347,9 +347,9 @@ controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event)
347 GNUNET_assert (event->details.peer_start.peer == slave1_peer); 347 GNUNET_assert (event->details.peer_start.peer == slave1_peer);
348 GNUNET_TESTBED_operation_done (op); 348 GNUNET_TESTBED_operation_done (op);
349 result = SLAVE1_PEER_START_SUCCESS; 349 result = SLAVE1_PEER_START_SUCCESS;
350 GNUNET_SCHEDULER_add_delayed 350 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
351 (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1), 351 (GNUNET_TIME_UNIT_SECONDS, 1), &delay_task,
352 &delay_task, NULL); 352 NULL);
353 break; 353 break;
354 case SLAVE1_PEER_START_SUCCESS: 354 case SLAVE1_PEER_START_SUCCESS:
355 GNUNET_assert (GNUNET_TESTBED_ET_PEER_STOP == event->type); 355 GNUNET_assert (GNUNET_TESTBED_ET_PEER_STOP == event->type);
@@ -357,7 +357,7 @@ controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event)
357 GNUNET_TESTBED_operation_done (op); 357 GNUNET_TESTBED_operation_done (op);
358 result = SLAVE1_PEER_STOP_SUCCESS; 358 result = SLAVE1_PEER_STOP_SUCCESS;
359 op = GNUNET_TESTBED_peer_start (slave2_peer); 359 op = GNUNET_TESTBED_peer_start (slave2_peer);
360 GNUNET_assert (NULL != op); 360 GNUNET_assert (NULL != op);
361 break; 361 break;
362 case SLAVE1_PEER_STOP_SUCCESS: 362 case SLAVE1_PEER_STOP_SUCCESS:
363 GNUNET_assert (GNUNET_TESTBED_ET_PEER_START == event->type); 363 GNUNET_assert (GNUNET_TESTBED_ET_PEER_START == event->type);
@@ -365,9 +365,9 @@ controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event)
365 GNUNET_assert (event->details.peer_start.peer == slave2_peer); 365 GNUNET_assert (event->details.peer_start.peer == slave2_peer);
366 GNUNET_TESTBED_operation_done (op); 366 GNUNET_TESTBED_operation_done (op);
367 result = SLAVE2_PEER_START_SUCCESS; 367 result = SLAVE2_PEER_START_SUCCESS;
368 GNUNET_SCHEDULER_add_delayed 368 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
369 (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1), 369 (GNUNET_TIME_UNIT_SECONDS, 1), &delay_task,
370 &delay_task, NULL); 370 NULL);
371 break; 371 break;
372 case SLAVE2_PEER_START_SUCCESS: 372 case SLAVE2_PEER_START_SUCCESS:
373 GNUNET_assert (GNUNET_TESTBED_ET_PEER_STOP == event->type); 373 GNUNET_assert (GNUNET_TESTBED_ET_PEER_STOP == event->type);
@@ -389,7 +389,7 @@ controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event)
389 GNUNET_TESTBED_operation_done (op); 389 GNUNET_TESTBED_operation_done (op);
390 result = SUCCESS; 390 result = SUCCESS;
391 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 391 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
392 break; 392 break;
393 default: 393 default:
394 GNUNET_assert (0); 394 GNUNET_assert (0);
395 } 395 }
@@ -402,7 +402,7 @@ controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event)
402 * @param cls the host which has been registered 402 * @param cls the host which has been registered
403 * @param emsg the error message; NULL if host registration is successful 403 * @param emsg the error message; NULL if host registration is successful
404 */ 404 */
405static void 405static void
406registration_cont (void *cls, const char *emsg) 406registration_cont (void *cls, const char *emsg)
407{ 407{
408 rh = NULL; 408 rh = NULL;
@@ -439,9 +439,9 @@ registration_cont (void *cls, const char *emsg)
439 * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not, 439 * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
440 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case 440 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
441 */ 441 */
442static void 442static void
443status_cb (void *cls, 443status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config,
444 const struct GNUNET_CONFIGURATION_Handle *config, int status) 444 int status)
445{ 445{
446 switch (result) 446 switch (result)
447 { 447 {
@@ -453,7 +453,7 @@ status_cb (void *cls,
453 event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT); 453 event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT);
454 event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED); 454 event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED);
455 mc = GNUNET_TESTBED_controller_connect (config, host, event_mask, 455 mc = GNUNET_TESTBED_controller_connect (config, host, event_mask,
456 &controller_cb, NULL); 456 &controller_cb, NULL);
457 GNUNET_assert (NULL != mc); 457 GNUNET_assert (NULL != mc);
458 result = MASTER_STARTED; 458 result = MASTER_STARTED;
459 slave = GNUNET_TESTBED_host_create_with_id (1, "127.0.0.1", NULL, 0); 459 slave = GNUNET_TESTBED_host_create_with_id (1, "127.0.0.1", NULL, 0);
@@ -468,7 +468,7 @@ status_cb (void *cls,
468 468
469 469
470/** 470/**
471 * Main run function. 471 * Main run function.
472 * 472 *
473 * @param cls NULL 473 * @param cls NULL
474 * @param args arguments passed to GNUNET_PROGRAM_run 474 * @param args arguments passed to GNUNET_PROGRAM_run
@@ -482,23 +482,26 @@ run (void *cls, char *const *args, const char *cfgfile,
482 host = GNUNET_TESTBED_host_create (NULL, NULL, 0); 482 host = GNUNET_TESTBED_host_create (NULL, NULL, 0);
483 GNUNET_assert (NULL != host); 483 GNUNET_assert (NULL != host);
484 cfg = GNUNET_CONFIGURATION_dup (config); 484 cfg = GNUNET_CONFIGURATION_dup (config);
485 cp = 485 cp = GNUNET_TESTBED_controller_start ("127.0.0.1", host, cfg, status_cb,
486 GNUNET_TESTBED_controller_start ("127.0.0.1", host, cfg, status_cb, NULL); 486 NULL);
487 abort_task = GNUNET_SCHEDULER_add_delayed 487 abort_task =
488 (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5), 488 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
489 &do_abort, NULL); 489 (GNUNET_TIME_UNIT_MINUTES, 5), &do_abort,
490 NULL);
490} 491}
491 492
492 493
493/** 494/**
494 * Main function 495 * Main function
495 */ 496 */
496int main (int argc, char **argv) 497int
498main (int argc, char **argv)
497{ 499{
498 int ret; 500 int ret;
501
499 char *const argv2[] = { "test_testbed_api_controllerlink", 502 char *const argv2[] = { "test_testbed_api_controllerlink",
500 "-c", "test_testbed_api.conf", 503 "-c", "test_testbed_api.conf",
501 NULL 504 NULL
502 }; 505 };
503 struct GNUNET_GETOPT_CommandLineOption options[] = { 506 struct GNUNET_GETOPT_CommandLineOption options[] = {
504 GNUNET_GETOPT_OPTION_END 507 GNUNET_GETOPT_OPTION_END
@@ -509,28 +512,31 @@ int main (int argc, char **argv)
509 struct GNUNET_OS_Process *auxp; 512 struct GNUNET_OS_Process *auxp;
510 enum GNUNET_OS_ProcessStatusType type; 513 enum GNUNET_OS_ProcessStatusType type;
511 unsigned long code; 514 unsigned long code;
512 515
513 auxp = GNUNET_OS_start_process_vap (GNUNET_NO, GNUNET_OS_INHERIT_STD_ALL, 516 auxp =
514 NULL, NULL, "ssh", remote_args); 517 GNUNET_OS_start_process_vap (GNUNET_NO, GNUNET_OS_INHERIT_STD_ALL, NULL,
518 NULL, "ssh", remote_args);
515 GNUNET_assert (NULL != auxp); 519 GNUNET_assert (NULL != auxp);
516 do 520 do
517 { 521 {
518 ret = GNUNET_OS_process_status (auxp, &type, &code); 522 ret = GNUNET_OS_process_status (auxp, &type, &code);
519 GNUNET_assert (GNUNET_SYSERR != ret); 523 GNUNET_assert (GNUNET_SYSERR != ret);
520 (void) usleep (300); 524 (void) usleep (300);
521 } while (GNUNET_NO == ret); 525 }
522 GNUNET_OS_process_destroy (auxp); 526 while (GNUNET_NO == ret);
527 GNUNET_OS_process_destroy (auxp);
523 if (0 != code) 528 if (0 != code)
524 { 529 {
525 (void) printf ("Unable to run the test as this system is not configured " 530 (void) printf ("Unable to run the test as this system is not configured "
526 "to use password less SSH logins to localhost.\n" 531 "to use password less SSH logins to localhost.\n"
527 "Marking test as successful\n"); 532 "Marking test as successful\n");
528 return 0; 533 return 0;
529 } 534 }
530 result = INIT; 535 result = INIT;
531 ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, 536 ret =
532 "test_testbed_api_controllerlink", "nohelp", options, &run, 537 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
533 NULL); 538 "test_testbed_api_controllerlink", "nohelp", options,
539 &run, NULL);
534 if ((GNUNET_OK != ret) || (SUCCESS != result)) 540 if ((GNUNET_OK != ret) || (SUCCESS != result))
535 return 1; 541 return 1;
536 return 0; 542 return 0;