- disable try_connect to force topology
[oweals/gnunet.git] / src / mesh / test_mesh_2dtorus.c
1 /*
2      This file is part of GNUnet.
3      (C) 2011 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 mesh/test_mesh_2dtorus.c
22  *
23  * @brief Test for creating a 2dtorus.
24  */
25 #include "platform.h"
26 #include "mesh_test_lib.h"
27 #include "gnunet_mesh_service.h"
28
29 #define REMOVE_DIR GNUNET_YES
30
31 /**
32  * How long until we give up on connecting the peers?
33  */
34 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1500)
35
36 /**
37  * Time to wait for stuff that should be rather fast
38  */
39 #define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
40
41
42 /**
43  * How many events have happened
44  */
45 static int ok;
46
47 /**
48  * Total number of currently running peers.
49  */
50 static unsigned long long peers_running;
51
52 /**
53  * Task to time out.
54  */
55 static GNUNET_SCHEDULER_TaskIdentifier timeout_task;
56
57
58 static void
59 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
60 {
61   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shutting down test\n");
62 }
63
64
65 /**
66  * test main: start test when all peers are connected
67  *
68  * @param cls Closure.
69  * @param ctx Argument to give to GNUNET_MESH_TEST_cleanup on test end.
70  * @param num_peers Number of peers that are running.
71  * @param peers Array of peers.
72  * @param meshes Handle to each of the MESHs of the peers.
73  */
74 static void
75 tmain (void *cls,
76        struct GNUNET_MESH_TEST_Context *ctx,
77        unsigned int num_peers,
78        struct GNUNET_TESTBED_Peer **peers,
79        struct GNUNET_MESH_Handle **meshes)
80 {
81   if (16 != num_peers)
82   {
83     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
84                 "running peers mismatch, aborting test!\n");
85     ok--;
86     GNUNET_MESH_TEST_cleanup (ctx);
87     return;
88   }
89   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
90               "testbed started successfully with ?? connections\n");
91   peers_running = num_peers;
92   timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, 
93                                                &shutdown_task, ctx);
94   ok = GNUNET_OK;
95   GNUNET_MESH_TEST_cleanup (ctx);
96 }
97
98
99 /**
100  * Main: start test
101  */
102 int
103 main (int argc, char *argv[])
104 {
105   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Start\n");
106   ok = GNUNET_SYSERR;
107
108   GNUNET_MESH_TEST_run ("test_mesh_2dtorus",
109                         "test_mesh_2dtorus.conf",
110                         16,
111                         &tmain,
112                         NULL,
113                         NULL,
114                         NULL,
115                         NULL,
116                         NULL
117   );
118
119   if (GNUNET_OK != ok)
120   {
121     GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "FAILED!\n");
122     return 1;
123   }
124   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "success\n");
125   return 0;
126 }
127
128 /* end of test_mesh_2dtorus.c */