From 232537fa5ddfbd27eaa426f7bf7e1279a27f56ab Mon Sep 17 00:00:00 2001 From: "Nathan S. Evans" Date: Thu, 24 Jun 2010 11:44:36 +0000 Subject: [PATCH] test case error handling --- src/dv/plugin_transport_dv.c | 2 - src/dv/test_transport_api_dv.c | 130 +++++++++++++++++---------------- 2 files changed, 67 insertions(+), 65 deletions(-) diff --git a/src/dv/plugin_transport_dv.c b/src/dv/plugin_transport_dv.c index 30e5b6ac1..38826e47f 100644 --- a/src/dv/plugin_transport_dv.c +++ b/src/dv/plugin_transport_dv.c @@ -383,8 +383,6 @@ libgnunet_plugin_transport_dv_init (void *cls) plugin = GNUNET_malloc (sizeof (struct Plugin)); plugin->env = env; - //plugin->service = service; - //plugin->server = GNUNET_SERVICE_get_server (service); plugin->dv_handle = GNUNET_DV_connect(env->sched, env->cfg, &handle_dv_message_received, plugin); 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 @@ -281,69 +281,6 @@ disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) total_server_connections -= 2; } -static void -send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc); - -static int -process_mtype (void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_MessageHeader *message, - struct GNUNET_TIME_Relative latency, - uint32_t distance) -{ - struct TestMessageContext *pos = cls; - struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *)message; - if (pos->uid != ntohl(msg->uid)) - return GNUNET_OK; - - GNUNET_assert(0 == memcmp(peer, &pos->peer1->id, sizeof(struct GNUNET_PeerIdentity))); - if (total_other_expected_messages == 0) - { - total_messages_received++; -#if VERBOSE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received message from `%4s', type %d, uid %u, distance %u.\n", GNUNET_i2s (peer), ntohs(message->type), ntohl(msg->uid), distance); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Total messages received %d, expected %d.\n", total_messages_received, expected_messages); -#endif - } - else - { - total_other_messages++; -#if VERBOSE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received message from `%4s', type %d, uid %u, distance %u.\n", GNUNET_i2s (peer), ntohs(message->type), ntohl(msg->uid), distance); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Total messages received %d, expected %d.\n", total_other_messages, total_other_expected_messages); -#endif - } - - if ((total_messages_received == expected_messages) && (total_other_messages == 0)) - { - GNUNET_SCHEDULER_cancel (sched, die_task); - /* - if ((num_peers == 3) && (total_other_expected_messages == 2)) - { - GNUNET_SCHEDULER_add_now (sched, &send_other_messages, NULL); - } - else - { - GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20), &send_other_messages, NULL); - }*/ - } - else if ((total_other_expected_messages > 0) && (total_other_messages == total_other_expected_messages)) - { - GNUNET_SCHEDULER_cancel (sched, die_task); - GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL); - } - else - { - pos->disconnect_task = GNUNET_SCHEDULER_add_now(sched, &disconnect_cores, pos); - } - - return GNUNET_OK; -} - static void end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) { @@ -421,6 +358,72 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) } } +static void +send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc); + +static int +process_mtype (void *cls, + const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_MessageHeader *message, + struct GNUNET_TIME_Relative latency, + uint32_t distance) +{ + struct TestMessageContext *pos = cls; + struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *)message; + if (pos->uid != ntohl(msg->uid)) + return GNUNET_OK; + + GNUNET_assert(0 == memcmp(peer, &pos->peer1->id, sizeof(struct GNUNET_PeerIdentity))); + if (total_other_expected_messages == 0) + { + total_messages_received++; +#if VERBOSE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received message from `%4s', type %d, uid %u, distance %u.\n", GNUNET_i2s (peer), ntohs(message->type), ntohl(msg->uid), distance); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Total messages received %d, expected %d.\n", total_messages_received, expected_messages); +#endif + } + else + { + total_other_messages++; +#if VERBOSE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received message from `%4s', type %d, uid %u, distance %u.\n", GNUNET_i2s (peer), ntohs(message->type), ntohl(msg->uid), distance); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Total messages received %d, expected %d.\n", total_other_messages, total_other_expected_messages); +#endif + } + + if ((total_messages_received == expected_messages) && (total_other_messages == 0)) + { + GNUNET_SCHEDULER_cancel (sched, die_task); + die_task = GNUNET_SCHEDULER_add_delayed (sched, + TEST_TIMEOUT, + &end_badly, "waiting for DV peers to connect!"); + /* + if ((num_peers == 3) && (total_other_expected_messages == 2)) + { + GNUNET_SCHEDULER_add_now (sched, &send_other_messages, NULL); + } + else + { + GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20), &send_other_messages, NULL); + }*/ + } + else if ((total_other_expected_messages > 0) && (total_other_messages == total_other_expected_messages)) + { + GNUNET_SCHEDULER_cancel (sched, die_task); + GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL); + } + else + { + pos->disconnect_task = GNUNET_SCHEDULER_add_now(sched, &disconnect_cores, pos); + } + + return GNUNET_OK; +} + static size_t transmit_ready (void *cls, size_t size, void *buf) { @@ -639,6 +642,7 @@ send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) #endif GNUNET_SCHEDULER_add_now (sched, &send_test_messages, other_test_messages); + GNUNET_SCHEDULER_cancel(sched, die_task); die_task = GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 250), &end_badly, "from send_other_messages"); } -- 2.25.1