c35c703570341e0c624a59b53d1d37b8725c2561
[oweals/gnunet.git] / src / testbed / test_testbed_api_3peers_3controllers.c
1 /*
2       This file is part of GNUnet
3       Copyright (C) 2008--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 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
16 /**
17  * @file testbed/test_testbed_api_3peers_3controllers.c
18  * @brief testcases for the testbed api: 3 peers are configured, started and
19  *          connected together. Each peer resides on its own controller.
20  * @author Sree Harsha Totakura
21  */
22
23
24 /**
25  * The testing architecture is:
26  *                  A
27  *                 / \
28  *                /   \
29  *               B === C
30  * A is the master controller and B, C are slave controllers. B links to C
31  * laterally.
32  * Peers are mapped to controllers in the following relations:
33  *             Peer         Controller
34  *               1              A
35  *               2              B
36  *               3              C
37  *
38  */
39
40 #include "platform.h"
41 #include "gnunet_util_lib.h"
42 #include "gnunet_testing_lib.h"
43 #include "gnunet_testbed_service.h"
44
45
46 /**
47  * Generic logging shortcut
48  */
49 #define LOG(kind,...)                           \
50   GNUNET_log (kind, __VA_ARGS__)
51
52 /**
53  * Relative time seconds shorthand
54  */
55 #define TIME_REL_SECS(sec) \
56   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec)
57
58
59 /**
60  * Peer context
61  */
62 struct PeerContext
63 {
64   /**
65    * The peer handle
66    */
67   struct GNUNET_TESTBED_Peer *peer;
68
69   /**
70    * Operations involving this peer
71    */
72   struct GNUNET_TESTBED_Operation *operation;
73
74   /**
75    * set to GNUNET_YES when peer is started
76    */
77   int is_running;
78 };
79
80 /**
81  * Our localhost
82  */
83 static struct GNUNET_TESTBED_Host *host;
84
85 /**
86  * The controller process of one controller
87  */
88 static struct GNUNET_TESTBED_ControllerProc *cp1;
89
90 /**
91  * A neighbouring host
92  */
93 static struct GNUNET_TESTBED_Host *neighbour1;
94
95 /**
96  * Another neighbouring host
97  */
98 static struct GNUNET_TESTBED_Host *neighbour2;
99
100 /**
101  * Handle for neighbour registration
102  */
103 static struct GNUNET_TESTBED_HostRegistrationHandle *reg_handle;
104
105 /**
106  * The controller handle of one controller
107  */
108 static struct GNUNET_TESTBED_Controller *controller1;
109
110 /**
111  * peer 1
112  */
113 static struct PeerContext peer1;
114
115 /**
116  * peer2
117  */
118 static struct PeerContext peer2;
119
120 /**
121  * peer3
122  */
123 static struct PeerContext peer3;
124
125 /**
126  * Handle to starting configuration
127  */
128 static struct GNUNET_CONFIGURATION_Handle *cfg;
129
130 /**
131  * Handle to slave controller C's configuration, used to establish lateral link from
132  * master controller
133  */
134 static struct GNUNET_CONFIGURATION_Handle *cfg2;
135
136 /**
137  * Handle to operations involving both peers
138  */
139 static struct GNUNET_TESTBED_Operation *common_operation;
140
141 /**
142  * The handle for whether a host is habitable or not
143  */
144 struct GNUNET_TESTBED_HostHabitableCheckHandle *hc_handle;
145
146 /**
147  * Abort task identifier
148  */
149 static struct GNUNET_SCHEDULER_Task * abort_task;
150
151 /**
152  * Delayed connect job identifier
153  */
154 static struct GNUNET_SCHEDULER_Task * delayed_connect_task;
155
156 /**
157  * Different stages in testing
158  */
159 enum Stage
160 {
161
162   /**
163    * Initial stage
164    */
165   INIT,
166
167   /**
168    * Controller 1 has started
169    */
170   CONTROLLER1_UP,
171
172   /**
173    * peer1 is created
174    */
175   PEER1_CREATED,
176
177   /**
178    * peer1 is started
179    */
180   PEER1_STARTED,
181
182   /**
183    * Controller 2 has started
184    */
185   CONTROLLER2_UP,
186
187   /**
188    * peer2 is created
189    */
190   PEER2_CREATED,
191
192   /**
193    * peer2 is started
194    */
195   PEER2_STARTED,
196
197   /**
198    * Controller 3 has started
199    */
200   CONTROLLER3_UP,
201
202   /**
203    * Peer3 is created
204    */
205   PEER3_CREATED,
206
207   /**
208    * Peer3 started
209    */
210   PEER3_STARTED,
211
212   /**
213    * peer1 and peer2 are connected
214    */
215   PEERS_1_2_CONNECTED,
216
217   /**
218    * peer2 and peer3 are connected
219    */
220   PEERS_2_3_CONNECTED,
221
222   /**
223    * Peers are connected once again (this should not fail as they are already connected)
224    */
225   PEERS_CONNECTED_2,
226
227   /**
228    * peers are stopped
229    */
230   PEERS_STOPPED,
231
232   /**
233    * Final success stage
234    */
235   SUCCESS,
236
237   /**
238    * Optional stage for marking test to be skipped
239    */
240   SKIP
241 };
242
243 /**
244  * The testing result
245  */
246 static enum Stage result;
247
248 /**
249  * Shutdown nicely
250  *
251  * @param cls NULL
252  */
253 static void
254 do_shutdown (void *cls)
255 {
256   if (NULL != abort_task)
257     GNUNET_SCHEDULER_cancel (abort_task);
258   if (NULL != hc_handle)
259     GNUNET_TESTBED_is_host_habitable_cancel (hc_handle);
260   GNUNET_assert (NULL == delayed_connect_task);
261   if (NULL != common_operation)
262     GNUNET_TESTBED_operation_done (common_operation);
263   if (NULL != reg_handle)
264     GNUNET_TESTBED_cancel_registration (reg_handle);
265   if (NULL != controller1)
266     GNUNET_TESTBED_controller_disconnect (controller1);
267   GNUNET_CONFIGURATION_destroy (cfg);
268   if (NULL != cfg2)
269     GNUNET_CONFIGURATION_destroy (cfg2);
270   if (NULL != cp1)
271     GNUNET_TESTBED_controller_stop (cp1);
272   if (NULL != host)
273     GNUNET_TESTBED_host_destroy (host);
274   if (NULL != neighbour1)
275     GNUNET_TESTBED_host_destroy (neighbour1);
276   if (NULL != neighbour2)
277     GNUNET_TESTBED_host_destroy (neighbour2);
278 }
279
280
281 /**
282  * abort task to run on test timed out
283  *
284  * @param cls NULL
285  */
286 static void
287 do_abort (void *cls)
288 {
289   LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
290   abort_task = NULL;
291   if (NULL != delayed_connect_task)
292   {
293     GNUNET_SCHEDULER_cancel (delayed_connect_task);
294     delayed_connect_task = NULL;
295   }
296   do_shutdown (cls);
297 }
298
299
300 static void
301 abort_test ()
302 {
303   if (NULL != abort_task)
304     GNUNET_SCHEDULER_cancel (abort_task);
305   abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
306 }
307
308
309 /**
310  * Callback to be called when an operation is completed
311  *
312  * @param cls the callback closure from functions generating an operation
313  * @param op the operation that has been finished
314  * @param emsg error message in case the operation has failed; will be NULL if
315  *          operation has executed successfully.
316  */
317 static void
318 op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg);
319
320
321 /**
322  * task for delaying a connect
323  *
324  * @param cls NULL
325  */
326 static void
327 do_delayed_connect (void *cls)
328 {
329   delayed_connect_task = NULL;
330   if (NULL != common_operation)
331   {
332     GNUNET_break (0);
333     abort_test ();
334     return;
335   }
336   common_operation =
337       GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer1.peer,
338                                       peer2.peer);
339 }
340
341
342 /**
343  * Callback to be called when an operation is completed
344  *
345  * @param cls the callback closure from functions generating an operation
346  * @param op the operation that has been finished
347  * @param emsg error message in case the operation has failed; will be NULL if
348  *          operation has executed successfully.
349  */
350 static void
351 op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
352 {
353   if (common_operation != op)
354   {
355     GNUNET_break (0);
356     abort_test ();
357     return;
358   }
359
360   switch (result)
361   {
362   case PEER3_STARTED:
363   case PEERS_2_3_CONNECTED:
364   case PEERS_1_2_CONNECTED:
365     break;
366   default:
367     GNUNET_break (0);
368     abort_test ();
369     return;
370   }
371   if ((NULL != peer1.operation) || (NULL != peer2.operation) ||
372       (NULL != peer3.operation))
373   {
374     GNUNET_break (0);
375     abort_test ();
376     return;
377   }
378 }
379
380
381 /**
382  * Functions of this signature are called when a peer has been successfully
383  * created
384  *
385  * @param cls NULL
386  * @param peer the handle for the created peer; NULL on any error during
387  *          creation
388  * @param emsg NULL if peer is not NULL; else MAY contain the error description
389  */
390 static void
391 peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
392 {
393   switch (result)
394   {
395   case CONTROLLER1_UP:
396     if ((NULL == peer1.operation) || (NULL == peer) || (NULL != peer1.peer))
397     {
398       GNUNET_break (0);
399       abort_test ();
400       return;
401     }
402     peer1.peer = peer;
403     GNUNET_TESTBED_operation_done (peer1.operation);
404     result = PEER1_CREATED;
405     peer1.operation = GNUNET_TESTBED_peer_start (NULL, peer, NULL, NULL);
406     break;
407   case CONTROLLER2_UP:
408     if ((NULL == peer2.operation) || (NULL == peer) || (NULL != peer2.peer))
409     {
410       GNUNET_break (0);
411       abort_test ();
412       return;
413     }
414     peer2.peer = peer;
415     GNUNET_TESTBED_operation_done (peer2.operation);
416     result = PEER2_CREATED;
417     peer2.operation = GNUNET_TESTBED_peer_start (NULL, peer, NULL, NULL);
418     break;
419   case CONTROLLER3_UP:
420     if ((NULL == peer3.operation) || (NULL == peer) || (NULL != peer3.peer))
421     {
422       GNUNET_break (0);
423       abort_test ();
424       return;
425     }
426     peer3.peer = peer;
427     GNUNET_TESTBED_operation_done (peer3.operation);
428     result = PEER3_CREATED;
429     peer3.operation = GNUNET_TESTBED_peer_start (NULL, peer, NULL, NULL);
430     break;
431   default:
432     GNUNET_break (0);
433     abort_test ();
434     return;
435   }
436 }
437
438
439 /**
440  * Signature of the event handler function called by the
441  * respective event controller.
442  *
443  * @param cls closure
444  * @param event information about the event
445  */
446 static void
447 controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
448 {
449   switch (event->type)
450   {
451   case GNUNET_TESTBED_ET_OPERATION_FINISHED:
452     if ((NULL != event->op_cls) ||
453         (NULL != event->details.operation_finished.emsg))
454     {
455       GNUNET_break (0);
456       abort_test ();
457       return;
458     }
459     switch (result)
460     {
461     case PEERS_STOPPED:
462       if (NULL != event->details.operation_finished.generic)
463       {
464         GNUNET_break (0);
465         abort_test ();
466         return;
467       }
468       if (event->op == peer1.operation)
469       {
470         GNUNET_TESTBED_operation_done (peer1.operation);
471         peer1.operation = NULL;
472         peer1.peer = NULL;
473       }
474       else if (event->op == peer2.operation)
475       {
476         GNUNET_TESTBED_operation_done (peer2.operation);
477         peer2.operation = NULL;
478         peer2.peer = NULL;
479       }
480       else if (event->op == peer3.operation)
481       {
482         GNUNET_TESTBED_operation_done (peer3.operation);
483         peer3.operation = NULL;
484         peer3.peer = NULL;
485       }
486       else
487       {
488         GNUNET_break (0);
489         abort_test ();
490         return;
491       }
492       if ((NULL == peer1.peer) && (NULL == peer2.peer) && (NULL == peer3.peer))
493       {
494         result = SUCCESS;
495         GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
496       }
497       break;
498     case PEER1_STARTED:
499       if ((NULL != event->details.operation_finished.generic) ||
500           (NULL == common_operation))
501       {
502         GNUNET_break (0);
503         abort_test ();
504         return;
505       }
506       GNUNET_TESTBED_operation_done (common_operation);
507       common_operation = NULL;
508       result = CONTROLLER2_UP;
509       peer2.operation =
510           GNUNET_TESTBED_peer_create (controller1, neighbour1, cfg,
511                                       &peer_create_cb, NULL);
512       if (NULL == peer2.operation)
513       {
514         GNUNET_break (0);
515         abort_test ();
516         return;
517       }
518       break;
519     case PEER2_STARTED:
520       if ((NULL != event->details.operation_finished.generic) ||
521           (NULL == common_operation))
522       {
523         GNUNET_break (0);
524         abort_test ();
525         return;
526       }
527       GNUNET_TESTBED_operation_done (common_operation);
528       common_operation = NULL;
529       result = CONTROLLER3_UP;
530       peer3.operation =
531           GNUNET_TESTBED_peer_create (controller1, neighbour2, cfg,
532                                       &peer_create_cb, NULL);
533       if (NULL == peer3.operation)
534       {
535         GNUNET_break (0);
536         abort_test ();
537         return;
538       }
539       break;
540     default:
541       GNUNET_break (0);
542       abort_test ();
543       return;
544     }
545     break;
546   case GNUNET_TESTBED_ET_PEER_START:
547     switch (result)
548     {
549     case PEER1_CREATED:
550       if (event->details.peer_start.host != host)
551       {
552         GNUNET_break (0);
553         abort_test ();
554         return;
555       }
556       peer1.is_running = GNUNET_YES;
557       GNUNET_TESTBED_operation_done (peer1.operation);
558       peer1.operation = NULL;
559       result = PEER1_STARTED;
560       common_operation =
561           GNUNET_TESTBED_controller_link (NULL, controller1, neighbour1, NULL,
562                                           GNUNET_YES);
563       break;
564     case PEER2_CREATED:
565       if (event->details.peer_start.host != neighbour1)
566       {
567         GNUNET_break (0);
568         abort_test ();
569         return;
570       }
571       peer2.is_running = GNUNET_YES;
572       GNUNET_TESTBED_operation_done (peer2.operation);
573       peer2.operation = NULL;
574       result = PEER2_STARTED;
575       if (NULL != common_operation)
576       {
577         GNUNET_break (0);
578         abort_test ();
579         return;
580       }
581       common_operation =
582           GNUNET_TESTBED_controller_link (NULL, controller1, neighbour2, NULL,
583                                           GNUNET_YES);
584       if (NULL == common_operation)
585       {
586         GNUNET_break (0);
587         abort_test ();
588         return;
589       }
590       break;
591     case PEER3_CREATED:
592       if (event->details.peer_start.host != neighbour2)
593       {
594         GNUNET_break (0);
595         abort_test ();
596         return;
597       }
598       peer3.is_running = GNUNET_YES;
599       GNUNET_TESTBED_operation_done (peer3.operation);
600       peer3.operation = NULL;
601       result = PEER3_STARTED;
602       common_operation =
603           GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer2.peer,
604                                           peer1.peer);
605       break;
606     default:
607       GNUNET_break (0);
608       abort_test ();
609       return;
610     }
611     break;
612   case GNUNET_TESTBED_ET_PEER_STOP:
613     if (PEERS_CONNECTED_2 != result)
614     {
615       GNUNET_break (0);
616       abort_test ();
617       return;
618     }
619     if (event->details.peer_stop.peer == peer1.peer)
620     {
621       peer1.is_running = GNUNET_NO;
622       GNUNET_TESTBED_operation_done (peer1.operation);
623     }
624     else if (event->details.peer_stop.peer == peer2.peer)
625     {
626       peer2.is_running = GNUNET_NO;
627       GNUNET_TESTBED_operation_done (peer2.operation);
628     }
629     else if (event->details.peer_stop.peer == peer3.peer)
630     {
631       peer3.is_running = GNUNET_NO;
632       GNUNET_TESTBED_operation_done (peer3.operation);
633     }
634     else
635     {
636       GNUNET_break (0);
637       abort_test ();
638       return;
639     }
640     if ((GNUNET_NO == peer1.is_running) && (GNUNET_NO == peer2.is_running) &&
641         (GNUNET_NO == peer3.is_running))
642     {
643       result = PEERS_STOPPED;
644       peer1.operation = GNUNET_TESTBED_peer_destroy (peer1.peer);
645       peer2.operation = GNUNET_TESTBED_peer_destroy (peer2.peer);
646       peer3.operation = GNUNET_TESTBED_peer_destroy (peer3.peer);
647     }
648     break;
649   case GNUNET_TESTBED_ET_CONNECT:
650     if ((NULL != peer1.operation) || (NULL != peer2.operation) ||
651         (NULL != peer3.operation) || (NULL == common_operation))
652     {
653       GNUNET_break (0);
654       abort_test ();
655       return;
656     }
657     switch (result)
658     {
659     case PEER3_STARTED:
660       if ((event->details.peer_connect.peer1 != peer2.peer) ||
661           (event->details.peer_connect.peer2 != peer1.peer))
662       {
663         GNUNET_break (0);
664         abort_test ();
665         return;
666       }
667       GNUNET_TESTBED_operation_done (common_operation);
668       common_operation = NULL;
669       result = PEERS_1_2_CONNECTED;
670       LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers connected\n");
671       common_operation =
672           GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer2.peer,
673                                           peer3.peer);
674       break;
675     case PEERS_1_2_CONNECTED:
676       if ((event->details.peer_connect.peer1 != peer2.peer) ||
677           (event->details.peer_connect.peer2 != peer3.peer))
678       {
679         GNUNET_break (0);
680         abort_test ();
681         return;
682       }
683       GNUNET_TESTBED_operation_done (common_operation);
684       common_operation = NULL;
685       result = PEERS_2_3_CONNECTED;
686       delayed_connect_task =
687           GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (3), &do_delayed_connect,
688                                         NULL);
689       break;
690     case PEERS_2_3_CONNECTED:
691       if ((event->details.peer_connect.peer1 != peer1.peer) ||
692           (event->details.peer_connect.peer2 != peer2.peer))
693       {
694         GNUNET_break (0);
695         abort_test ();
696         return;
697       }
698       GNUNET_TESTBED_operation_done (common_operation);
699       common_operation = NULL;
700       result = PEERS_CONNECTED_2;
701       LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers connected again\n");
702       peer1.operation = GNUNET_TESTBED_peer_stop (NULL, peer1.peer, NULL, NULL);
703       peer2.operation = GNUNET_TESTBED_peer_stop (NULL, peer2.peer, NULL, NULL);
704       peer3.operation = GNUNET_TESTBED_peer_stop (NULL, peer3.peer, NULL, NULL);
705       break;
706     default:
707       GNUNET_break (0);
708       abort_test ();
709       return;
710     }
711     break;
712   default:
713     GNUNET_break (0);
714     abort_test ();
715     return;
716   }
717 }
718
719
720 /**
721  * Callback which will be called to after a host registration succeeded or failed
722  *
723  * @param cls the host which has been registered
724  * @param emsg the error message; NULL if host registration is successful
725  */
726 static void
727 registration_comp (void *cls, const char *emsg)
728 {
729   reg_handle = NULL;
730   if (cls == neighbour1)
731   {
732     neighbour2 = GNUNET_TESTBED_host_create ("127.0.0.1", NULL, cfg, 0);
733     if (NULL == neighbour2)
734     {
735       GNUNET_break (0);
736       abort_test ();
737       return;
738     }
739     reg_handle =
740         GNUNET_TESTBED_register_host (controller1, neighbour2,
741                                       &registration_comp, neighbour2);
742     if (NULL == reg_handle)
743     {
744       GNUNET_break (0);
745       abort_test ();
746       return;
747     }
748     return;
749   }
750   if (cls != neighbour2)
751   {
752     GNUNET_break (0);
753     abort_test ();
754     return;
755   }
756   peer1.operation =
757       GNUNET_TESTBED_peer_create (controller1, host, cfg, &peer_create_cb,
758                                   &peer1);
759   if (NULL == peer1.operation)
760   {
761     GNUNET_break (0);
762     abort_test ();
763     return;
764   }
765 }
766
767
768 /**
769  * Callback to signal successfull startup of the controller process
770  *
771  * @param cls the closure from GNUNET_TESTBED_controller_start()
772  * @param cfg the configuration with which the controller has been started;
773  *          NULL if status is not GNUNET_OK
774  * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
775  *          GNUNET_TESTBED_controller_stop() shouldn't be called in this case
776  */
777 static void
778 status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config,
779            int status)
780 {
781   uint64_t event_mask;
782
783   if (GNUNET_OK != status)
784   {
785     GNUNET_break (0);
786     cp1 = NULL;
787     abort_test ();
788     return;
789   }
790   event_mask = 0;
791   event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START);
792   event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP);
793   event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT);
794   event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED);
795   switch (result)
796   {
797   case INIT:
798     controller1 =
799         GNUNET_TESTBED_controller_connect (host, event_mask,
800                                            &controller_cb, NULL);
801     if (NULL == controller1)
802     {
803       GNUNET_break (0);
804       abort_test ();
805       return;
806     }
807     result = CONTROLLER1_UP;
808     neighbour1 = GNUNET_TESTBED_host_create ("127.0.0.1", NULL, cfg, 0);
809     if (NULL == neighbour1)
810     {
811       GNUNET_break (0);
812       abort_test ();
813       return;
814     }
815     reg_handle =
816         GNUNET_TESTBED_register_host (controller1, neighbour1,
817                                       &registration_comp, neighbour1);
818     if (NULL == reg_handle)
819     {
820       GNUNET_break (0);
821       abort_test ();
822       return;
823     }
824     break;
825   default:
826     GNUNET_break (0);
827     abort_test ();
828     return;
829   }
830 }
831
832
833 /**
834  * Callbacks of this type are called by GNUNET_TESTBED_is_host_habitable to
835  * inform whether the given host is habitable or not. The Handle returned by
836  * GNUNET_TESTBED_is_host_habitable() is invalid after this callback is called
837  *
838  * @param cls NULL
839  * @param host the host whose status is being reported; will be NULL if the host
840  *          given to GNUNET_TESTBED_is_host_habitable() is NULL
841  * @param status #GNUNET_YES if it is habitable; #GNUNET_NO if not
842  */
843 static void
844 host_habitable_cb (void *cls,
845                    const struct GNUNET_TESTBED_Host *_host,
846                    int status)
847 {
848   hc_handle = NULL;
849   if (GNUNET_NO == status)
850   {
851     (void) PRINTF ("%s",
852                    "Unable to run the test as this system is not configured "
853                    "to use password less SSH logins to localhost.\n"
854                    "Skipping test\n");
855     GNUNET_SCHEDULER_cancel (abort_task);
856     abort_task = NULL;
857     GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
858     result = SKIP;
859     return;
860   }
861   cp1 =
862       GNUNET_TESTBED_controller_start ("127.0.0.1", host, status_cb, NULL);
863 }
864
865
866 /**
867  * Main run function.
868  *
869  * @param cls NULL
870  * @param args arguments passed to GNUNET_PROGRAM_run
871  * @param cfgfile the path to configuration file
872  * @param cfg the configuration file handle
873  */
874 static void
875 run (void *cls, char *const *args, const char *cfgfile,
876      const struct GNUNET_CONFIGURATION_Handle *config)
877 {
878   cfg = GNUNET_CONFIGURATION_dup (config);
879   host = GNUNET_TESTBED_host_create (NULL, NULL, cfg, 0);
880   if (NULL == host)
881   {
882     GNUNET_break (0);
883     abort_test ();
884     return;
885   }
886   if (NULL ==
887       (hc_handle =
888        GNUNET_TESTBED_is_host_habitable (host, config, &host_habitable_cb,
889                                          NULL)))
890   {
891     GNUNET_TESTBED_host_destroy (host);
892     host = NULL;
893     (void) PRINTF ("%s",
894                    "Unable to run the test as this system is not configured "
895                    "to use password less SSH logins to localhost.\n"
896                    "Skipping test\n");
897     result = SKIP;
898     return;
899   }
900   abort_task =
901       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
902                                     (GNUNET_TIME_UNIT_MINUTES, 3), &do_abort,
903                                     NULL);
904 }
905
906
907 /**
908  * Main function
909  */
910 int
911 main (int argc, char **argv)
912 {
913   char *const argv2[] = { "test_testbed_api_3peers_3controllers",
914     "-c", "test_testbed_api.conf",
915     NULL
916   };
917   struct GNUNET_GETOPT_CommandLineOption options[] = {
918     GNUNET_GETOPT_OPTION_END
919   };
920   int ret;
921
922   result = INIT;
923   ret =
924       GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
925                           "test_testbed_api_3peers_3controllers", "nohelp",
926                           options, &run, NULL);
927   if (GNUNET_OK != ret)
928     return 1;
929   switch (result)
930   {
931   case SUCCESS:
932     return 0;
933   case SKIP:
934     return 77;                  /* Mark test as skipped */
935   default:
936     return 1;
937   }
938 }
939
940 /* end of test_testbed_api_3peers_3controllers.c */