- mark operation done in case of failure
[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
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             unsigned int num_peers,
67             struct GNUNET_TESTBED_Peer **peers)
68 {
69   unsigned int i;
70
71   GNUNET_assert (NUM_PEERS == num_peers);
72   for (i=0;i<num_peers-1;i++)
73     {
74       connect_left++;
75       GNUNET_TESTBED_overlay_connect (NULL,
76                                       &notify_connect_complete, NULL,
77                                       peers[i], peers[i+1]);
78     }
79 }
80
81
82 int
83 main (int argc, char *argv[])
84 {
85   (void) GNUNET_TESTBED_test_run ("test-gnunet-daemon-topology",
86                                   "test_gnunet_daemon_topology_data.conf",
87                                   NUM_PEERS,
88                                   0, NULL, NULL,
89                                   &do_connect, NULL);
90   GNUNET_DISK_directory_remove ("/tmp/test-gnunet-topology");
91   return ok;
92 }
93
94 /* end of test_gnunet_daemon_topology.c */