diff options
author | Nathan S. Evans <evans@in.tum.de> | 2010-06-24 11:44:36 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2010-06-24 11:44:36 +0000 |
commit | 232537fa5ddfbd27eaa426f7bf7e1279a27f56ab (patch) | |
tree | 18e2cf9e68b5db5531bc4cef132a8bbe6fb205d9 /src/dv/test_transport_api_dv.c | |
parent | 3c7ca71dcb7c0eec5bd47cc98f4b8497991f525d (diff) | |
download | gnunet-232537fa5ddfbd27eaa426f7bf7e1279a27f56ab.tar.gz gnunet-232537fa5ddfbd27eaa426f7bf7e1279a27f56ab.zip |
test case error handling
Diffstat (limited to 'src/dv/test_transport_api_dv.c')
-rw-r--r-- | src/dv/test_transport_api_dv.c | 130 |
1 files changed, 67 insertions, 63 deletions
diff --git a/src/dv/test_transport_api_dv.c b/src/dv/test_transport_api_dv.c index faf279066..706407f15 100644 --- a/src/dv/test_transport_api_dv.c +++ b/src/dv/test_transport_api_dv.c | |||
@@ -282,69 +282,6 @@ disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
282 | } | 282 | } |
283 | 283 | ||
284 | static void | 284 | static void |
285 | send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc); | ||
286 | |||
287 | static int | ||
288 | process_mtype (void *cls, | ||
289 | const struct GNUNET_PeerIdentity *peer, | ||
290 | const struct GNUNET_MessageHeader *message, | ||
291 | struct GNUNET_TIME_Relative latency, | ||
292 | uint32_t distance) | ||
293 | { | ||
294 | struct TestMessageContext *pos = cls; | ||
295 | struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *)message; | ||
296 | if (pos->uid != ntohl(msg->uid)) | ||
297 | return GNUNET_OK; | ||
298 | |||
299 | GNUNET_assert(0 == memcmp(peer, &pos->peer1->id, sizeof(struct GNUNET_PeerIdentity))); | ||
300 | if (total_other_expected_messages == 0) | ||
301 | { | ||
302 | total_messages_received++; | ||
303 | #if VERBOSE | ||
304 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
305 | "Received message from `%4s', type %d, uid %u, distance %u.\n", GNUNET_i2s (peer), ntohs(message->type), ntohl(msg->uid), distance); | ||
306 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
307 | "Total messages received %d, expected %d.\n", total_messages_received, expected_messages); | ||
308 | #endif | ||
309 | } | ||
310 | else | ||
311 | { | ||
312 | total_other_messages++; | ||
313 | #if VERBOSE | ||
314 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
315 | "Received message from `%4s', type %d, uid %u, distance %u.\n", GNUNET_i2s (peer), ntohs(message->type), ntohl(msg->uid), distance); | ||
316 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
317 | "Total messages received %d, expected %d.\n", total_other_messages, total_other_expected_messages); | ||
318 | #endif | ||
319 | } | ||
320 | |||
321 | if ((total_messages_received == expected_messages) && (total_other_messages == 0)) | ||
322 | { | ||
323 | GNUNET_SCHEDULER_cancel (sched, die_task); | ||
324 | /* | ||
325 | if ((num_peers == 3) && (total_other_expected_messages == 2)) | ||
326 | { | ||
327 | GNUNET_SCHEDULER_add_now (sched, &send_other_messages, NULL); | ||
328 | } | ||
329 | else | ||
330 | { | ||
331 | GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20), &send_other_messages, NULL); | ||
332 | }*/ | ||
333 | } | ||
334 | else if ((total_other_expected_messages > 0) && (total_other_messages == total_other_expected_messages)) | ||
335 | { | ||
336 | GNUNET_SCHEDULER_cancel (sched, die_task); | ||
337 | GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL); | ||
338 | } | ||
339 | else | ||
340 | { | ||
341 | pos->disconnect_task = GNUNET_SCHEDULER_add_now(sched, &disconnect_cores, pos); | ||
342 | } | ||
343 | |||
344 | return GNUNET_OK; | ||
345 | } | ||
346 | |||
347 | static void | ||
348 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | 285 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) |
349 | { | 286 | { |
350 | char *msg = cls; | 287 | char *msg = cls; |
@@ -421,6 +358,72 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
421 | } | 358 | } |
422 | } | 359 | } |
423 | 360 | ||
361 | static void | ||
362 | send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc); | ||
363 | |||
364 | static int | ||
365 | process_mtype (void *cls, | ||
366 | const struct GNUNET_PeerIdentity *peer, | ||
367 | const struct GNUNET_MessageHeader *message, | ||
368 | struct GNUNET_TIME_Relative latency, | ||
369 | uint32_t distance) | ||
370 | { | ||
371 | struct TestMessageContext *pos = cls; | ||
372 | struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *)message; | ||
373 | if (pos->uid != ntohl(msg->uid)) | ||
374 | return GNUNET_OK; | ||
375 | |||
376 | GNUNET_assert(0 == memcmp(peer, &pos->peer1->id, sizeof(struct GNUNET_PeerIdentity))); | ||
377 | if (total_other_expected_messages == 0) | ||
378 | { | ||
379 | total_messages_received++; | ||
380 | #if VERBOSE | ||
381 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
382 | "Received message from `%4s', type %d, uid %u, distance %u.\n", GNUNET_i2s (peer), ntohs(message->type), ntohl(msg->uid), distance); | ||
383 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
384 | "Total messages received %d, expected %d.\n", total_messages_received, expected_messages); | ||
385 | #endif | ||
386 | } | ||
387 | else | ||
388 | { | ||
389 | total_other_messages++; | ||
390 | #if VERBOSE | ||
391 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
392 | "Received message from `%4s', type %d, uid %u, distance %u.\n", GNUNET_i2s (peer), ntohs(message->type), ntohl(msg->uid), distance); | ||
393 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
394 | "Total messages received %d, expected %d.\n", total_other_messages, total_other_expected_messages); | ||
395 | #endif | ||
396 | } | ||
397 | |||
398 | if ((total_messages_received == expected_messages) && (total_other_messages == 0)) | ||
399 | { | ||
400 | GNUNET_SCHEDULER_cancel (sched, die_task); | ||
401 | die_task = GNUNET_SCHEDULER_add_delayed (sched, | ||
402 | TEST_TIMEOUT, | ||
403 | &end_badly, "waiting for DV peers to connect!"); | ||
404 | /* | ||
405 | if ((num_peers == 3) && (total_other_expected_messages == 2)) | ||
406 | { | ||
407 | GNUNET_SCHEDULER_add_now (sched, &send_other_messages, NULL); | ||
408 | } | ||
409 | else | ||
410 | { | ||
411 | GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20), &send_other_messages, NULL); | ||
412 | }*/ | ||
413 | } | ||
414 | else if ((total_other_expected_messages > 0) && (total_other_messages == total_other_expected_messages)) | ||
415 | { | ||
416 | GNUNET_SCHEDULER_cancel (sched, die_task); | ||
417 | GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL); | ||
418 | } | ||
419 | else | ||
420 | { | ||
421 | pos->disconnect_task = GNUNET_SCHEDULER_add_now(sched, &disconnect_cores, pos); | ||
422 | } | ||
423 | |||
424 | return GNUNET_OK; | ||
425 | } | ||
426 | |||
424 | static size_t | 427 | static size_t |
425 | transmit_ready (void *cls, size_t size, void *buf) | 428 | transmit_ready (void *cls, size_t size, void *buf) |
426 | { | 429 | { |
@@ -639,6 +642,7 @@ send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
639 | #endif | 642 | #endif |
640 | 643 | ||
641 | GNUNET_SCHEDULER_add_now (sched, &send_test_messages, other_test_messages); | 644 | GNUNET_SCHEDULER_add_now (sched, &send_test_messages, other_test_messages); |
645 | GNUNET_SCHEDULER_cancel(sched, die_task); | ||
642 | die_task = GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 250), &end_badly, "from send_other_messages"); | 646 | die_task = GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 250), &end_badly, "from send_other_messages"); |
643 | } | 647 | } |
644 | 648 | ||