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