- test config fixes for adaptive overlay connects
[oweals/gnunet.git] / src / testbed / test_testbed_api_3peers_3controllers.c
1 /*
2       This file is part of GNUnet
3       (C) 2008--2012 Christian Grothoff (and other contributing authors)
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., 59 Temple Place - Suite 330,
18       Boston, MA 02111-1307, 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-new.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  * Abort task identifier
148  */
149 static GNUNET_SCHEDULER_TaskIdentifier abort_task;
150
151 /**
152  * Delayed connect job identifier
153  */
154 static GNUNET_SCHEDULER_TaskIdentifier 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 /**
239  * The testing result
240  */
241 static enum Stage result;
242
243 /**
244  * Shutdown nicely
245  *
246  * @param cls NULL
247  * @param tc the task context
248  */
249 static void
250 do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
251 {
252   if (GNUNET_SCHEDULER_NO_TASK != abort_task)
253     GNUNET_SCHEDULER_cancel (abort_task);
254   GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == delayed_connect_task);
255   if (NULL != reg_handle)
256     GNUNET_TESTBED_cancel_registration (reg_handle);
257   if (NULL != controller1)
258     GNUNET_TESTBED_controller_disconnect (controller1);
259   GNUNET_CONFIGURATION_destroy (cfg);
260   if (NULL != cfg2)
261     GNUNET_CONFIGURATION_destroy (cfg2);
262   if (NULL != cp1)
263     GNUNET_TESTBED_controller_stop (cp1);
264   if (NULL != host)
265     GNUNET_TESTBED_host_destroy (host);
266   if (NULL != neighbour1)
267     GNUNET_TESTBED_host_destroy (neighbour1);
268   if (NULL != neighbour2)
269     GNUNET_TESTBED_host_destroy (neighbour2);
270 }
271
272
273 /**
274  * abort task to run on test timed out
275  *
276  * @param cls NULL
277  * @param tc the task context
278  */
279 static void
280 do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
281 {
282   LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
283   abort_task = GNUNET_SCHEDULER_NO_TASK;
284   if (GNUNET_SCHEDULER_NO_TASK != delayed_connect_task)
285   {
286     GNUNET_SCHEDULER_cancel (delayed_connect_task);
287     delayed_connect_task = GNUNET_SCHEDULER_NO_TASK;
288   }
289   do_shutdown (cls, tc);
290 }
291
292 static void
293 abort_test ()
294 {
295   if (GNUNET_SCHEDULER_NO_TASK != abort_task)
296     GNUNET_SCHEDULER_cancel (abort_task);
297   abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
298 }
299
300
301 /**
302  * Callback to be called when an operation is completed
303  *
304  * @param cls the callback closure from functions generating an operation
305  * @param op the operation that has been finished
306  * @param emsg error message in case the operation has failed; will be NULL if
307  *          operation has executed successfully.
308  */
309 static void 
310 op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg);
311
312
313 /**
314  * task for delaying a connect
315  *
316  * @param cls NULL
317  * @param tc the task context
318  */
319 static void
320 do_delayed_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
321 {
322   delayed_connect_task = GNUNET_SCHEDULER_NO_TASK;
323   if (NULL != common_operation)
324   {
325     GNUNET_break (0);
326     abort_test();
327     return;
328   }
329   common_operation = GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, 
330                                                      peer1.peer, peer2.peer);
331 }
332
333
334 /**
335  * Callback to be called when an operation is completed
336  *
337  * @param cls the callback closure from functions generating an operation
338  * @param op the operation that has been finished
339  * @param emsg error message in case the operation has failed; will be NULL if
340  *          operation has executed successfully.
341  */
342 static void 
343 op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
344 {
345   if (common_operation != op)
346   {
347     GNUNET_break (0);
348     abort_test();
349     return;
350   }
351   switch(result)
352   {
353   case PEER3_STARTED:
354     if ((NULL != peer1.operation) ||
355         (NULL != peer2.operation) ||
356         (NULL == common_operation))
357     {
358       GNUNET_break (0);
359       abort_test();
360       return;
361     }
362     GNUNET_TESTBED_operation_done (common_operation);
363     common_operation = NULL;
364     result = PEERS_1_2_CONNECTED;
365     LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers connected\n");
366     common_operation = 
367         GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer2.peer,
368                                           peer3.peer);
369     break;
370   case PEERS_1_2_CONNECTED:
371     if (NULL == common_operation)
372     {
373       GNUNET_break (0);
374       abort_test();
375       return;
376     }
377     GNUNET_TESTBED_operation_done (common_operation);
378     common_operation = NULL;
379     result = PEERS_2_3_CONNECTED;
380     delayed_connect_task =
381           GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (3),
382                                         &do_delayed_connect, NULL);
383     break;
384   case PEERS_2_3_CONNECTED:
385     if ((NULL != peer1.operation) ||
386         (NULL != peer2.operation) ||
387         (NULL == common_operation))
388     {
389       GNUNET_break (0);
390       abort_test();
391       return;
392     }
393     GNUNET_TESTBED_operation_done (common_operation);
394     common_operation = NULL;
395     result = PEERS_CONNECTED_2;
396     LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers connected again\n");
397     peer1.operation = GNUNET_TESTBED_peer_stop (peer1.peer, NULL, NULL);
398     peer2.operation = GNUNET_TESTBED_peer_stop (peer2.peer, NULL, NULL);
399     peer3.operation = GNUNET_TESTBED_peer_stop (peer3.peer, NULL, NULL);
400     break;
401   default:
402     GNUNET_break (0);
403     abort_test();
404     return;
405   }
406 }
407
408
409 /**
410  * Functions of this signature are called when a peer has been successfully
411  * created
412  *
413  * @param cls NULL
414  * @param peer the handle for the created peer; NULL on any error during
415  *          creation
416  * @param emsg NULL if peer is not NULL; else MAY contain the error description
417  */
418 static void
419 peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
420 {
421   switch (result)
422   {
423   case CONTROLLER1_UP:
424     if ((NULL == peer1.operation) ||
425         (NULL == peer) ||
426         (NULL != peer1.peer))
427     {
428       GNUNET_break (0);
429       abort_test();
430       return;
431     }
432     peer1.peer = peer;
433     GNUNET_TESTBED_operation_done (peer1.operation);
434     result = PEER1_CREATED;
435     peer1.operation = GNUNET_TESTBED_peer_start (NULL, peer, NULL, NULL);
436     break;
437   case CONTROLLER2_UP:
438     if ((NULL == peer2.operation) ||
439         (NULL == peer) ||
440         (NULL != peer2.peer))
441     {
442       GNUNET_break (0);
443       abort_test();
444       return;
445     }
446     peer2.peer = peer;
447     GNUNET_TESTBED_operation_done (peer2.operation);
448     result = PEER2_CREATED;
449     peer2.operation = GNUNET_TESTBED_peer_start (NULL, peer, NULL, NULL);
450     break;
451   case CONTROLLER3_UP:
452     if ((NULL == peer3.operation) ||
453         (NULL == peer) ||
454         (NULL != peer3.peer))
455     {
456       GNUNET_break (0);
457       abort_test();
458       return;
459     }
460     peer3.peer = peer;
461     GNUNET_TESTBED_operation_done (peer3.operation);
462     result = PEER3_CREATED;
463     peer3.operation = GNUNET_TESTBED_peer_start (NULL, peer, NULL, NULL);
464     break;
465   default:
466     GNUNET_break (0);
467     abort_test();
468     return;
469   }  
470 }
471
472
473 /**
474  * Signature of the event handler function called by the
475  * respective event controller.
476  *
477  * @param cls closure
478  * @param event information about the event
479  */
480 static void
481 controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
482 {
483   switch (event->type)
484   {
485   case GNUNET_TESTBED_ET_OPERATION_FINISHED:
486     if ((NULL != event->details.operation_finished.op_cls)
487         || (NULL != event->details.operation_finished.emsg))
488     {
489       GNUNET_break (0);
490       abort_test();
491       return;
492     }
493     switch (result)
494     {      
495     case PEERS_STOPPED:
496       if (NULL != event->details.operation_finished.generic)
497       {
498         GNUNET_break (0);
499         abort_test();
500         return;
501       }
502       if (event->details.operation_finished.operation == peer1.operation)
503       {
504         GNUNET_TESTBED_operation_done (peer1.operation);
505         peer1.operation = NULL;
506         peer1.peer = NULL;
507       }
508       else if (event->details.operation_finished.operation == peer2.operation)
509       {
510         GNUNET_TESTBED_operation_done (peer2.operation);
511         peer2.operation = NULL;
512         peer2.peer = NULL;
513       }
514       else if (event->details.operation_finished.operation == peer3.operation)
515       {
516         GNUNET_TESTBED_operation_done (peer3.operation);
517         peer3.operation = NULL;
518         peer3.peer = NULL;
519       }
520       else
521       {
522         GNUNET_break (0);
523         abort_test();
524         return;
525       }
526       if ((NULL == peer1.peer) && (NULL == peer2.peer) && (NULL == peer3.peer))
527       {
528         result = SUCCESS;
529         GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
530       }
531       break;
532     case PEER1_STARTED:
533       if ((NULL != event->details.operation_finished.generic) ||
534           (NULL == common_operation))
535       {
536         GNUNET_break (0);
537         abort_test();
538         return;
539       }
540       GNUNET_TESTBED_operation_done (common_operation);
541       common_operation = NULL;
542       result = CONTROLLER2_UP;
543       peer2.operation =
544           GNUNET_TESTBED_peer_create (controller1, neighbour1, cfg,
545                                       &peer_create_cb, NULL);
546       if (NULL == peer2.operation)
547       {
548         GNUNET_break (0);
549         abort_test();
550         return;
551       }
552       break;
553     case PEER2_STARTED:
554       if ((NULL != event->details.operation_finished.generic) ||
555           (NULL == common_operation))
556       {
557         GNUNET_break (0);
558         abort_test();
559         return;
560       }
561       GNUNET_TESTBED_operation_done (common_operation);
562       common_operation = NULL;
563       result = CONTROLLER3_UP;
564       peer3.operation =
565           GNUNET_TESTBED_peer_create (controller1, neighbour2, cfg,
566                                       &peer_create_cb, NULL);
567       if (NULL == peer3.operation)
568       {
569         GNUNET_break (0);
570         abort_test();
571         return;
572       }
573       break;
574     default:
575       GNUNET_break (0);
576       abort_test();
577       return;
578     }
579     break;
580   case GNUNET_TESTBED_ET_PEER_START:    
581     switch (result)
582     {
583     case PEER1_CREATED:
584       if (event->details.peer_start.host != host)
585       {
586         GNUNET_break (0);
587         abort_test();
588         return;
589       }
590       peer1.is_running = GNUNET_YES;
591       GNUNET_TESTBED_operation_done (peer1.operation);
592       peer1.operation = NULL;
593       result = PEER1_STARTED;
594       common_operation =
595           GNUNET_TESTBED_controller_link (NULL, controller1, neighbour1, NULL, cfg,
596                                           GNUNET_YES); 
597       break;
598     case PEER2_CREATED:
599       if (event->details.peer_start.host != neighbour1)
600       {
601         GNUNET_break (0);
602         abort_test();
603         return;
604       }
605       peer2.is_running = GNUNET_YES;
606       GNUNET_TESTBED_operation_done (peer2.operation);
607       peer2.operation = NULL;
608       result = PEER2_STARTED;
609       if (NULL != common_operation)
610       {
611         GNUNET_break (0);
612         abort_test();
613         return;
614       }
615       common_operation =
616           GNUNET_TESTBED_controller_link (NULL, controller1, neighbour2, NULL, cfg,
617                                           GNUNET_YES);
618       if (NULL == common_operation)
619       {
620         GNUNET_break (0);
621         abort_test();
622         return;
623       }
624       break;
625     case PEER3_CREATED:
626       if (event->details.peer_start.host != neighbour2)
627       {
628         GNUNET_break (0);
629         abort_test();
630         return;
631       }
632       peer3.is_running = GNUNET_YES;
633       GNUNET_TESTBED_operation_done (peer3.operation);
634       peer3.operation = NULL;
635       result = PEER3_STARTED;
636       common_operation =
637           GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer2.peer,
638                                           peer1.peer);
639       break;
640     default:
641       GNUNET_break (0);
642       abort_test();
643       return;
644     }    
645     break;
646   case GNUNET_TESTBED_ET_PEER_STOP:
647     if (PEERS_CONNECTED_2 != result)
648     {
649       GNUNET_break (0);
650       abort_test();
651       return;
652     }
653     if (event->details.peer_stop.peer == peer1.peer)
654     {
655       peer1.is_running = GNUNET_NO;
656       GNUNET_TESTBED_operation_done (peer1.operation);
657     }
658     else if (event->details.peer_stop.peer == peer2.peer)
659     {
660       peer2.is_running = GNUNET_NO;
661       GNUNET_TESTBED_operation_done (peer2.operation);
662     }
663     else if (event->details.peer_stop.peer == peer3.peer)
664     {
665       peer3.is_running = GNUNET_NO;
666       GNUNET_TESTBED_operation_done (peer3.operation);
667     }
668     else
669     {
670       GNUNET_break (0);
671       abort_test();
672       return;
673     }
674     if ((GNUNET_NO == peer1.is_running) &&
675         (GNUNET_NO == peer2.is_running) &&
676         (GNUNET_NO == peer3.is_running))
677     {
678       result = PEERS_STOPPED;
679       peer1.operation = GNUNET_TESTBED_peer_destroy (peer1.peer);
680       peer2.operation = GNUNET_TESTBED_peer_destroy (peer2.peer);
681       peer3.operation = GNUNET_TESTBED_peer_destroy (peer3.peer);
682     }
683     break;
684   case GNUNET_TESTBED_ET_CONNECT:
685     if ((NULL != peer1.operation) ||
686         (NULL != peer2.operation) ||
687         (NULL != peer3.operation))
688     {
689       GNUNET_break (0);
690       abort_test();
691       return;
692     }
693     switch (result)
694     {
695     case PEER3_STARTED:
696       if ((NULL == common_operation) ||
697           (event->details.peer_connect.peer1 != peer2.peer) ||
698           (event->details.peer_connect.peer2 != peer1.peer))
699       {
700         GNUNET_break (0);
701         abort_test();
702         return;
703       }
704       break;
705     case PEERS_2_3_CONNECTED:
706       if ((NULL == common_operation) ||
707           (event->details.peer_connect.peer1 != peer1.peer) ||
708           (event->details.peer_connect.peer2 != peer2.peer))
709       {
710         GNUNET_break (0);
711         abort_test();
712         return;
713       }
714       break;
715     case PEERS_1_2_CONNECTED: 
716       if ((NULL == common_operation) ||
717           (event->details.peer_connect.peer1 != peer2.peer) ||
718           (event->details.peer_connect.peer2 != peer3.peer))
719       {
720         GNUNET_break (0);
721         abort_test();
722         return;
723       }
724       break;
725     default:
726       GNUNET_break (0);
727       abort_test();
728       return;
729     }
730     break;
731   default:
732     GNUNET_break (0);
733     abort_test();
734     return;
735   }
736 }
737
738
739 /**
740  * Callback which will be called to after a host registration succeeded or failed
741  *
742  * @param cls the host which has been registered
743  * @param emsg the error message; NULL if host registration is successful
744  */
745 static void
746 registration_comp (void *cls, const char *emsg)
747 {
748   reg_handle = NULL;
749   if (cls == neighbour1)
750   {
751     neighbour2 = GNUNET_TESTBED_host_create ("127.0.0.1", NULL, 0);
752     if (NULL == neighbour2)
753     {
754       GNUNET_break (0);
755       abort_test();
756       return;
757     }
758     reg_handle =
759         GNUNET_TESTBED_register_host (controller1, neighbour2, &registration_comp,
760                                       neighbour2);
761     if (NULL == reg_handle)
762     {
763       GNUNET_break (0);
764       abort_test();
765       return;
766     }
767     return;
768   }
769   if (cls != neighbour2)
770   {
771     GNUNET_break (0);
772     abort_test();
773     return;
774   }
775   peer1.operation =
776       GNUNET_TESTBED_peer_create (controller1, host, cfg, &peer_create_cb,
777                                   &peer1);
778   if (NULL == peer1.operation)
779   {
780     GNUNET_break (0);
781     abort_test();
782     return;
783   }
784 }
785
786
787 /**
788  * Callback to signal successfull startup of the controller process
789  *
790  * @param cls the closure from GNUNET_TESTBED_controller_start()
791  * @param cfg the configuration with which the controller has been started;
792  *          NULL if status is not GNUNET_OK
793  * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
794  *          GNUNET_TESTBED_controller_stop() shouldn't be called in this case
795  */
796 static void
797 status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config, int status)
798 {
799   uint64_t event_mask;
800   
801   if (GNUNET_OK != status)
802   {
803     GNUNET_break (0);
804     cp1 = NULL;
805     abort_test();
806     return;
807   }
808   event_mask = 0;
809   event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START);
810   event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP);
811   event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT);
812   event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED);
813   switch (result)
814   {
815   case INIT:
816     controller1 =
817         GNUNET_TESTBED_controller_connect (config, host, event_mask, &controller_cb,
818                                            NULL);
819     if (NULL == controller1)
820     {
821       GNUNET_break (0);
822       abort_test();
823       return;
824     }
825     result = CONTROLLER1_UP;
826     neighbour1 = GNUNET_TESTBED_host_create ("127.0.0.1", NULL, 0);
827     if (NULL == neighbour1)
828     {
829       GNUNET_break (0);
830       abort_test();
831       return;
832     }
833     reg_handle =
834         GNUNET_TESTBED_register_host (controller1, neighbour1, &registration_comp,
835                                       neighbour1);
836     if (NULL == reg_handle)
837     {
838       GNUNET_break (0);
839       abort_test();
840       return;
841     }
842     break;
843   default:
844     GNUNET_break (0);
845     abort_test();
846     return;
847   }  
848 }
849
850
851 /**
852  * Main run function.
853  *
854  * @param cls NULL
855  * @param args arguments passed to GNUNET_PROGRAM_run
856  * @param cfgfile the path to configuration file
857  * @param cfg the configuration file handle
858  */
859 static void
860 run (void *cls, char *const *args, const char *cfgfile,
861      const struct GNUNET_CONFIGURATION_Handle *config)
862 {
863   host = GNUNET_TESTBED_host_create (NULL, NULL, 0);
864   if (NULL == host)
865   {
866     GNUNET_break (0);
867     abort_test();
868     return;
869   }
870   if (GNUNET_YES != GNUNET_TESTBED_is_host_habitable (host, config))
871   {
872     GNUNET_TESTBED_host_destroy (host);
873     host = NULL;
874     (void) PRINTF ("%s",
875                    "Unable to run the test as this system is not configured "
876                    "to use password less SSH logins to localhost.\n"
877                    "Marking test as successful\n");
878     result = SUCCESS;
879     return;
880   }
881   cfg = GNUNET_CONFIGURATION_dup (config);
882   cp1 = GNUNET_TESTBED_controller_start ("127.0.0.1", host, cfg, status_cb,
883                                          NULL);
884   abort_task =
885       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
886                                     (GNUNET_TIME_UNIT_MINUTES, 3), &do_abort,
887                                     NULL);
888 }
889
890
891 /**
892  * Main function
893  */
894 int
895 main (int argc, char **argv)
896 {
897   char *const argv2[] = { "test_testbed_api_3peers_3controllers",
898                           "-c", "test_testbed_api.conf",
899                           NULL
900   };
901   struct GNUNET_GETOPT_CommandLineOption options[] = {
902     GNUNET_GETOPT_OPTION_END
903   };
904   int ret;
905
906   result = INIT;
907   ret =
908       GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
909                           "test_testbed_api_3peers_3controllers", "nohelp",
910                           options, &run, NULL);
911   if ((GNUNET_OK != ret) || (SUCCESS != result))
912     return 1;
913   return 0;
914 }
915
916 /* end of test_testbed_api_3peers_3controllers.c */