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