first batch of license fixes (boring)
[oweals/gnunet.git] / src / topology / test_gnunet_daemon_topology.c
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2009, 2012 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 topology/test_gnunet_daemon_topology.c
17  * @brief testcase for topology maintenance code
18  */
19 #include "platform.h"
20 #include "gnunet_testbed_service.h"
21
22
23 #define NUM_PEERS 8
24
25 /**
26  * How long until we give up on connecting the peers?
27  */
28 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 600)
29
30
31 static int ok;
32
33 static unsigned int connect_left;
34
35
36 static void
37 notify_connect_complete (void *cls,
38                          struct GNUNET_TESTBED_Operation *op,
39                          const char *emsg)
40 {
41   GNUNET_TESTBED_operation_done (op);
42   if (NULL != emsg)
43   {
44     FPRINTF (stderr, "Failed to connect two peers: %s\n", emsg);
45     GNUNET_SCHEDULER_shutdown ();
46     ok = 1;
47     return;
48   }
49   connect_left--;
50   if (0 == connect_left)
51   {
52     /* FIXME: check that topology adds a few more links
53      * in addition to those that were seeded */
54     GNUNET_SCHEDULER_shutdown ();
55   }
56 }
57
58
59 static void
60 do_connect (void *cls,
61             struct GNUNET_TESTBED_RunHandle *h,
62             unsigned int num_peers,
63             struct GNUNET_TESTBED_Peer **peers,
64             unsigned int links_succeeded,
65             unsigned int links_failed)
66 {
67   unsigned int i;
68
69   GNUNET_assert (NUM_PEERS == num_peers);
70   for (i=0;i<num_peers-1;i++)
71     {
72       connect_left++;
73       GNUNET_TESTBED_overlay_connect (NULL,
74                                       &notify_connect_complete, NULL,
75                                       peers[i], peers[i+1]);
76     }
77 }
78
79
80 int
81 main (int argc, char *argv[])
82 {
83   (void) GNUNET_TESTBED_test_run ("test-gnunet-daemon-topology",
84                                   "test_gnunet_daemon_topology_data.conf",
85                                   NUM_PEERS,
86                                   0, NULL, NULL,
87                                   &do_connect, NULL);
88   GNUNET_DISK_directory_remove ("/tmp/test-gnunet-topology");
89   return ok;
90 }
91
92 /* end of test_gnunet_daemon_topology.c */