first batch of license fixes (boring)
[oweals/gnunet.git] / src / dv / test_transport_dv.c
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2009, 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  * @file dv/test_transport_dv.c
17  * @brief base testcase for testing distance vector transport
18  */
19 #include "platform.h"
20 #include "gnunet_core_service.h"
21 #include "gnunet_testbed_service.h"
22
23 /**
24  * Return value from main, set to 0 on success.
25  */
26 static int ok;
27
28 struct GNUNET_TESTBED_Operation *topology_op;
29
30 static struct GNUNET_SCHEDULER_Task * shutdown_task;
31
32
33 static void
34 do_shutdown (void *cls)
35 {
36   shutdown_task = NULL;
37   if (NULL != topology_op)
38   {
39     GNUNET_TESTBED_operation_done (topology_op);
40     topology_op = NULL;
41   }
42 }
43
44
45 static void
46 topology_completed (void *cls,
47                     unsigned int nsuccess,
48                     unsigned int nfailures)
49 {
50   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
51               "Links successful %u / %u failed\n",
52               nsuccess,
53               nfailures);
54   GNUNET_TESTBED_operation_done (topology_op);
55   topology_op = NULL;
56
57   if (nfailures > 0)
58   {
59     fprintf (stderr,
60              "Error: links successful %u but %u failed\n",
61              nsuccess,
62              nfailures);
63     ok = 1;
64   }
65   else
66     ok = 0;
67
68   GNUNET_SCHEDULER_shutdown ();
69 }
70
71
72 static void
73 test_connection (void *cls,
74                  struct GNUNET_TESTBED_RunHandle *h,
75                  unsigned int num_peers,
76                  struct GNUNET_TESTBED_Peer **peers,
77                  unsigned int links_succeeded,
78                  unsigned int links_failed)
79 {
80   shutdown_task = GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
81                                                  NULL);
82   if (4 != num_peers)
83   {
84     ok = 1;
85     fprintf (stderr,
86              "Only %u out of 4 peers were started ...\n",
87              num_peers);
88   }
89
90   if (0 != links_failed)
91   {
92     /* All peers except DV peers are connected  */
93     fprintf (stderr,
94              "Testbed failed to connect peers (%u links OK, %u links failed)\n",
95              links_succeeded,
96              links_failed);
97
98     topology_op = GNUNET_TESTBED_overlay_configure_topology
99       (NULL, num_peers, peers, NULL,
100        &topology_completed, NULL,
101        GNUNET_TESTBED_TOPOLOGY_CLIQUE,
102        GNUNET_TESTBED_TOPOLOGY_OPTION_END);
103     return;
104   }
105
106   ok = 1;
107   fprintf (stderr,
108            "Testbed connected peers, should not happen...\n");
109   GNUNET_SCHEDULER_shutdown ();
110 }
111
112
113 int
114 main (int argc, char *argv[])
115 {
116   ok = 1;
117   /* Connecting initial topology */
118   (void) GNUNET_TESTBED_test_run ("test-transport-dv",
119                                   "test_transport_dv_data.conf",
120                                   4,
121                                   0, NULL, NULL,
122                                   &test_connection, NULL);
123   return ok;
124 }
125
126 /* end of test_transport_dv.c */