diff options
-rw-r--r-- | src/cadet/Makefile.am | 119 | ||||
-rw-r--r-- | src/cadet/cadet_test_lib.c | 303 | ||||
-rw-r--r-- | src/cadet/cadet_test_lib.h | 106 |
3 files changed, 56 insertions, 472 deletions
diff --git a/src/cadet/Makefile.am b/src/cadet/Makefile.am index c33a653b0..d7208d601 100644 --- a/src/cadet/Makefile.am +++ b/src/cadet/Makefile.am | |||
@@ -86,37 +86,30 @@ endif | |||
86 | 86 | ||
87 | 87 | ||
88 | if HAVE_TESTING | 88 | if HAVE_TESTING |
89 | noinst_LTLIBRARIES = libgnunetcadettest.la libgnunetcadettestnew.la $(noinst_LIB_EXP) | 89 | noinst_LTLIBRARIES = libgnunetcadettest.la $(noinst_LIB_EXP) |
90 | noinst_PROGRAMS = gnunet-cadet-profiler | 90 | noinst_PROGRAMS = gnunet-cadet-profiler |
91 | endif | 91 | endif |
92 | 92 | ||
93 | libgnunetcadettest_la_SOURCES = \ | ||
94 | cadet_test_lib.c cadet_test_lib.h | ||
95 | libgnunetcadettest_la_LIBADD = \ | ||
96 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
97 | $(top_builddir)/src/testbed/libgnunettestbed.la \ | ||
98 | libgnunetcadet.la | ||
99 | |||
100 | if HAVE_TESTING | 93 | if HAVE_TESTING |
101 | check_PROGRAMS = \ | 94 | check_PROGRAMS = \ |
102 | test_cadet_local_mq \ | 95 | test_cadet_local_mq \ |
103 | test_cadet_2_forward_new \ | 96 | test_cadet_2_forward \ |
104 | test_cadet_2_forward_new \ | 97 | test_cadet_2_forward \ |
105 | test_cadet_2_signal_new \ | 98 | test_cadet_2_signal \ |
106 | test_cadet_2_keepalive_new \ | 99 | test_cadet_2_keepalive \ |
107 | test_cadet_2_speed_new \ | 100 | test_cadet_2_speed \ |
108 | test_cadet_2_speed_ack_new \ | 101 | test_cadet_2_speed_ack \ |
109 | test_cadet_2_speed_backwards_new \ | 102 | test_cadet_2_speed_backwards \ |
110 | test_cadet_2_speed_reliable_new \ | 103 | test_cadet_2_speed_reliable \ |
111 | test_cadet_2_speed_reliable_backwards_new \ | 104 | test_cadet_2_speed_reliable_backwards \ |
112 | test_cadet_5_forward_new \ | 105 | test_cadet_5_forward \ |
113 | test_cadet_5_signal_new \ | 106 | test_cadet_5_signal \ |
114 | test_cadet_5_keepalive_new \ | 107 | test_cadet_5_keepalive \ |
115 | test_cadet_5_speed_new \ | 108 | test_cadet_5_speed \ |
116 | test_cadet_5_speed_ack_new \ | 109 | test_cadet_5_speed_ack \ |
117 | test_cadet_5_speed_reliable_new \ | 110 | test_cadet_5_speed_reliable \ |
118 | test_cadet_5_speed_reliable_backwards_new \ | 111 | test_cadet_5_speed_reliable_backwards \ |
119 | test_cadet_5_speed_backwards_new | 112 | test_cadet_5_speed_backwards |
120 | endif | 113 | endif |
121 | 114 | ||
122 | ld_cadet_test_lib = \ | 115 | ld_cadet_test_lib = \ |
@@ -146,89 +139,89 @@ test_cadet_local_mq_LDADD = \ | |||
146 | $(top_builddir)/src/util/libgnunetutil.la | 139 | $(top_builddir)/src/util/libgnunetutil.la |
147 | 140 | ||
148 | 141 | ||
149 | libgnunetcadettestnew_la_SOURCES = \ | 142 | libgnunetcadettest_la_SOURCES = \ |
150 | cadet_test_lib_new.c cadet_test_lib_new.h | 143 | cadet_test_lib_new.c cadet_test_lib_new.h |
151 | libgnunetcadettestnew_la_LIBADD = \ | 144 | libgnunetcadettest_la_LIBADD = \ |
152 | $(top_builddir)/src/util/libgnunetutil.la \ | 145 | $(top_builddir)/src/util/libgnunetutil.la \ |
153 | $(top_builddir)/src/testbed/libgnunettestbed.la \ | 146 | $(top_builddir)/src/testbed/libgnunettestbed.la \ |
154 | libgnunetcadetnew.la | 147 | libgnunetcadetnew.la |
155 | 148 | ||
156 | ld_cadet_test_lib_new = \ | 149 | ld_cadet_test_lib = \ |
157 | $(top_builddir)/src/util/libgnunetutil.la \ | 150 | $(top_builddir)/src/util/libgnunetutil.la \ |
158 | $(top_builddir)/src/testing/libgnunettesting.la \ | 151 | $(top_builddir)/src/testing/libgnunettesting.la \ |
159 | libgnunetcadetnew.la \ | 152 | libgnunetcadetnew.la \ |
160 | libgnunetcadettestnew.la \ | 153 | libgnunetcadettest.la \ |
161 | $(top_builddir)/src/testbed/libgnunettestbed.la \ | 154 | $(top_builddir)/src/testbed/libgnunettestbed.la \ |
162 | $(top_builddir)/src/statistics/libgnunetstatistics.la | 155 | $(top_builddir)/src/statistics/libgnunetstatistics.la |
163 | dep_cadet_test_lib_new = \ | 156 | dep_cadet_test_lib = \ |
164 | libgnunetcadetnew.la \ | 157 | libgnunetcadetnew.la \ |
165 | libgnunetcadettestnew.la \ | 158 | libgnunetcadettest.la \ |
166 | $(top_builddir)/src/statistics/libgnunetstatistics.la | 159 | $(top_builddir)/src/statistics/libgnunetstatistics.la |
167 | 160 | ||
168 | test_cadet_2_forward_new_SOURCES = \ | 161 | test_cadet_2_forward_SOURCES = \ |
169 | test_cadet_new.c | 162 | test_cadet_new.c |
170 | test_cadet_2_forward_new_LDADD = $(ld_cadet_test_lib_new) | 163 | test_cadet_2_forward_LDADD = $(ld_cadet_test_lib) |
171 | 164 | ||
172 | test_cadet_2_signal_new_SOURCES = \ | 165 | test_cadet_2_signal_SOURCES = \ |
173 | test_cadet_new.c | 166 | test_cadet_new.c |
174 | test_cadet_2_signal_new_LDADD = $(ld_cadet_test_lib_new) | 167 | test_cadet_2_signal_LDADD = $(ld_cadet_test_lib) |
175 | 168 | ||
176 | test_cadet_2_keepalive_new_SOURCES = \ | 169 | test_cadet_2_keepalive_SOURCES = \ |
177 | test_cadet_new.c | 170 | test_cadet_new.c |
178 | test_cadet_2_keepalive_new_LDADD = $(ld_cadet_test_lib_new) | 171 | test_cadet_2_keepalive_LDADD = $(ld_cadet_test_lib) |
179 | 172 | ||
180 | test_cadet_2_speed_new_SOURCES = \ | 173 | test_cadet_2_speed_SOURCES = \ |
181 | test_cadet_new.c | 174 | test_cadet_new.c |
182 | test_cadet_2_speed_new_LDADD = $(ld_cadet_test_lib_new) | 175 | test_cadet_2_speed_LDADD = $(ld_cadet_test_lib) |
183 | 176 | ||
184 | test_cadet_2_speed_ack_new_SOURCES = \ | 177 | test_cadet_2_speed_ack_SOURCES = \ |
185 | test_cadet_new.c | 178 | test_cadet_new.c |
186 | test_cadet_2_speed_ack_new_LDADD = $(ld_cadet_test_lib_new) | 179 | test_cadet_2_speed_ack_LDADD = $(ld_cadet_test_lib) |
187 | 180 | ||
188 | test_cadet_2_speed_backwards_new_SOURCES = \ | 181 | test_cadet_2_speed_backwards_SOURCES = \ |
189 | test_cadet_new.c | 182 | test_cadet_new.c |
190 | test_cadet_2_speed_backwards_new_LDADD = $(ld_cadet_test_lib_new) | 183 | test_cadet_2_speed_backwards_LDADD = $(ld_cadet_test_lib) |
191 | 184 | ||
192 | test_cadet_2_speed_reliable_new_SOURCES = \ | 185 | test_cadet_2_speed_reliable_SOURCES = \ |
193 | test_cadet_new.c | 186 | test_cadet_new.c |
194 | test_cadet_2_speed_reliable_new_LDADD = $(ld_cadet_test_lib_new) | 187 | test_cadet_2_speed_reliable_LDADD = $(ld_cadet_test_lib) |
195 | 188 | ||
196 | test_cadet_2_speed_reliable_backwards_new_SOURCES = \ | 189 | test_cadet_2_speed_reliable_backwards_SOURCES = \ |
197 | test_cadet_new.c | 190 | test_cadet_new.c |
198 | test_cadet_2_speed_reliable_backwards_new_LDADD = $(ld_cadet_test_lib_new) | 191 | test_cadet_2_speed_reliable_backwards_LDADD = $(ld_cadet_test_lib) |
199 | 192 | ||
200 | 193 | ||
201 | test_cadet_5_forward_new_SOURCES = \ | 194 | test_cadet_5_forward_SOURCES = \ |
202 | test_cadet_new.c | 195 | test_cadet_new.c |
203 | test_cadet_5_forward_new_LDADD = $(ld_cadet_test_lib_new) | 196 | test_cadet_5_forward_LDADD = $(ld_cadet_test_lib) |
204 | 197 | ||
205 | test_cadet_5_signal_new_SOURCES = \ | 198 | test_cadet_5_signal_SOURCES = \ |
206 | test_cadet_new.c | 199 | test_cadet_new.c |
207 | test_cadet_5_signal_new_LDADD = $(ld_cadet_test_lib_new) | 200 | test_cadet_5_signal_LDADD = $(ld_cadet_test_lib) |
208 | 201 | ||
209 | test_cadet_5_keepalive_new_SOURCES = \ | 202 | test_cadet_5_keepalive_SOURCES = \ |
210 | test_cadet_new.c | 203 | test_cadet_new.c |
211 | test_cadet_5_keepalive_new_LDADD = $(ld_cadet_test_lib_new) | 204 | test_cadet_5_keepalive_LDADD = $(ld_cadet_test_lib) |
212 | 205 | ||
213 | test_cadet_5_speed_new_SOURCES = \ | 206 | test_cadet_5_speed_SOURCES = \ |
214 | test_cadet_new.c | 207 | test_cadet_new.c |
215 | test_cadet_5_speed_new_LDADD = $(ld_cadet_test_lib_new) | 208 | test_cadet_5_speed_LDADD = $(ld_cadet_test_lib) |
216 | 209 | ||
217 | test_cadet_5_speed_ack_new_SOURCES = \ | 210 | test_cadet_5_speed_ack_SOURCES = \ |
218 | test_cadet_new.c | 211 | test_cadet_new.c |
219 | test_cadet_5_speed_ack_new_LDADD = $(ld_cadet_test_lib_new) | 212 | test_cadet_5_speed_ack_LDADD = $(ld_cadet_test_lib) |
220 | 213 | ||
221 | test_cadet_5_speed_backwards_new_SOURCES = \ | 214 | test_cadet_5_speed_backwards_SOURCES = \ |
222 | test_cadet_new.c | 215 | test_cadet_new.c |
223 | test_cadet_5_speed_backwards_new_LDADD = $(ld_cadet_test_lib_new) | 216 | test_cadet_5_speed_backwards_LDADD = $(ld_cadet_test_lib) |
224 | 217 | ||
225 | test_cadet_5_speed_reliable_new_SOURCES = \ | 218 | test_cadet_5_speed_reliable_SOURCES = \ |
226 | test_cadet_new.c | 219 | test_cadet_new.c |
227 | test_cadet_5_speed_reliable_new_LDADD = $(ld_cadet_test_lib_new) | 220 | test_cadet_5_speed_reliable_LDADD = $(ld_cadet_test_lib) |
228 | 221 | ||
229 | test_cadet_5_speed_reliable_backwards_new_SOURCES = \ | 222 | test_cadet_5_speed_reliable_backwards_SOURCES = \ |
230 | test_cadet_new.c | 223 | test_cadet_new.c |
231 | test_cadet_5_speed_reliable_backwards_new_LDADD = $(ld_cadet_test_lib_new) | 224 | test_cadet_5_speed_reliable_backwards_LDADD = $(ld_cadet_test_lib) |
232 | 225 | ||
233 | 226 | ||
234 | if ENABLE_TEST_RUN | 227 | if ENABLE_TEST_RUN |
diff --git a/src/cadet/cadet_test_lib.c b/src/cadet/cadet_test_lib.c deleted file mode 100644 index 9a70dad49..000000000 --- a/src/cadet/cadet_test_lib.c +++ /dev/null | |||
@@ -1,303 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 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 cadet/cadet_test_lib.c | ||
22 | * @author Bartlomiej Polot | ||
23 | * @brief library for writing CADET tests | ||
24 | */ | ||
25 | #include "platform.h" | ||
26 | #include "gnunet_util_lib.h" | ||
27 | #include "cadet_test_lib.h" | ||
28 | #include "gnunet_cadet_service.h" | ||
29 | |||
30 | /** | ||
31 | * Test context for a CADET Test. | ||
32 | */ | ||
33 | struct GNUNET_CADET_TEST_Context | ||
34 | { | ||
35 | /** | ||
36 | * Array of running peers. | ||
37 | */ | ||
38 | struct GNUNET_TESTBED_Peer **peers; | ||
39 | |||
40 | /** | ||
41 | * Array of handles to the CADET for each peer. | ||
42 | */ | ||
43 | struct GNUNET_CADET_Handle **cadetes; | ||
44 | |||
45 | /** | ||
46 | * Operation associated with the connection to the CADET. | ||
47 | */ | ||
48 | struct GNUNET_TESTBED_Operation **ops; | ||
49 | |||
50 | /** | ||
51 | * Main function of the test to run once all CADETs are available. | ||
52 | */ | ||
53 | GNUNET_CADET_TEST_AppMain app_main; | ||
54 | |||
55 | /** | ||
56 | * Closure for 'app_main'. | ||
57 | */ | ||
58 | void *app_main_cls; | ||
59 | |||
60 | /** | ||
61 | * Number of peers running, size of the arrays above. | ||
62 | */ | ||
63 | unsigned int num_peers; | ||
64 | |||
65 | /** | ||
66 | * Handler for incoming tunnels. | ||
67 | */ | ||
68 | GNUNET_CADET_InboundChannelNotificationHandler *new_channel; | ||
69 | |||
70 | /** | ||
71 | * Cleaner for destroyed incoming tunnels. | ||
72 | */ | ||
73 | GNUNET_CADET_ChannelEndHandler *cleaner; | ||
74 | |||
75 | /** | ||
76 | * Message handlers. | ||
77 | */ | ||
78 | struct GNUNET_CADET_MessageHandler* handlers; | ||
79 | |||
80 | /** | ||
81 | * Application ports. | ||
82 | */ | ||
83 | const struct GNUNET_HashCode **ports; | ||
84 | |||
85 | }; | ||
86 | |||
87 | |||
88 | /** | ||
89 | * Context for a cadet adapter callback. | ||
90 | */ | ||
91 | struct GNUNET_CADET_TEST_AdapterContext | ||
92 | { | ||
93 | /** | ||
94 | * Peer number for the particular peer. | ||
95 | */ | ||
96 | unsigned int peer; | ||
97 | |||
98 | /** | ||
99 | * General context. | ||
100 | */ | ||
101 | struct GNUNET_CADET_TEST_Context *ctx; | ||
102 | }; | ||
103 | |||
104 | |||
105 | /** | ||
106 | * Adapter function called to establish a connection to | ||
107 | * the CADET service. | ||
108 | * | ||
109 | * @param cls closure | ||
110 | * @param cfg configuration of the peer to connect to; will be available until | ||
111 | * GNUNET_TESTBED_operation_done() is called on the operation returned | ||
112 | * from GNUNET_TESTBED_service_connect() | ||
113 | * @return service handle to return in 'op_result', NULL on error | ||
114 | */ | ||
115 | static void * | ||
116 | cadet_connect_adapter (void *cls, | ||
117 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
118 | { | ||
119 | struct GNUNET_CADET_TEST_AdapterContext *actx = cls; | ||
120 | struct GNUNET_CADET_TEST_Context *ctx = actx->ctx; | ||
121 | struct GNUNET_CADET_Handle *h; | ||
122 | |||
123 | h = GNUNET_CADET_connect (cfg, | ||
124 | (void *) (long) actx->peer, | ||
125 | ctx->cleaner, | ||
126 | ctx->handlers); | ||
127 | if (NULL == ctx->ports) | ||
128 | return h; | ||
129 | |||
130 | for (int i = 0; NULL != ctx->ports[i]; i++) | ||
131 | { | ||
132 | (void ) GNUNET_CADET_open_port (h, ctx->ports[i], | ||
133 | ctx->new_channel, | ||
134 | (void *) (long) actx->peer); | ||
135 | } | ||
136 | |||
137 | return h; | ||
138 | } | ||
139 | |||
140 | |||
141 | /** | ||
142 | * Adapter function called to destroy a connection to | ||
143 | * the CADET service. | ||
144 | * | ||
145 | * @param cls closure | ||
146 | * @param op_result service handle returned from the connect adapter | ||
147 | */ | ||
148 | static void | ||
149 | cadet_disconnect_adapter (void *cls, | ||
150 | void *op_result) | ||
151 | { | ||
152 | struct GNUNET_CADET_Handle *cadet = op_result; | ||
153 | struct GNUNET_CADET_TEST_AdapterContext *actx = cls; | ||
154 | |||
155 | GNUNET_free (actx); | ||
156 | GNUNET_CADET_disconnect (cadet); | ||
157 | } | ||
158 | |||
159 | |||
160 | /** | ||
161 | * Callback to be called when a service connect operation is completed. | ||
162 | * | ||
163 | * @param cls The callback closure from functions generating an operation. | ||
164 | * @param op The operation that has been finished. | ||
165 | * @param ca_result The service handle returned from | ||
166 | * GNUNET_TESTBED_ConnectAdapter() (cadet handle). | ||
167 | * @param emsg Error message in case the operation has failed. | ||
168 | * NULL if operation has executed successfully. | ||
169 | */ | ||
170 | static void | ||
171 | cadet_connect_cb (void *cls, | ||
172 | struct GNUNET_TESTBED_Operation *op, | ||
173 | void *ca_result, | ||
174 | const char *emsg) | ||
175 | { | ||
176 | struct GNUNET_CADET_TEST_Context *ctx = cls; | ||
177 | unsigned int i; | ||
178 | |||
179 | if (NULL != emsg) | ||
180 | { | ||
181 | fprintf (stderr, "Failed to connect to CADET service: %s\n", | ||
182 | emsg); | ||
183 | GNUNET_SCHEDULER_shutdown (); | ||
184 | return; | ||
185 | } | ||
186 | for (i = 0; i < ctx->num_peers; i++) | ||
187 | if (op == ctx->ops[i]) | ||
188 | { | ||
189 | ctx->cadetes[i] = ca_result; | ||
190 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "...cadet %u connected\n", i); | ||
191 | } | ||
192 | for (i = 0; i < ctx->num_peers; i++) | ||
193 | if (NULL == ctx->cadetes[i]) | ||
194 | return; /* still some CADET connections missing */ | ||
195 | /* all CADET connections ready! */ | ||
196 | ctx->app_main (ctx->app_main_cls, | ||
197 | ctx, | ||
198 | ctx->num_peers, | ||
199 | ctx->peers, | ||
200 | ctx->cadetes); | ||
201 | } | ||
202 | |||
203 | |||
204 | void | ||
205 | GNUNET_CADET_TEST_cleanup (struct GNUNET_CADET_TEST_Context *ctx) | ||
206 | { | ||
207 | unsigned int i; | ||
208 | |||
209 | for (i = 0; i < ctx->num_peers; i++) | ||
210 | { | ||
211 | GNUNET_assert (NULL != ctx->ops[i]); | ||
212 | GNUNET_TESTBED_operation_done (ctx->ops[i]); | ||
213 | ctx->ops[i] = NULL; | ||
214 | } | ||
215 | GNUNET_free (ctx->ops); | ||
216 | GNUNET_free (ctx->cadetes); | ||
217 | GNUNET_free (ctx); | ||
218 | GNUNET_SCHEDULER_shutdown (); | ||
219 | } | ||
220 | |||
221 | |||
222 | /** | ||
223 | * Callback run when the testbed is ready (peers running and connected to | ||
224 | * each other) | ||
225 | * | ||
226 | * @param cls Closure (context). | ||
227 | * @param h the run handle | ||
228 | * @param num_peers Number of peers that are running. | ||
229 | * @param peers Handles to each one of the @c num_peers peers. | ||
230 | * @param links_succeeded the number of overlay link connection attempts that | ||
231 | * succeeded | ||
232 | * @param links_failed the number of overlay link connection attempts that | ||
233 | * failed | ||
234 | */ | ||
235 | static void | ||
236 | cadet_test_run (void *cls, | ||
237 | struct GNUNET_TESTBED_RunHandle *h, | ||
238 | unsigned int num_peers, | ||
239 | struct GNUNET_TESTBED_Peer **peers, | ||
240 | unsigned int links_succeeded, | ||
241 | unsigned int links_failed) | ||
242 | { | ||
243 | struct GNUNET_CADET_TEST_Context *ctx = cls; | ||
244 | unsigned int i; | ||
245 | |||
246 | if (num_peers != ctx->num_peers) | ||
247 | { | ||
248 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers started %u/%u, ending\n", | ||
249 | num_peers, ctx->num_peers); | ||
250 | exit (1); | ||
251 | } | ||
252 | ctx->peers = peers; | ||
253 | for (i = 0; i < num_peers; i++) | ||
254 | { | ||
255 | struct GNUNET_CADET_TEST_AdapterContext *newctx; | ||
256 | newctx = GNUNET_new (struct GNUNET_CADET_TEST_AdapterContext); | ||
257 | newctx->peer = i; | ||
258 | newctx->ctx = ctx; | ||
259 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connecting to cadet %u\n", i); | ||
260 | ctx->ops[i] = GNUNET_TESTBED_service_connect (ctx, | ||
261 | peers[i], | ||
262 | "cadet", | ||
263 | &cadet_connect_cb, | ||
264 | ctx, | ||
265 | &cadet_connect_adapter, | ||
266 | &cadet_disconnect_adapter, | ||
267 | newctx); | ||
268 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "op handle %p\n", ctx->ops[i]); | ||
269 | } | ||
270 | } | ||
271 | |||
272 | |||
273 | void | ||
274 | GNUNET_CADET_TEST_run (const char *testname, | ||
275 | const char *cfgname, | ||
276 | unsigned int num_peers, | ||
277 | GNUNET_CADET_TEST_AppMain tmain, | ||
278 | void *tmain_cls, | ||
279 | GNUNET_CADET_InboundChannelNotificationHandler new_channel, | ||
280 | GNUNET_CADET_ChannelEndHandler cleaner, | ||
281 | struct GNUNET_CADET_MessageHandler* handlers, | ||
282 | const struct GNUNET_HashCode **ports) | ||
283 | { | ||
284 | struct GNUNET_CADET_TEST_Context *ctx; | ||
285 | |||
286 | ctx = GNUNET_new (struct GNUNET_CADET_TEST_Context); | ||
287 | ctx->num_peers = num_peers; | ||
288 | ctx->ops = GNUNET_malloc (num_peers * sizeof (struct GNUNET_TESTBED_Operation *)); | ||
289 | ctx->cadetes = GNUNET_malloc (num_peers * sizeof (struct GNUNET_CADET_Handle *)); | ||
290 | ctx->app_main = tmain; | ||
291 | ctx->app_main_cls = tmain_cls; | ||
292 | ctx->new_channel = new_channel; | ||
293 | ctx->cleaner = cleaner; | ||
294 | ctx->handlers = handlers; | ||
295 | ctx->ports = ports; | ||
296 | GNUNET_TESTBED_test_run (testname, | ||
297 | cfgname, | ||
298 | num_peers, | ||
299 | 0LL, NULL, NULL, | ||
300 | &cadet_test_run, ctx); | ||
301 | } | ||
302 | |||
303 | /* end of cadet_test_lib.c */ | ||
diff --git a/src/cadet/cadet_test_lib.h b/src/cadet/cadet_test_lib.h deleted file mode 100644 index 464977d42..000000000 --- a/src/cadet/cadet_test_lib.h +++ /dev/null | |||
@@ -1,106 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 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 cadet/cadet_test_lib.h | ||
22 | * @author Bartlomiej Polot | ||
23 | * @brief library for writing CADET tests | ||
24 | */ | ||
25 | #ifndef CADET_TEST_LIB_H | ||
26 | #define CADET_TEST_LIB_H | ||
27 | |||
28 | #ifdef __cplusplus | ||
29 | extern "C" | ||
30 | { | ||
31 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
32 | } | ||
33 | #endif | ||
34 | #endif | ||
35 | |||
36 | #include "gnunet_testbed_service.h" | ||
37 | #include "gnunet_cadet_service.h" | ||
38 | |||
39 | /** | ||
40 | * Test context for a CADET Test. | ||
41 | */ | ||
42 | struct GNUNET_CADET_TEST_Context; | ||
43 | |||
44 | |||
45 | /** | ||
46 | * Main function of a CADET test. | ||
47 | * | ||
48 | * @param cls Closure. | ||
49 | * @param ctx Argument to give to GNUNET_CADET_TEST_cleanup on test end. | ||
50 | * @param num_peers Number of peers that are running. | ||
51 | * @param peers Array of peers. | ||
52 | * @param cadetes Handle to each of the CADETs of the peers. | ||
53 | */ | ||
54 | typedef void (*GNUNET_CADET_TEST_AppMain) (void *cls, | ||
55 | struct GNUNET_CADET_TEST_Context *ctx, | ||
56 | unsigned int num_peers, | ||
57 | struct GNUNET_TESTBED_Peer **peers, | ||
58 | struct GNUNET_CADET_Handle **cadetes); | ||
59 | |||
60 | |||
61 | /** | ||
62 | * Run a test using the given name, configuration file and number of | ||
63 | * peers. | ||
64 | * All cadet callbacks will receive the peer number as the closure. | ||
65 | * | ||
66 | * @param testname Name of the test (for logging). | ||
67 | * @param cfgname Name of the configuration file. | ||
68 | * @param num_peers Number of peers to start. | ||
69 | * @param tmain Main function to run once the testbed is ready. | ||
70 | * @param tmain_cls Closure for 'tmain'. | ||
71 | * @param new_channel Handler for incoming tunnels. | ||
72 | * @param cleaner Cleaner for destroyed incoming tunnels. | ||
73 | * @param handlers Message handlers. | ||
74 | * @param ports Ports the peers offer, NULL-terminated. | ||
75 | */ | ||
76 | void | ||
77 | GNUNET_CADET_TEST_run (const char *testname, | ||
78 | const char *cfgname, | ||
79 | unsigned int num_peers, | ||
80 | GNUNET_CADET_TEST_AppMain tmain, | ||
81 | void *tmain_cls, | ||
82 | GNUNET_CADET_InboundChannelNotificationHandler new_channel, | ||
83 | GNUNET_CADET_ChannelEndHandler cleaner, | ||
84 | struct GNUNET_CADET_MessageHandler* handlers, | ||
85 | const struct GNUNET_HashCode **ports); | ||
86 | |||
87 | |||
88 | /** | ||
89 | * Clean up the testbed. | ||
90 | * | ||
91 | * @param ctx handle for the testbed | ||
92 | */ | ||
93 | void | ||
94 | GNUNET_CADET_TEST_cleanup (struct GNUNET_CADET_TEST_Context *ctx); | ||
95 | |||
96 | |||
97 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
98 | { | ||
99 | #endif | ||
100 | #ifdef __cplusplus | ||
101 | } | ||
102 | #endif | ||
103 | |||
104 | |||
105 | /* ifndef CADET_TEST_LIB_H */ | ||
106 | #endif | ||