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