diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-10-20 14:10:28 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-10-20 14:10:28 +0000 |
commit | 9aa7853d6c5fa43d0384ae79476bb45242af61fb (patch) | |
tree | 8d81c58b5687bf52b2bf80f0f53826f3a0c5c782 /src/mesh/test_mesh_small.c | |
parent | 85e2435610b558e583f10eb6fe5a8f73d7aab3a7 (diff) | |
download | gnunet-9aa7853d6c5fa43d0384ae79476bb45242af61fb.tar.gz gnunet-9aa7853d6c5fa43d0384ae79476bb45242af61fb.zip |
Changed testcases structure
Diffstat (limited to 'src/mesh/test_mesh_small.c')
-rw-r--r-- | src/mesh/test_mesh_small.c | 510 |
1 files changed, 442 insertions, 68 deletions
diff --git a/src/mesh/test_mesh_small.c b/src/mesh/test_mesh_small.c index a7ea4ee79..9fe2c1292 100644 --- a/src/mesh/test_mesh_small.c +++ b/src/mesh/test_mesh_small.c | |||
@@ -20,7 +20,7 @@ | |||
20 | /** | 20 | /** |
21 | * @file mesh/test_mesh_small.c | 21 | * @file mesh/test_mesh_small.c |
22 | * | 22 | * |
23 | * @brief Test for the mesh service. | 23 | * @brief Test for the mesh service: retransmission of traffic. |
24 | */ | 24 | */ |
25 | #include "platform.h" | 25 | #include "platform.h" |
26 | #include "gnunet_testing_lib.h" | 26 | #include "gnunet_testing_lib.h" |
@@ -47,15 +47,31 @@ struct StatsContext | |||
47 | }; | 47 | }; |
48 | 48 | ||
49 | 49 | ||
50 | // static struct MeshPeer *peer_head; | ||
51 | // | ||
52 | // static struct MeshPeer *peer_tail; | ||
53 | |||
54 | /** | 50 | /** |
55 | * How long until we give up on connecting the peers? | 51 | * How long until we give up on connecting the peers? |
56 | */ | 52 | */ |
57 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1500) | 53 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1500) |
58 | 54 | ||
55 | /** | ||
56 | * Time to wait for stuff that should be rather fast | ||
57 | */ | ||
58 | #define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | ||
59 | |||
60 | /** | ||
61 | * DIFFERENT TESTS TO RUN | ||
62 | */ | ||
63 | #define SETUP 0 | ||
64 | #define UNICAST 1 | ||
65 | #define MULTICAST 2 | ||
66 | |||
67 | /** | ||
68 | * Which test are we running? | ||
69 | */ | ||
70 | static int test; | ||
71 | |||
72 | /** | ||
73 | * How many events have happened | ||
74 | */ | ||
59 | static int ok; | 75 | static int ok; |
60 | 76 | ||
61 | /** | 77 | /** |
@@ -99,11 +115,21 @@ static struct GNUNET_DISK_FileHandle *output_file; | |||
99 | static struct GNUNET_DISK_FileHandle *data_file; | 115 | static struct GNUNET_DISK_FileHandle *data_file; |
100 | 116 | ||
101 | /** | 117 | /** |
118 | * How many data points to capture before triggering next round? | ||
119 | */ | ||
120 | static struct GNUNET_TIME_Relative wait_time; | ||
121 | |||
122 | /** | ||
102 | * Task called to disconnect peers. | 123 | * Task called to disconnect peers. |
103 | */ | 124 | */ |
104 | static GNUNET_SCHEDULER_TaskIdentifier disconnect_task; | 125 | static GNUNET_SCHEDULER_TaskIdentifier disconnect_task; |
105 | 126 | ||
106 | /** | 127 | /** |
128 | * Task To perform tests | ||
129 | */ | ||
130 | static GNUNET_SCHEDULER_TaskIdentifier test_task; | ||
131 | |||
132 | /** | ||
107 | * Task called to shutdown test. | 133 | * Task called to shutdown test. |
108 | */ | 134 | */ |
109 | static GNUNET_SCHEDULER_TaskIdentifier shutdown_handle; | 135 | static GNUNET_SCHEDULER_TaskIdentifier shutdown_handle; |
@@ -112,7 +138,21 @@ static char *topology_file; | |||
112 | 138 | ||
113 | static char *data_filename; | 139 | static char *data_filename; |
114 | 140 | ||
115 | static struct GNUNET_TIME_Relative time_out; | 141 | static struct GNUNET_TESTING_Daemon *d1; |
142 | |||
143 | static GNUNET_PEER_Id pid1; | ||
144 | |||
145 | static struct GNUNET_TESTING_Daemon *d2; | ||
146 | |||
147 | static struct GNUNET_MESH_Handle *h1; | ||
148 | |||
149 | static struct GNUNET_MESH_Handle *h2; | ||
150 | |||
151 | static struct GNUNET_MESH_Tunnel *t; | ||
152 | |||
153 | static struct GNUNET_MESH_Tunnel *incoming_t; | ||
154 | |||
155 | static uint16_t *mesh_peers; | ||
116 | 156 | ||
117 | /** | 157 | /** |
118 | * Check whether peers successfully shut down. | 158 | * Check whether peers successfully shut down. |
@@ -123,17 +163,15 @@ shutdown_callback (void *cls, const char *emsg) | |||
123 | if (emsg != NULL) | 163 | if (emsg != NULL) |
124 | { | 164 | { |
125 | #if VERBOSE | 165 | #if VERBOSE |
126 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n"); | 166 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Shutdown of peers failed!\n"); |
127 | #endif | 167 | #endif |
128 | if (ok == 0) | 168 | ok--; |
129 | ok = 666; | ||
130 | } | 169 | } |
131 | else | 170 | else |
132 | { | 171 | { |
133 | #if VERBOSE | 172 | #if VERBOSE |
134 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers successfully shut down!\n"); | 173 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: All peers successfully shut down!\n"); |
135 | #endif | 174 | #endif |
136 | ok = 0; | ||
137 | } | 175 | } |
138 | } | 176 | } |
139 | 177 | ||
@@ -142,7 +180,7 @@ static void | |||
142 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 180 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
143 | { | 181 | { |
144 | #if VERBOSE | 182 | #if VERBOSE |
145 | fprintf (stderr, "Ending test.\n"); | 183 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Ending test.\n"); |
146 | #endif | 184 | #endif |
147 | 185 | ||
148 | if (disconnect_task != GNUNET_SCHEDULER_NO_TASK) | 186 | if (disconnect_task != GNUNET_SCHEDULER_NO_TASK) |
@@ -150,6 +188,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
150 | GNUNET_SCHEDULER_cancel (disconnect_task); | 188 | GNUNET_SCHEDULER_cancel (disconnect_task); |
151 | disconnect_task = GNUNET_SCHEDULER_NO_TASK; | 189 | disconnect_task = GNUNET_SCHEDULER_NO_TASK; |
152 | } | 190 | } |
191 | |||
153 | if (data_file != NULL) | 192 | if (data_file != NULL) |
154 | GNUNET_DISK_file_close (data_file); | 193 | GNUNET_DISK_file_close (data_file); |
155 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | 194 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
@@ -157,26 +196,132 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
157 | } | 196 | } |
158 | 197 | ||
159 | 198 | ||
199 | static void | ||
200 | disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
201 | { | ||
202 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
203 | "test: disconnecting mesh service of peers\n"); | ||
204 | disconnect_task = GNUNET_SCHEDULER_NO_TASK; | ||
205 | GNUNET_MESH_disconnect(h1); | ||
206 | GNUNET_MESH_disconnect(h2); | ||
207 | GNUNET_SCHEDULER_cancel (shutdown_handle); | ||
208 | shutdown_handle = GNUNET_SCHEDULER_add_now(&shutdown_task, NULL); | ||
209 | } | ||
210 | |||
211 | |||
212 | /** | ||
213 | * Transmit ready callback | ||
214 | */ | ||
215 | size_t | ||
216 | tmt_rdy (void *cls, size_t size, void *buf) | ||
217 | { | ||
218 | struct GNUNET_MessageHeader *msg = buf; | ||
219 | |||
220 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: tmt_rdy called\n"); | ||
221 | if (size < sizeof(struct GNUNET_MessageHeader) || NULL == buf) | ||
222 | return 0; | ||
223 | msg->size = htons (sizeof(struct GNUNET_MessageHeader)); | ||
224 | msg->type = htons ((long) cls); | ||
225 | return sizeof(struct GNUNET_MessageHeader); | ||
226 | } | ||
227 | |||
228 | |||
229 | /** | ||
230 | * Function is called whenever a message is received. | ||
231 | * | ||
232 | * @param cls closure (set from GNUNET_MESH_connect) | ||
233 | * @param tunnel connection to the other end | ||
234 | * @param tunnel_ctx place to store local state associated with the tunnel | ||
235 | * @param sender who sent the message | ||
236 | * @param message the actual message | ||
237 | * @param atsi performance data for the connection | ||
238 | * @return GNUNET_OK to keep the connection open, | ||
239 | * GNUNET_SYSERR to close it (signal serious error) | ||
240 | */ | ||
241 | int | ||
242 | data_callback (void *cls, | ||
243 | struct GNUNET_MESH_Tunnel * tunnel, | ||
244 | void **tunnel_ctx, | ||
245 | const struct GNUNET_PeerIdentity *sender, | ||
246 | const struct GNUNET_MessageHeader *message, | ||
247 | const struct GNUNET_ATS_Information *atsi) | ||
248 | { | ||
249 | long client = (long) cls; | ||
250 | |||
251 | switch (client) | ||
252 | { | ||
253 | case 1L: | ||
254 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
255 | "test: Origin client got a response!\n"); | ||
256 | ok++; | ||
257 | GNUNET_MESH_tunnel_destroy (tunnel); | ||
258 | GNUNET_SCHEDULER_cancel (disconnect_task); | ||
259 | disconnect_task = GNUNET_SCHEDULER_add_delayed(SHORT_TIME, | ||
260 | &disconnect_mesh_peers, | ||
261 | NULL); | ||
262 | break; | ||
263 | case 2L: | ||
264 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
265 | "test: Destination client got a message \n"); | ||
266 | ok++; | ||
267 | GNUNET_MESH_notify_transmit_ready(incoming_t, | ||
268 | GNUNET_NO, | ||
269 | 0, | ||
270 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
271 | sender, | ||
272 | sizeof(struct GNUNET_MessageHeader), | ||
273 | &tmt_rdy, | ||
274 | (void *) 1L); | ||
275 | GNUNET_SCHEDULER_cancel (disconnect_task); | ||
276 | disconnect_task = GNUNET_SCHEDULER_add_delayed(SHORT_TIME, | ||
277 | &disconnect_mesh_peers, | ||
278 | NULL); | ||
279 | break; | ||
280 | default: | ||
281 | break; | ||
282 | } | ||
283 | return GNUNET_OK; | ||
284 | } | ||
285 | |||
286 | |||
160 | /** | 287 | /** |
161 | * Handlers, for diverse services | 288 | * Handlers, for diverse services |
162 | */ | 289 | */ |
163 | static struct GNUNET_MESH_MessageHandler handlers[] = { | 290 | static struct GNUNET_MESH_MessageHandler handlers[] = { |
164 | // {&callback, 1, 0}, | 291 | {&data_callback, 1, sizeof(struct GNUNET_MessageHeader)}, |
165 | {NULL, 0, 0} | 292 | {NULL, 0, 0} |
166 | }; | 293 | }; |
167 | 294 | ||
168 | 295 | ||
169 | static void | 296 | /** |
170 | disconnect_mesh (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 297 | * Method called whenever another peer has added us to a tunnel |
298 | * the other peer initiated. | ||
299 | * | ||
300 | * @param cls closure | ||
301 | * @param tunnel new handle to the tunnel | ||
302 | * @param initiator peer that started the tunnel | ||
303 | * @param atsi performance information for the tunnel | ||
304 | * @return initial tunnel context for the tunnel | ||
305 | * (can be NULL -- that's not an error) | ||
306 | */ | ||
307 | static void * | ||
308 | incoming_tunnel (void *cls, | ||
309 | struct GNUNET_MESH_Tunnel * tunnel, | ||
310 | const struct GNUNET_PeerIdentity * initiator, | ||
311 | const struct GNUNET_ATS_Information * atsi) | ||
171 | { | 312 | { |
172 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 313 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
173 | "test: disconnecting mesh service of peers\n"); | 314 | "test: Incoming tunnel from %s\n", |
174 | disconnect_task = GNUNET_SCHEDULER_NO_TASK; | 315 | GNUNET_i2s(initiator)); |
175 | GNUNET_SCHEDULER_cancel (shutdown_handle); | 316 | ok++; |
176 | shutdown_handle = GNUNET_SCHEDULER_add_now(&shutdown_task, NULL); | 317 | incoming_t = tunnel; |
318 | GNUNET_SCHEDULER_cancel (disconnect_task); | ||
319 | disconnect_task = GNUNET_SCHEDULER_add_delayed(SHORT_TIME, | ||
320 | &disconnect_mesh_peers, | ||
321 | NULL); | ||
322 | return NULL; | ||
177 | } | 323 | } |
178 | 324 | ||
179 | |||
180 | /** | 325 | /** |
181 | * Function called whenever an inbound tunnel is destroyed. Should clean up | 326 | * Function called whenever an inbound tunnel is destroyed. Should clean up |
182 | * any associated state. | 327 | * any associated state. |
@@ -190,12 +335,21 @@ static void | |||
190 | tunnel_cleaner (void *cls, const struct GNUNET_MESH_Tunnel *tunnel, | 335 | tunnel_cleaner (void *cls, const struct GNUNET_MESH_Tunnel *tunnel, |
191 | void *tunnel_ctx) | 336 | void *tunnel_ctx) |
192 | { | 337 | { |
193 | #if VERBOSE | 338 | long i = (long) cls; |
194 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tunnel disconnected\n"); | 339 | |
195 | #endif | 340 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
341 | "test: Incoming tunnel disconnected at peer %d\n", | ||
342 | i); | ||
343 | if (2L == i) | ||
344 | ok++; | ||
345 | |||
346 | GNUNET_SCHEDULER_cancel (disconnect_task); | ||
347 | disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_mesh_peers, NULL); | ||
348 | |||
196 | return; | 349 | return; |
197 | } | 350 | } |
198 | 351 | ||
352 | |||
199 | /** | 353 | /** |
200 | * Method called whenever a tunnel falls apart. | 354 | * Method called whenever a tunnel falls apart. |
201 | * | 355 | * |
@@ -205,13 +359,15 @@ tunnel_cleaner (void *cls, const struct GNUNET_MESH_Tunnel *tunnel, | |||
205 | static void | 359 | static void |
206 | dh (void *cls, const struct GNUNET_PeerIdentity *peer) | 360 | dh (void *cls, const struct GNUNET_PeerIdentity *peer) |
207 | { | 361 | { |
208 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "peer disconnected\n"); | 362 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
363 | "test: peer %s disconnected\n", | ||
364 | GNUNET_i2s(peer)); | ||
209 | return; | 365 | return; |
210 | } | 366 | } |
211 | 367 | ||
212 | 368 | ||
213 | /** | 369 | /** |
214 | * Method called whenever a tunnel is established. | 370 | * Method called whenever a peer connects to a tunnel. |
215 | * | 371 | * |
216 | * @param cls closure | 372 | * @param cls closure |
217 | * @param peer peer identity the tunnel was created to, NULL on timeout | 373 | * @param peer peer identity the tunnel was created to, NULL on timeout |
@@ -221,44 +377,180 @@ static void | |||
221 | ch (void *cls, const struct GNUNET_PeerIdentity *peer, | 377 | ch (void *cls, const struct GNUNET_PeerIdentity *peer, |
222 | const struct GNUNET_ATS_Information *atsi) | 378 | const struct GNUNET_ATS_Information *atsi) |
223 | { | 379 | { |
224 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "peer connected\n"); | 380 | struct GNUNET_PeerIdentity *dest; |
381 | |||
382 | switch (test) | ||
383 | { | ||
384 | case UNICAST: | ||
385 | dest = &d2->id; | ||
386 | break; | ||
387 | case MULTICAST: | ||
388 | dest = NULL; | ||
389 | break; | ||
390 | default: | ||
391 | return; | ||
392 | } | ||
393 | |||
394 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
395 | "test: peer %s connected\n", | ||
396 | GNUNET_i2s(peer)); | ||
397 | if (0 == memcmp(&d2->id, peer, sizeof(d2->id)) && (long) cls == 1L) | ||
398 | ok++; | ||
399 | if (GNUNET_SCHEDULER_NO_TASK != disconnect_task) | ||
400 | { | ||
401 | GNUNET_SCHEDULER_cancel (disconnect_task); | ||
402 | disconnect_task = GNUNET_SCHEDULER_add_delayed(SHORT_TIME, | ||
403 | &disconnect_mesh_peers, | ||
404 | NULL); | ||
405 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Sending data...\n"); | ||
406 | GNUNET_MESH_notify_transmit_ready(t, | ||
407 | GNUNET_NO, | ||
408 | 0, | ||
409 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
410 | dest, | ||
411 | sizeof(struct GNUNET_MessageHeader), | ||
412 | &tmt_rdy, | ||
413 | (void *) 1L); | ||
414 | } | ||
415 | else | ||
416 | { | ||
417 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Disconnect already run?\n"); | ||
418 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Aborting...\n"); | ||
419 | } | ||
225 | return; | 420 | return; |
226 | } | 421 | } |
227 | 422 | ||
228 | 423 | ||
424 | static void | ||
425 | do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
426 | { | ||
427 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: test_task\n"); | ||
428 | GNUNET_MESH_peer_request_connect_add(t, &d2->id); | ||
429 | GNUNET_SCHEDULER_cancel (disconnect_task); | ||
430 | disconnect_task = GNUNET_SCHEDULER_add_delayed( | ||
431 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30), | ||
432 | &disconnect_mesh_peers, NULL); | ||
433 | } | ||
434 | |||
435 | |||
436 | /** | ||
437 | * Prototype of a callback function indicating that two peers | ||
438 | * are currently connected. | ||
439 | * | ||
440 | * @param cls closure | ||
441 | * @param first peer id for first daemon | ||
442 | * @param second peer id for the second daemon | ||
443 | * @param distance distance between the connected peers | ||
444 | * @param emsg error message (NULL on success) | ||
445 | */ | ||
446 | void | ||
447 | topo_cb (void *cls, | ||
448 | const struct GNUNET_PeerIdentity* first, | ||
449 | const struct GNUNET_PeerIdentity* second, | ||
450 | const char *emsg) | ||
451 | { | ||
452 | GNUNET_PEER_Id p1; | ||
453 | GNUNET_PEER_Id p2; | ||
454 | struct GNUNET_PeerIdentity id; | ||
455 | |||
456 | GNUNET_PEER_resolve(1, &id); | ||
457 | p1 = GNUNET_PEER_search(first); | ||
458 | if (p1 == pid1) | ||
459 | { | ||
460 | p2 = GNUNET_PEER_search(second); | ||
461 | GNUNET_assert(p2 < num_peers); | ||
462 | GNUNET_assert(p2 > 0); | ||
463 | mesh_peers[p2]++; | ||
464 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
465 | "test: %s IS a neighbor\n", | ||
466 | GNUNET_i2s(second)); | ||
467 | return; | ||
468 | } | ||
469 | p1 = GNUNET_PEER_search(second); | ||
470 | if (p1 == pid1) | ||
471 | { | ||
472 | p2 = GNUNET_PEER_search(first); | ||
473 | GNUNET_assert(p2 < num_peers); | ||
474 | GNUNET_assert(p2 > 0); | ||
475 | mesh_peers[p2]++; | ||
476 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
477 | "test: %s IS a neighbor\n", | ||
478 | GNUNET_i2s(first)); | ||
479 | return; | ||
480 | } | ||
481 | } | ||
482 | |||
229 | /** | 483 | /** |
230 | * connect_mesh_service: connect to the mesh service of one of the peers | 484 | * connect_mesh_service: connect to the mesh service of one of the peers |
231 | * | 485 | * |
232 | */ | 486 | */ |
233 | static void | 487 | static void |
234 | connect_mesh (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 488 | connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
235 | { | 489 | { |
236 | struct GNUNET_TESTING_Daemon *d; | ||
237 | struct GNUNET_MESH_Handle *h; | ||
238 | struct GNUNET_MESH_Tunnel *t; | ||
239 | GNUNET_MESH_ApplicationType app; | 490 | GNUNET_MESH_ApplicationType app; |
491 | unsigned int i; | ||
492 | struct GNUNET_PeerIdentity id; | ||
240 | 493 | ||
241 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connect_mesh_service\n"); | 494 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: connect_mesh_service\n"); |
242 | 495 | ||
243 | d = GNUNET_TESTING_daemon_get (pg, 1); | 496 | for (i = 1; i <= num_peers; i++) |
497 | { | ||
498 | GNUNET_PEER_resolve(i, &id); | ||
499 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
500 | "test: peer %s has %u conns to d1\n", | ||
501 | GNUNET_i2s (&id), | ||
502 | mesh_peers[i]); | ||
503 | if (mesh_peers[i] == 0) | ||
504 | break; | ||
505 | } | ||
506 | GNUNET_assert (i < num_peers); | ||
507 | d2 = GNUNET_TESTING_daemon_get_by_id (pg, &id); | ||
508 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
509 | "test: Peer searched: %s\n", | ||
510 | GNUNET_i2s (&d2->id)); | ||
244 | app = (GNUNET_MESH_ApplicationType) 0; | 511 | app = (GNUNET_MESH_ApplicationType) 0; |
245 | 512 | ||
246 | #if VERBOSE | 513 | #if VERBOSE |
247 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 514 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
248 | "connecting to mesh service of peer %s\n", GNUNET_i2s (&d->id)); | 515 | "test: connecting to mesh service of peer %s (%u)\n", |
516 | GNUNET_i2s (&d1->id), | ||
517 | mesh_peers[0]); | ||
518 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
519 | "test: connecting to mesh service of peer %s (%u)\n", | ||
520 | GNUNET_i2s (&d2->id), | ||
521 | i); | ||
249 | #endif | 522 | #endif |
250 | h = GNUNET_MESH_connect (d->cfg, 10, NULL, NULL, &tunnel_cleaner, handlers, | 523 | h1 = GNUNET_MESH_connect (d1->cfg, |
251 | &app); | 524 | 10, |
525 | (void *) 1L, | ||
526 | NULL, | ||
527 | &tunnel_cleaner, | ||
528 | handlers, | ||
529 | &app); | ||
530 | h2 = GNUNET_MESH_connect (d2->cfg, | ||
531 | 10, | ||
532 | (void *) 2L, | ||
533 | &incoming_tunnel, | ||
534 | &tunnel_cleaner, | ||
535 | handlers, | ||
536 | &app); | ||
252 | #if VERBOSE | 537 | #if VERBOSE |
253 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected to mesh service of peer %s\n", | 538 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
254 | GNUNET_i2s (&d->id)); | 539 | "test: connected to mesh service of peer %s\n", |
540 | GNUNET_i2s (&d1->id)); | ||
541 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
542 | "test: connected to mesh service of peer %s\n", | ||
543 | GNUNET_i2s (&d2->id)); | ||
255 | #endif | 544 | #endif |
256 | t = GNUNET_MESH_tunnel_create (h, NULL, &ch, &dh, NULL); | 545 | t = GNUNET_MESH_tunnel_create (h1, NULL, &ch, &dh, (void *) 1L); |
257 | GNUNET_MESH_tunnel_destroy (t); | 546 | test_task = |
258 | GNUNET_MESH_disconnect (h); | 547 | GNUNET_SCHEDULER_add_delayed( |
548 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 6), | ||
549 | &do_test, NULL); | ||
259 | } | 550 | } |
260 | 551 | ||
261 | 552 | ||
553 | |||
262 | /** | 554 | /** |
263 | * peergroup_ready: start test when all peers are connected | 555 | * peergroup_ready: start test when all peers are connected |
264 | * @param cls closure | 556 | * @param cls closure |
@@ -269,22 +561,28 @@ peergroup_ready (void *cls, const char *emsg) | |||
269 | { | 561 | { |
270 | char *buf; | 562 | char *buf; |
271 | int buf_len; | 563 | int buf_len; |
564 | unsigned int i; | ||
272 | 565 | ||
273 | if (emsg != NULL) | 566 | if (emsg != NULL) |
274 | { | 567 | { |
275 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 568 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
276 | "Peergroup callback called with error, aborting test!\n"); | 569 | "test: Peergroup callback called with error, aborting test!\n"); |
277 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n"); | 570 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
278 | ok = 1; | 571 | "test: Error from testing: `%s'\n", emsg); |
572 | ok--; | ||
279 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | 573 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
280 | return; | 574 | return; |
281 | } | 575 | } |
282 | #if VERBOSE | 576 | #if VERBOSE |
283 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer Group started successfully!\n"); | 577 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
578 | "************************************************************\n"); | ||
579 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
580 | "test: Peer Group started successfully!\n"); | ||
581 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
582 | "test: Have %u connections\n", | ||
583 | total_connections); | ||
284 | #endif | 584 | #endif |
285 | 585 | ||
286 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Have %u connections\n", | ||
287 | total_connections); | ||
288 | if (data_file != NULL) | 586 | if (data_file != NULL) |
289 | { | 587 | { |
290 | buf = NULL; | 588 | buf = NULL; |
@@ -294,10 +592,29 @@ peergroup_ready (void *cls, const char *emsg) | |||
294 | GNUNET_free (buf); | 592 | GNUNET_free (buf); |
295 | } | 593 | } |
296 | peers_running = GNUNET_TESTING_daemons_running (pg); | 594 | peers_running = GNUNET_TESTING_daemons_running (pg); |
297 | 595 | for (i = 0; i < num_peers; i++) | |
298 | GNUNET_SCHEDULER_add_now (&connect_mesh, NULL); | 596 | { |
597 | d1 = GNUNET_TESTING_daemon_get (pg, i); | ||
598 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
599 | "test: %u: %s\n", | ||
600 | GNUNET_PEER_intern(&d1->id), | ||
601 | GNUNET_i2s (&d1->id)); | ||
602 | } | ||
603 | d1 = GNUNET_TESTING_daemon_get (pg, 0); | ||
604 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
605 | "test: Peer looking: %s\n", | ||
606 | GNUNET_i2s (&d1->id)); | ||
607 | pid1 = GNUNET_PEER_intern(&d1->id); | ||
608 | mesh_peers[pid1] = 100; | ||
609 | GNUNET_TESTING_get_topology(pg, &topo_cb, NULL); | ||
610 | |||
611 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply( | ||
612 | GNUNET_TIME_UNIT_SECONDS, | ||
613 | 4), | ||
614 | &connect_mesh_service, | ||
615 | NULL); | ||
299 | disconnect_task = | 616 | disconnect_task = |
300 | GNUNET_SCHEDULER_add_delayed (time_out, &disconnect_mesh, NULL); | 617 | GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL); |
301 | 618 | ||
302 | } | 619 | } |
303 | 620 | ||
@@ -325,7 +642,16 @@ connect_cb (void *cls, const struct GNUNET_PeerIdentity *first, | |||
325 | struct GNUNET_TESTING_Daemon *second_daemon, const char *emsg) | 642 | struct GNUNET_TESTING_Daemon *second_daemon, const char *emsg) |
326 | { | 643 | { |
327 | if (emsg == NULL) | 644 | if (emsg == NULL) |
645 | { | ||
328 | total_connections++; | 646 | total_connections++; |
647 | } | ||
648 | else | ||
649 | { | ||
650 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
651 | "test: Problem with new connection (%s)\n", | ||
652 | emsg); | ||
653 | } | ||
654 | |||
329 | } | 655 | } |
330 | 656 | ||
331 | 657 | ||
@@ -341,9 +667,10 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
341 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 667 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
342 | { | 668 | { |
343 | char *temp_str; | 669 | char *temp_str; |
670 | unsigned long long temp_wait; | ||
344 | struct GNUNET_TESTING_Host *hosts; | 671 | struct GNUNET_TESTING_Host *hosts; |
345 | 672 | ||
346 | ok = 1; | 673 | ok = 0; |
347 | testing_cfg = GNUNET_CONFIGURATION_dup (cfg); | 674 | testing_cfg = GNUNET_CONFIGURATION_dup (cfg); |
348 | 675 | ||
349 | GNUNET_log_setup ("test_mesh_small", | 676 | GNUNET_log_setup ("test_mesh_small", |
@@ -355,28 +682,29 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
355 | NULL); | 682 | NULL); |
356 | 683 | ||
357 | #if VERBOSE | 684 | #if VERBOSE |
358 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n"); | 685 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Starting daemons.\n"); |
359 | GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing", | 686 | GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing", |
360 | "use_progressbars", "YES"); | 687 | "use_progressbars", "YES"); |
361 | #endif | 688 | #endif |
362 | 689 | ||
363 | time_out = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30); | ||
364 | |||
365 | if (GNUNET_OK != | 690 | if (GNUNET_OK != |
366 | GNUNET_CONFIGURATION_get_value_number (testing_cfg, "testing", | 691 | GNUNET_CONFIGURATION_get_value_number (testing_cfg, "testing", |
367 | "num_peers", &num_peers)) | 692 | "num_peers", &num_peers)) |
368 | { | 693 | { |
369 | GNUNET_assert (GNUNET_OK == | 694 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
370 | GNUNET_CONFIGURATION_load (testing_cfg, | 695 | "Option TESTING:NUM_PEERS is required!\n"); |
371 | "test_mesh_small.conf")); | 696 | return; |
372 | if (GNUNET_OK != | 697 | } |
373 | GNUNET_CONFIGURATION_get_value_number (testing_cfg, "testing", | 698 | |
374 | "num_peers", &num_peers)) | 699 | mesh_peers = GNUNET_malloc (sizeof(GNUNET_PEER_Id) * (num_peers + 1)); |
375 | { | 700 | |
376 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 701 | if (GNUNET_OK != |
377 | "Option TESTING:NUM_PEERS is required!\n"); | 702 | GNUNET_CONFIGURATION_get_value_number (testing_cfg, "test_mesh_small", |
378 | return; | 703 | "wait_time", &temp_wait)) |
379 | } | 704 | { |
705 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
706 | "Option test_mesh_small:wait_time is required!\n"); | ||
707 | return; | ||
380 | } | 708 | } |
381 | 709 | ||
382 | if (GNUNET_OK != | 710 | if (GNUNET_OK != |
@@ -412,6 +740,9 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
412 | GNUNET_free (data_filename); | 740 | GNUNET_free (data_filename); |
413 | } | 741 | } |
414 | 742 | ||
743 | wait_time = | ||
744 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_wait); | ||
745 | |||
415 | if (GNUNET_YES == | 746 | if (GNUNET_YES == |
416 | GNUNET_CONFIGURATION_get_value_string (cfg, "test_mesh_small", | 747 | GNUNET_CONFIGURATION_get_value_string (cfg, "test_mesh_small", |
417 | "output_file", &temp_str)) | 748 | "output_file", &temp_str)) |
@@ -458,13 +789,56 @@ static struct GNUNET_GETOPT_CommandLineOption options[] = { | |||
458 | int | 789 | int |
459 | main (int argc, char *argv[]) | 790 | main (int argc, char *argv[]) |
460 | { | 791 | { |
461 | GNUNET_PROGRAM_run (argc, argv, "test_mesh_small", | 792 | char *const argv2[] = { |
462 | gettext_noop ("Test mesh in a small network."), options, | 793 | argv[0], |
463 | &run, NULL); | 794 | "-c", |
795 | "test_mesh_small.conf", | ||
796 | #if VERBOSE | ||
797 | "-L", | ||
798 | "DEBUG", | ||
799 | #endif | ||
800 | NULL | ||
801 | }; | ||
802 | int ok_goal; | ||
803 | |||
804 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Start\n"); | ||
805 | if (strstr (argv[0], "test_mesh_small_unicast") != NULL) | ||
806 | { | ||
807 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: UNICAST\n"); | ||
808 | test = UNICAST; | ||
809 | ok_goal = 5; | ||
810 | } | ||
811 | else if (strstr (argv[0], "test_mesh_small_multicast") != NULL) | ||
812 | { | ||
813 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: MULTICAST\n"); | ||
814 | test = MULTICAST; | ||
815 | ok_goal = 5; | ||
816 | } | ||
817 | else | ||
818 | { | ||
819 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: UNKNOWN\n"); | ||
820 | test = SETUP; | ||
821 | ok_goal = 0; | ||
822 | } | ||
823 | |||
824 | GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, | ||
825 | "test_mesh_small", | ||
826 | gettext_noop ("Test mesh in a small network."), | ||
827 | options, &run, NULL); | ||
464 | #if REMOVE_DIR | 828 | #if REMOVE_DIR |
465 | GNUNET_DISK_directory_remove ("/tmp/test_mesh_small"); | 829 | GNUNET_DISK_directory_remove ("/tmp/test_mesh_small"); |
466 | #endif | 830 | #endif |
467 | return ok; | 831 | if (ok_goal != ok) |
832 | { | ||
833 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
834 | "test: %s FAILED! (%d/%d)\n", | ||
835 | argv[0], ok, ok_goal); | ||
836 | return 1; | ||
837 | } | ||
838 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
839 | "test: %s success\n", | ||
840 | argv[0]); | ||
841 | return 0; | ||
468 | } | 842 | } |
469 | 843 | ||
470 | /* end of test_mesh_small.c */ | 844 | /* end of test_mesh_small.c */ |