aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing.c
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-04-27 15:32:55 +0000
committerNathan S. Evans <evans@in.tum.de>2010-04-27 15:32:55 +0000
commit7346e9edb1c5d68312a76ae10a38d360beaa39b5 (patch)
treec545520152b6507a471a371bdcdaf6a15ccefcd1 /src/testing/testing.c
parentc457e0af785fbb91c06869ac789ae39e5cfda7c3 (diff)
downloadgnunet-7346e9edb1c5d68312a76ae10a38d360beaa39b5.tar.gz
gnunet-7346e9edb1c5d68312a76ae10a38d360beaa39b5.zip
testing bug fixes (hopefully)
Diffstat (limited to 'src/testing/testing.c')
-rw-r--r--src/testing/testing.c63
1 files changed, 43 insertions, 20 deletions
diff --git a/src/testing/testing.c b/src/testing/testing.c
index 1df3ad68c..fcc8c9767 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -38,6 +38,7 @@
38#include "gnunet_hello_lib.h" 38#include "gnunet_hello_lib.h"
39 39
40#define DEBUG_TESTING GNUNET_NO 40#define DEBUG_TESTING GNUNET_NO
41#define DEBUG_TESTING_RECONNECT GNUNET_YES
41 42
42/** 43/**
43 * How long do we wait after starting gnunet-service-arm 44 * How long do we wait after starting gnunet-service-arm
@@ -64,14 +65,26 @@ static void
64process_hello (void *cls, const struct GNUNET_MessageHeader *message) 65process_hello (void *cls, const struct GNUNET_MessageHeader *message)
65{ 66{
66 struct GNUNET_TESTING_Daemon *daemon = cls; 67 struct GNUNET_TESTING_Daemon *daemon = cls;
67 GNUNET_TRANSPORT_get_hello_cancel(daemon->th, &process_hello, daemon); 68 if (daemon == NULL)
69 return;
70
71 if (daemon->server != NULL)
72 {
73 GNUNET_CORE_disconnect(daemon->server);
74 daemon->server = NULL;
75 }
76
77 GNUNET_assert (message != NULL);
78 if (daemon->th != NULL)
79 {
80 GNUNET_TRANSPORT_get_hello_cancel(daemon->th, &process_hello, daemon);
81 }
68#if DEBUG_TESTING 82#if DEBUG_TESTING
69 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 83 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
70 "Received `%s' from transport service of `%4s'\n", 84 "Received `%s' from transport service of `%4s'\n",
71 "HELLO", GNUNET_i2s (&daemon->id)); 85 "HELLO", GNUNET_i2s (&daemon->id));
72#endif 86#endif
73 87
74 GNUNET_assert (message != NULL);
75 GNUNET_free_non_null(daemon->hello); 88 GNUNET_free_non_null(daemon->hello);
76 daemon->hello = GNUNET_malloc(ntohs(message->size)); 89 daemon->hello = GNUNET_malloc(ntohs(message->size));
77 memcpy(daemon->hello, message, ntohs(message->size)); 90 memcpy(daemon->hello, message, ntohs(message->size));
@@ -126,6 +139,7 @@ testing_init (void *cls,
126 d->id = *my_identity; 139 d->id = *my_identity;
127 d->shortname = strdup (GNUNET_i2s (my_identity)); 140 d->shortname = strdup (GNUNET_i2s (my_identity));
128 d->server = server; 141 d->server = server;
142 d->running = GNUNET_YES;
129 if (GNUNET_YES == d->dead) 143 if (GNUNET_YES == d->dead)
130 GNUNET_TESTING_daemon_stop (d, d->dead_cb, d->dead_cb_cls); 144 GNUNET_TESTING_daemon_stop (d, d->dead_cb, d->dead_cb_cls);
131 else if (NULL != cb) 145 else if (NULL != cb)
@@ -344,6 +358,7 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
344 } 358 }
345 GNUNET_CONFIGURATION_destroy (d->cfg); 359 GNUNET_CONFIGURATION_destroy (d->cfg);
346 GNUNET_free (d->cfgfile); 360 GNUNET_free (d->cfgfile);
361 GNUNET_free_non_null(d->hello);
347 GNUNET_free_non_null (d->hostname); 362 GNUNET_free_non_null (d->hostname);
348 GNUNET_free_non_null (d->username); 363 GNUNET_free_non_null (d->username);
349 GNUNET_free_non_null (d->shortname); 364 GNUNET_free_non_null (d->shortname);
@@ -370,6 +385,7 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
370 } 385 }
371 GNUNET_CONFIGURATION_destroy (d->cfg); 386 GNUNET_CONFIGURATION_destroy (d->cfg);
372 GNUNET_free (d->cfgfile); 387 GNUNET_free (d->cfgfile);
388 GNUNET_free_non_null(d->hello);
373 GNUNET_free_non_null (d->hostname); 389 GNUNET_free_non_null (d->hostname);
374 GNUNET_free_non_null (d->username); 390 GNUNET_free_non_null (d->username);
375 GNUNET_free_non_null (d->shortname); 391 GNUNET_free_non_null (d->shortname);
@@ -388,6 +404,7 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
388 /* state clean up and notifications */ 404 /* state clean up and notifications */
389 GNUNET_CONFIGURATION_destroy (d->cfg); 405 GNUNET_CONFIGURATION_destroy (d->cfg);
390 GNUNET_free (d->cfgfile); 406 GNUNET_free (d->cfgfile);
407 GNUNET_free_non_null(d->hello);
391 GNUNET_free_non_null (d->hostname); 408 GNUNET_free_non_null (d->hostname);
392 GNUNET_free_non_null (d->username); 409 GNUNET_free_non_null (d->username);
393 GNUNET_free_non_null (d->shortname); 410 GNUNET_free_non_null (d->shortname);
@@ -633,14 +650,11 @@ GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
633 "-c", d->cfgfile, "-e", "-d", "-q", NULL); 650 "-c", d->cfgfile, "-e", "-d", "-q", NULL);
634 } 651 }
635 652
636 GNUNET_free_non_null(d->hello);
637
638 d->wait_runs = 0; 653 d->wait_runs = 0;
639 d->task 654 d->task
640 = GNUNET_SCHEDULER_add_delayed (d->sched, 655 = GNUNET_SCHEDULER_add_delayed (d->sched,
641 GNUNET_CONSTANTS_EXEC_WAIT, 656 GNUNET_CONSTANTS_EXEC_WAIT,
642 &start_fsm, d); 657 &start_fsm, d);
643 return;
644} 658}
645 659
646 660
@@ -820,6 +834,12 @@ notify_connect_result (void *cls,
820 ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK; 834 ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK;
821 } 835 }
822 836
837 if ((ctx->timeout_task != GNUNET_SCHEDULER_NO_TASK) && (tc->reason != GNUNET_SCHEDULER_REASON_TIMEOUT))
838 {
839 GNUNET_SCHEDULER_cancel(ctx->d1->sched, ctx->timeout_task);
840 ctx->timeout_task = GNUNET_SCHEDULER_NO_TASK;
841 }
842
823 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) 843 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
824 { 844 {
825 if (ctx->d2th != NULL) 845 if (ctx->d2th != NULL)
@@ -842,10 +862,20 @@ notify_connect_result (void *cls,
842 ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, ctx->d1->cfg, 862 ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, ctx->d1->cfg,
843 ctx->d2->cfg, ctx->d1, ctx->d2, NULL); 863 ctx->d2->cfg, ctx->d1, ctx->d2, NULL);
844 } 864 }
845 GNUNET_SCHEDULER_cancel(ctx->d1->sched, ctx->timeout_task);
846 } 865 }
847 else if (remaining.value > 0) 866 else if (remaining.value > 0)
848 { 867 {
868 if (ctx->d1core != NULL)
869 {
870 GNUNET_CORE_disconnect(ctx->d1core);
871 ctx->d1core = NULL;
872 }
873
874 if (ctx->d2th != NULL)
875 {
876 GNUNET_TRANSPORT_disconnect(ctx->d2th);
877 ctx->d2th = NULL;
878 }
849 GNUNET_SCHEDULER_add_now(ctx->d1->sched, &reattempt_daemons_connect, ctx); 879 GNUNET_SCHEDULER_add_now(ctx->d1->sched, &reattempt_daemons_connect, ctx);
850 return; 880 return;
851 } 881 }
@@ -859,7 +889,6 @@ notify_connect_result (void *cls,
859 } 889 }
860 } 890 }
861 891
862
863 GNUNET_TRANSPORT_disconnect (ctx->d2th); 892 GNUNET_TRANSPORT_disconnect (ctx->d2th);
864 ctx->d2th = NULL; 893 ctx->d2th = NULL;
865 GNUNET_CORE_disconnect (ctx->d1core); 894 GNUNET_CORE_disconnect (ctx->d1core);
@@ -886,6 +915,8 @@ connect_notify (void *cls, const struct GNUNET_PeerIdentity * peer, struct GNUNE
886 if (memcmp(&ctx->d2->id, peer, sizeof(struct GNUNET_PeerIdentity)) == 0) 915 if (memcmp(&ctx->d2->id, peer, sizeof(struct GNUNET_PeerIdentity)) == 0)
887 { 916 {
888 ctx->connected = GNUNET_YES; 917 ctx->connected = GNUNET_YES;
918 GNUNET_SCHEDULER_cancel(ctx->d1->sched, ctx->timeout_task);
919 ctx->timeout_task = GNUNET_SCHEDULER_NO_TASK;
889 GNUNET_SCHEDULER_add_now (ctx->d1->sched, 920 GNUNET_SCHEDULER_add_now (ctx->d1->sched,
890 &notify_connect_result, 921 &notify_connect_result,
891 ctx); 922 ctx);
@@ -935,7 +966,7 @@ GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
935{ 966{
936 struct ConnectContext *ctx; 967 struct ConnectContext *ctx;
937 968
938 if ((d1->server == NULL) || (d2->server == NULL)) 969 if ((d1->running == GNUNET_NO) || (d2->running == GNUNET_NO))
939 { 970 {
940 if (NULL != cb) 971 if (NULL != cb)
941 cb (cb_cls, &d1->id, &d2->id, d1->cfg, d2->cfg, d1, d2, 972 cb (cb_cls, &d1->id, &d2->id, d1->cfg, d2->cfg, d1, d2,
@@ -988,6 +1019,7 @@ GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
988 d2->cfg, d2, NULL, NULL, NULL); 1019 d2->cfg, d2, NULL, NULL, NULL);
989 if (ctx->d2th == NULL) 1020 if (ctx->d2th == NULL)
990 { 1021 {
1022 GNUNET_CORE_disconnect(ctx->d1core);
991 GNUNET_free (ctx); 1023 GNUNET_free (ctx);
992 if (NULL != cb) 1024 if (NULL != cb)
993 cb (cb_cls, &d1->id, &d2->id, d1->cfg, d2->cfg, d1, d2, 1025 cb (cb_cls, &d1->id, &d2->id, d1->cfg, d2->cfg, d1, d2,
@@ -1011,22 +1043,12 @@ reattempt_daemons_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext
1011 { 1043 {
1012 return; 1044 return;
1013 } 1045 }
1014#if DEBUG_TESTING 1046#if DEBUG_TESTING_RECONNECT
1015 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "re-attempting connect of peer %s to peer %s\n", 1047 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "re-attempting connect of peer %s to peer %s\n",
1016 ctx->d1->shortname, ctx->d2->shortname); 1048 ctx->d1->shortname, ctx->d2->shortname);
1017#endif 1049#endif
1018 1050
1019 if (ctx->d1core != NULL) 1051 GNUNET_assert(ctx->d1core == NULL);
1020 {
1021 GNUNET_CORE_disconnect(ctx->d1core);
1022 ctx->d1core = NULL;
1023 }
1024
1025 if (ctx->d2th != NULL)
1026 {
1027 GNUNET_TRANSPORT_disconnect(ctx->d2th);
1028 ctx->d2th = NULL;
1029 }
1030 1052
1031 ctx->d1core = GNUNET_CORE_connect (ctx->d1->sched, 1053 ctx->d1core = GNUNET_CORE_connect (ctx->d1->sched,
1032 ctx->d1->cfg, 1054 ctx->d1->cfg,
@@ -1049,6 +1071,7 @@ reattempt_daemons_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext
1049 ctx->d2->cfg, ctx->d2, NULL, NULL, NULL); 1071 ctx->d2->cfg, ctx->d2, NULL, NULL, NULL);
1050 if (ctx->d2th == NULL) 1072 if (ctx->d2th == NULL)
1051 { 1073 {
1074 GNUNET_CORE_disconnect(ctx->d1core);
1052 GNUNET_free (ctx); 1075 GNUNET_free (ctx);
1053 if (NULL != ctx->cb) 1076 if (NULL != ctx->cb)
1054 ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2, 1077 ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2,