-fix (C) notices
[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
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., 51 Franklin Street, Fifth Floor,
18      Boston, MA 02110-1301, 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
41 static void
42 notify_connect_complete (void *cls,
43                          struct GNUNET_TESTBED_Operation *op,
44                          const char *emsg)
45 {
46   GNUNET_TESTBED_operation_done (op);
47   if (NULL != emsg)
48   {
49     FPRINTF (stderr, "Failed to connect two peers: %s\n", emsg);
50     GNUNET_SCHEDULER_shutdown ();
51     ok = 1;
52     return;
53   }
54   connect_left--;
55   if (0 == connect_left)
56   {
57     /* FIXME: check that topology adds a few more links
58      * in addition to those that were seeded */
59     GNUNET_SCHEDULER_shutdown ();
60   }
61 }
62
63
64 static void
65 do_connect (void *cls,
66             struct GNUNET_TESTBED_RunHandle *h,
67             unsigned int num_peers,
68             struct GNUNET_TESTBED_Peer **peers,
69             unsigned int links_succeeded,
70             unsigned int links_failed)
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   (void) 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 */