diff options
Diffstat (limited to 'src/testing/test_testing_topology.c')
-rw-r--r-- | src/testing/test_testing_topology.c | 105 |
1 files changed, 31 insertions, 74 deletions
diff --git a/src/testing/test_testing_topology.c b/src/testing/test_testing_topology.c index ba5e237..b216544 100644 --- a/src/testing/test_testing_topology.c +++ b/src/testing/test_testing_topology.c @@ -26,7 +26,6 @@ #include "gnunet_core_service.h" #include "gnunet_os_lib.h" -#define VERBOSE GNUNET_NO #define PROGRESS_BARS GNUNET_YES @@ -167,25 +166,23 @@ static struct TestMessageContext *test_messages; /** * Check whether peers successfully shut down. */ -void +static void shutdown_callback (void *cls, const char *emsg) { if (emsg != NULL) { -#if VERBOSE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n"); -#endif + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Shutdown of peers failed: %s!\n", + emsg); if (ok == 0) ok = 666; } else { -#if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers successfully shut down!\n"); -#endif } } + #if DELAY_FOR_LOGGING static void gather_log_data () @@ -200,12 +197,12 @@ gather_log_data () GNUNET_OS_start_process (NULL, NULL, "./memsize.pl", "memsize.pl", "totals.txt", peer_number, connect_number, NULL); GNUNET_OS_process_wait (mem_process); - GNUNET_OS_process_close (mem_process); + GNUNET_OS_process_destroy (mem_process); mem_process = NULL; } - #endif + static void finish_testing () { @@ -213,11 +210,8 @@ finish_testing () struct TestMessageContext *pos; struct TestMessageContext *free_pos; -#if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called finish testing, stopping daemons.\n"); -#endif - pos = test_messages; while (pos != NULL) { @@ -239,16 +233,11 @@ finish_testing () } GNUNET_free (free_pos); } -#if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n", transmit_ready_scheduled, transmit_ready_failed, transmit_ready_called); -#endif - -#if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Calling daemons_stop\n"); -#endif GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); if (dotOutFile != NULL) @@ -256,7 +245,6 @@ finish_testing () FPRINTF (dotOutFile, "%s", "}"); FCLOSE (dotOutFile); } - ok = 0; } @@ -267,21 +255,20 @@ disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) struct TestMessageContext *pos = cls; /* Disconnect from the respective cores */ -#if VERBOSE > 1 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from peer 1 `%4s'\n", GNUNET_i2s (&pos->peer1->id)); -#endif if (pos->peer1handle != NULL) + { GNUNET_CORE_disconnect (pos->peer1handle); -#if VERBOSE > 1 + pos->peer1handle = NULL; + } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from peer 2 `%4s'\n", GNUNET_i2s (&pos->peer2->id)); -#endif if (pos->peer2handle != NULL) + { GNUNET_CORE_disconnect (pos->peer2handle); - /* Set handles to NULL so test case can be ended properly */ - pos->peer1handle = NULL; - pos->peer2handle = NULL; + pos->peer2handle = NULL; + } pos->disconnect_task = GNUNET_SCHEDULER_NO_TASK; /* Decrement total connections so new can be established */ total_server_connections -= 2; @@ -316,6 +303,7 @@ stats_print (void *cls, const struct GNUNET_PeerIdentity *peer, } #endif + static void topology_cb (void *cls, const struct GNUNET_PeerIdentity *first, const struct GNUNET_PeerIdentity *second, const char *emsg) @@ -348,6 +336,7 @@ topology_cb (void *cls, const struct GNUNET_PeerIdentity *first, } } + static int process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message, @@ -382,14 +371,12 @@ process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer, total_messages_received++; -#if VERBOSE > 1 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message from `%4s', type %d.\n", GNUNET_i2s (peer), ntohs (message->type)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Total messages received %d, expected %d.\n", total_messages_received, expected_messages); -#endif if (total_messages_received == expected_messages) { @@ -416,13 +403,14 @@ process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer, return GNUNET_OK; } + static void end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { char *msg = cls; - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "End badly was called (%s)... stopping daemons.\n", msg); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Ending with error: %s\n", msg); struct TestMessageContext *pos; struct TestMessageContext *free_pos; @@ -444,7 +432,6 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_free (free_pos); } -#if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n", transmit_ready_scheduled, transmit_ready_failed, @@ -452,7 +439,6 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Total messages received %d, expected %d.\n", total_messages_received, expected_messages); -#endif if (pg != NULL) { @@ -469,6 +455,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) } } + static size_t transmit_ready (void *cls, size_t size, void *buf) { @@ -481,12 +468,10 @@ transmit_ready (void *cls, size_t size, void *buf) m->header.size = htons (sizeof (struct GNUNET_TestMessage)); m->uid = htonl (pos->uid); transmit_ready_called++; -#if VERBOSE > 1 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "transmit ready for peer %s\ntransmit_ready's scheduled %d, transmit_ready's called %d\n", GNUNET_i2s (&pos->peer1->id), transmit_ready_scheduled, transmit_ready_called); -#endif return sizeof (struct GNUNET_TestMessage); } @@ -495,11 +480,13 @@ static struct GNUNET_CORE_MessageHandler no_handlers[] = { {NULL, 0, 0} }; + static struct GNUNET_CORE_MessageHandler handlers[] = { {&process_mtype, MTYPE, sizeof (struct GNUNET_TestMessage)}, {NULL, 0, 0} }; + static void init_notify_peer2 (void *cls, struct GNUNET_CORE_Handle *server, const struct GNUNET_PeerIdentity *my_identity) @@ -511,12 +498,10 @@ init_notify_peer2 (void *cls, struct GNUNET_CORE_Handle *server, pos->peer2connected = GNUNET_YES; if (pos->peer1notified == GNUNET_YES) /* Peer 1 has been notified of connection to peer 2 */ { -#if VERBOSE > 1 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Scheduling message send to peer `%s' from peer `%s' (init_notify_peer2)\n", GNUNET_i2s (my_identity), GNUNET_h2s (&pos->peer1->id.hashPubKey)); -#endif if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle, GNUNET_YES, 0, TIMEOUT, &pos->peer2->id, @@ -535,6 +520,7 @@ init_notify_peer2 (void *cls, struct GNUNET_CORE_Handle *server, } } + /** * Method called whenever a given peer connects. * @@ -553,23 +539,19 @@ connect_notify_peers (void *cls, const struct GNUNET_PeerIdentity *peer, if (0 == memcmp (peer, &pos->peer2->id, sizeof (struct GNUNET_PeerIdentity))) { pos->peer1notified = GNUNET_YES; -#if VERBOSE > 1 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' notified of connection to peer `%s'\n", GNUNET_i2s (&pos->peer1->id), GNUNET_h2s (&peer->hashPubKey)); -#endif } else return; if (pos->peer2connected == GNUNET_YES) /* Already connected and notified of connection, send message! */ { -#if VERBOSE > 1 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Scheduling message send to peer `%s' from peer `%s' (init_notify_peer2)\n", GNUNET_i2s (&pos->peer2->id), GNUNET_h2s (&pos->peer1->id.hashPubKey)); -#endif if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle, GNUNET_YES, 0, TIMEOUT, &pos->peer2->id, @@ -588,6 +570,7 @@ connect_notify_peers (void *cls, const struct GNUNET_PeerIdentity *peer, } } + static void init_notify_peer1 (void *cls, struct GNUNET_CORE_Handle *server, const struct GNUNET_PeerIdentity *my_identity) @@ -595,13 +578,9 @@ init_notify_peer1 (void *cls, struct GNUNET_CORE_Handle *server, struct TestMessageContext *pos = cls; total_server_connections++; - -#if VERBOSE > 1 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core connection to `%4s' established, setting up handles\n", GNUNET_i2s (my_identity)); -#endif - /* * Connect to the receiving peer */ @@ -663,7 +642,7 @@ send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) } -void +static void topology_callback (void *cls, const struct GNUNET_PeerIdentity *first, const struct GNUNET_PeerIdentity *second, uint32_t distance, const struct GNUNET_CONFIGURATION_Handle *first_cfg, @@ -694,10 +673,8 @@ topology_callback (void *cls, const struct GNUNET_PeerIdentity *first, fflush (stdout); #endif total_connections++; -#if VERBOSE > 1 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "connected peer %s to peer %s\n", first_daemon->shortname, second_daemon->shortname); -#endif temp_context = GNUNET_malloc (sizeof (struct TestMessageContext)); temp_context->peer1 = first_daemon; temp_context->peer2 = second_daemon; @@ -711,26 +688,22 @@ topology_callback (void *cls, const struct GNUNET_PeerIdentity *first, FPRINTF (dotOutFile, "\tn%s -- n%s;\n", first_daemon->shortname, second_daemon->shortname); } -#if VERBOSE else { failed_connections++; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to connect peer %s to peer %s with error :\n%s\n", first_daemon->shortname, second_daemon->shortname, emsg); } -#endif if (total_connections == expected_connections) { #if PROGRESS_BARS FPRINTF (stdout, "%s", "100%%]\n"); #endif -#if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created %d total connections, which is our target number! Calling send messages.\n", total_connections); -#endif modnum = expected_messages / 4; dotnum = (expected_messages / 50) + 1; if (modnum == 0) @@ -777,26 +750,24 @@ topology_callback (void *cls, const struct GNUNET_PeerIdentity *first, } else { -#if VERBOSE > 1 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Have %d total connections, %d failed connections, Want %d (at least %d)\n", total_connections, failed_connections, expected_connections, expected_connections - (unsigned int) (fail_percentage * expected_connections)); -#endif } } + static void topology_creation_finished (void *cls, const char *emsg) { -#if VERBOSE if (emsg == NULL) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All topology connections created successfully!\n"); -#endif } + static void connect_topology () { @@ -810,7 +781,7 @@ connect_topology () connect_timeout, connect_attempts, &topology_creation_finished, NULL); #if PROGRESS_BARS - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Have %d expected connections\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Have %d expected connections\n", expected_connections); #endif } @@ -884,10 +855,8 @@ peers_started_callback (void *cls, const struct GNUNET_PeerIdentity *id, return; } GNUNET_assert (id != NULL); -#if VERBOSE > 1 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n", (num_peers - peers_left) + 1, num_peers); -#endif #if PROGRESS_BARS if ((num_peers - peers_left) % modnum == 0) { @@ -910,10 +879,8 @@ peers_started_callback (void *cls, const struct GNUNET_PeerIdentity *id, #if PROGRESS_BARS FPRINTF (stdout, "%s", "100%%]\n"); #endif -#if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All %d daemons started, now connecting peers!\n", num_peers); -#endif GNUNET_SCHEDULER_cancel (die_task); /* Set up task in case topology creation doesn't finish * within a reasonable amount of time */ @@ -952,12 +919,9 @@ hostkey_callback (void *cls, const struct GNUNET_PeerIdentity *id, "Hostkey callback received error: %s\n", emsg); } -#if VERBOSE > 1 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostkey (%d/%d) created for peer `%s'\n", num_peers - peers_left, num_peers, GNUNET_i2s (id)); -#endif - #if PROGRESS_BARS if ((num_peers - peers_left) % modnum == 0) { @@ -993,6 +957,7 @@ hostkey_callback (void *cls, const struct GNUNET_PeerIdentity *id, } } + static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) @@ -1012,11 +977,8 @@ run (void *cls, char *const *args, const char *cfgfile, FPRINTF (dotOutFile, "%s", "strict graph G {\n"); } -#if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons based on config file %s\n", cfgfile); -#endif - if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome", &test_directory)) @@ -1069,7 +1031,7 @@ run (void *cls, char *const *args, const char *cfgfile, "connect_topology_option_modifier", &connect_topology_option_modifier_string)) { - if (sscanf + if (SSCANF (connect_topology_option_modifier_string, "%lf", &connect_topology_option_modifier) != 1) { @@ -1178,6 +1140,7 @@ run (void *cls, char *const *args, const char *cfgfile, } + static int check () { @@ -1192,9 +1155,6 @@ check () char *const argv[] = { binary_name, "-c", config_file_name, -#if VERBOSE - "-L", "DEBUG", -#endif NULL }; struct GNUNET_GETOPT_CommandLineOption options[] = { @@ -1214,6 +1174,7 @@ check () return ok; } + int main (int argc, char *argv[]) { @@ -1238,11 +1199,7 @@ main (int argc, char *argv[]) GNUNET_asprintf (&dotOutFileName, "topology_%s.dot", topology_string); GNUNET_log_setup (our_binary_name, -#if VERBOSE - "DEBUG", -#else "WARNING", -#endif NULL); ret = check (); GNUNET_free (topology_string); |