From 092f6ee135d29f88264d9553d26829c2772f7e16 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Thu, 23 Aug 2012 11:48:27 +0000 Subject: [PATCH] plugin test --- src/transport/Makefile.am | 45 ++++++++++ .../plugin_transport_udp_broadcasting.c | 4 +- src/transport/test_plugin_transport.c | 82 ++++++++++++++----- 3 files changed, 109 insertions(+), 22 deletions(-) diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index 66331db92..99fe2d936 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am @@ -47,6 +47,7 @@ if LINUX WLAN_BIN_DUMMY = gnunet-helper-transport-wlan-dummy WLAN_BIN_SENDER = gnunet-transport-wlan-sender WLAN_PLUGIN_LA = libgnunet_plugin_transport_wlan.la + WLAN_PLUGIN_TEST = test_plugin_wlan WLAN_API_TEST = test_transport_api_wlan WLAN_REL_TEST = test_transport_api_reliability_wlan WLAN_UREL_TEST = test_transport_api_unreliability_wlan @@ -295,6 +296,10 @@ check_PROGRAMS = \ test_transport_testing_restart \ test_transport_testing \ test_transport_startonly \ + test_plugin_tcp \ + test_plugin_udp \ + test_plugin_unix \ + $(WLAN_PLUGIN_TEST) \ test_transport_api_blacklisting \ test_transport_api_disconnect_tcp \ test_transport_api_bidirectional_connect \ @@ -342,6 +347,10 @@ TESTS = \ test_transport_testing_restart \ test_transport_testing \ test_transport_startonly \ + test_plugin_tcp \ + test_plugin_udp \ + test_plugin_unix \ + $(WLAN_PLUGIN_TEST) \ test_transport_api_blacklisting \ test_transport_api_disconnect_tcp \ test_transport_api_bidirectional_connect \ @@ -435,6 +444,42 @@ test_transport_startonly_LDADD = \ $(top_builddir)/src/util/libgnunetutil.la \ $(top_builddir)/src/transport/libgnunettransporttesting.la +test_plugin_tcp_SOURCES = \ + test_plugin_transport.c +test_plugin_tcp_LDADD = \ + $(top_builddir)/src/transport/libgnunettransport.la \ + $(top_builddir)/src/statistics/libgnunetstatistics.la \ + $(top_builddir)/src/hello/libgnunethello.la \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(top_builddir)/src/transport/libgnunettransporttesting.la + +test_plugin_udp_SOURCES = \ + test_plugin_transport.c +test_plugin_udp_LDADD = \ + $(top_builddir)/src/transport/libgnunettransport.la \ + $(top_builddir)/src/statistics/libgnunetstatistics.la \ + $(top_builddir)/src/hello/libgnunethello.la \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(top_builddir)/src/transport/libgnunettransporttesting.la + +test_plugin_unix_SOURCES = \ + test_plugin_transport.c +test_plugin_unix_LDADD = \ + $(top_builddir)/src/transport/libgnunettransport.la \ + $(top_builddir)/src/statistics/libgnunetstatistics.la \ + $(top_builddir)/src/hello/libgnunethello.la \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(top_builddir)/src/transport/libgnunettransporttesting.la + +test_plugin_wlan_SOURCES = \ + test_plugin_transport.c +test_plugin_wlan_LDADD = \ + $(top_builddir)/src/transport/libgnunettransport.la \ + $(top_builddir)/src/statistics/libgnunetstatistics.la \ + $(top_builddir)/src/hello/libgnunethello.la \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(top_builddir)/src/transport/libgnunettransporttesting.la + test_transport_api_tcp_SOURCES = \ test_transport_api.c test_transport_api_tcp_LDADD = \ diff --git a/src/transport/plugin_transport_udp_broadcasting.c b/src/transport/plugin_transport_udp_broadcasting.c index d418e50d9..db6c1fe8c 100644 --- a/src/transport/plugin_transport_udp_broadcasting.c +++ b/src/transport/plugin_transport_udp_broadcasting.c @@ -228,6 +228,8 @@ prepare_beacon (struct Plugin *plugin, struct UDP_Beacon_Message *msg) const struct GNUNET_MessageHeader *hello; hello = plugin->env->get_our_hello (); + if (NULL == hello) + return 0; hello_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello); msg_size = hello_size + sizeof (struct UDP_Beacon_Message); @@ -258,7 +260,7 @@ udp_ipv4_broadcast_send (void *cls, sent = 0; baddr = plugin->ipv4_broadcast_head; /* just IPv4 */ - while ((baddr != NULL) && (baddr->addrlen == sizeof (struct sockaddr_in))) + while ((msg_size > 0) && (baddr != NULL) && (baddr->addrlen == sizeof (struct sockaddr_in))) { struct sockaddr_in *addr = (struct sockaddr_in *) baddr->addr; diff --git a/src/transport/test_plugin_transport.c b/src/transport/test_plugin_transport.c index dbd6c6c63..bc7df9880 100644 --- a/src/transport/test_plugin_transport.c +++ b/src/transport/test_plugin_transport.c @@ -40,7 +40,8 @@ /** * How long until we give up on transmitting the message? */ -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) +#define WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) +#define TIMEOUT GNUNET_TIME_relative_multiply (WAIT, 3) /** * Our public key. @@ -67,6 +68,11 @@ const struct GNUNET_CONFIGURATION_Handle *cfg; */ struct GNUNET_STATISTICS_Handle *stats; +/** + * Our HELLO + */ +struct GNUNET_HELLO_Message *hello; + /** * Number of neighbours we'd like to have. */ @@ -87,14 +93,28 @@ struct GNUNET_TRANSPORT_PluginFunctions *api; */ static GNUNET_SCHEDULER_TaskIdentifier timeout_task; +/** + * Timeout task + */ +static GNUNET_SCHEDULER_TaskIdentifier timeout_wait; + /** * Library name */ static char *libname; +/** + * Plugin addresses head + */ struct AddressWrapper *head; + +/** + * Plugin addresses tail + */ struct AddressWrapper *tail; +unsigned int addresses_reported; + /** * Did the test pass or fail? */ @@ -115,21 +135,13 @@ struct AddressWrapper static void end () { - if (NULL != head) - { - - } - if (GNUNET_SCHEDULER_NO_TASK != timeout_task) { GNUNET_SCHEDULER_cancel (timeout_task); timeout_task = GNUNET_SCHEDULER_NO_TASK; } - if (NULL != api) - { GNUNET_PLUGIN_unload (libname, api); - } GNUNET_free (libname); libname = NULL; GNUNET_STATISTICS_destroy (stats, GNUNET_NO); @@ -139,13 +151,16 @@ end () } static void - end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct AddressWrapper *w; int c = 0; - timeout_task = GNUNET_SCHEDULER_NO_TASK; + if (GNUNET_SCHEDULER_NO_TASK != timeout_wait) + { + GNUNET_SCHEDULER_cancel (timeout_wait); + timeout_wait = GNUNET_SCHEDULER_NO_TASK; + } if (NULL != libname) { if (NULL != api) @@ -178,10 +193,25 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) ok = 1; } +static void +wait_end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + timeout_wait = GNUNET_SCHEDULER_NO_TASK; + if (0 == addresses_reported) + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _("Plugin did not report any addresses, could not check plugin \n")); + end (); +} + static void end_badly_now () { + if (GNUNET_SCHEDULER_NO_TASK != timeout_wait) + { + GNUNET_SCHEDULER_cancel (timeout_wait); + timeout_wait = GNUNET_SCHEDULER_NO_TASK; + } if (GNUNET_SCHEDULER_NO_TASK != timeout_task) { GNUNET_SCHEDULER_cancel (timeout_task); @@ -202,7 +232,6 @@ env_receive (void *cls, uint16_t sender_address_len) { /* do nothing */ - GNUNET_break (0); return GNUNET_TIME_relative_get_zero_(); } @@ -220,7 +249,8 @@ env_notify_address (void *cls, if (GNUNET_YES == add_remove) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + addresses_reported ++; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Adding address of length %u\n"), addrlen); w = GNUNET_malloc (sizeof (struct AddressWrapper)); @@ -271,10 +301,16 @@ env_notify_address (void *cls, end_badly_now(); return; } + if (GNUNET_SCHEDULER_NO_TASK != timeout_wait) + { + GNUNET_SCHEDULER_cancel (timeout_wait); + timeout_wait = GNUNET_SCHEDULER_NO_TASK; + } + timeout_wait = GNUNET_SCHEDULER_add_delayed (WAIT, &wait_end, NULL); } else if (GNUNET_NO == add_remove) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Removing address of length %u\n"), addrlen); w = head; @@ -304,8 +340,9 @@ env_notify_address (void *cls, { GNUNET_break (0); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Invalid operation\n")); + _("Invalid operation: %u \n"), add_remove); end_badly_now (); + return; } } @@ -315,17 +352,15 @@ env_get_address_type (void *cls, size_t addrlen) { struct GNUNET_ATS_Information ats; - ats.type = htonl (0); - ats.value = htonl (0); + ats.type = htonl (GNUNET_ATS_NETWORK_TYPE); + ats.value = htonl (GNUNET_ATS_NET_LOOPBACK); return ats; } - const struct GNUNET_MessageHeader * env_get_our_hello (void) { - GNUNET_break (0); - return NULL; + return (const struct GNUNET_MessageHeader *) hello; } void env_session_end (void *cls, @@ -409,6 +444,9 @@ run (void *cls, char *const *args, const char *cfgfile, GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key), &my_identity.hashPubKey); + + hello = GNUNET_HELLO_create(&my_public_key, NULL, NULL); + /* load plugins... */ setup_plugin_environment (); @@ -431,11 +469,13 @@ run (void *cls, char *const *args, const char *cfgfile, if (api == NULL) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Failed to load transport plugin for tcp\n")); + _("Failed to load transport plugin for %s\n"), plugin); end_badly_now (); return; } + timeout_wait = GNUNET_SCHEDULER_add_delayed (WAIT, &wait_end, NULL); + /* Check if all functions are implemented */ if (NULL == api->address_pretty_printer) { -- 2.25.1