gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r37522 - gnunet/src/transport


From: gnunet
Subject: [GNUnet-SVN] r37522 - gnunet/src/transport
Date: Sun, 10 Jul 2016 16:58:37 +0200

Author: grothoff
Date: 2016-07-10 16:58:37 +0200 (Sun, 10 Jul 2016)
New Revision: 37522

Modified:
   gnunet/src/transport/test_transport_address_switch.c
   gnunet/src/transport/test_transport_api_disconnect.c
   gnunet/src/transport/test_transport_testing_restart.c
   gnunet/src/transport/test_transport_testing_startstop.c
   gnunet/src/transport/transport-testing-main.c
   gnunet/src/transport/transport-testing.c
Log:
clean up switch tests

Modified: gnunet/src/transport/test_transport_address_switch.c
===================================================================
--- gnunet/src/transport/test_transport_address_switch.c        2016-07-10 
14:56:13 UTC (rev 37521)
+++ gnunet/src/transport/test_transport_address_switch.c        2016-07-10 
14:58:37 UTC (rev 37522)
@@ -1,6 +1,6 @@
 /*
  This file is part of GNUnet.
- Copyright (C) 2009, 2010, 2011 GNUnet e.V.
+ Copyright (C) 2009, 2010, 2011, 2016 GNUnet e.V.
 
  GNUnet is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published
@@ -33,19 +33,20 @@
  * addresses in connected state and a test message was successfully transmitted
  * after this switch.
  *
- * Since it is not possible to trigger an address switch from
- * outside, the test still passes when no address switching attempt takes
- * place. It fails if an address switch attempt fails.
+ * Since it is not possible to trigger an address switch from outside,
+ * the test returns "77" (skipped) when no address switching attempt
+ * takes place. It fails if an address switch attempt fails.
+ *
+ * NOTE: The test seems largely useless right now, as we simply NEVER
+ * switch addresses under the test conditions.  However, it may be a
+ * good starting point for a future test.  For now, it always times
+ * out and returns "77" (skipped), so we set the timeout suitably low.
  */
 #include "platform.h"
 #include "gnunet_transport_service.h"
 #include "gnunet_ats_service.h"
-#include "gauger.h"
 #include "transport-testing.h"
 
-/*
- * Testcase specific declarations
- */
 
 GNUNET_NETWORK_STRUCT_BEGIN
 struct TestMessage
@@ -68,86 +69,44 @@
 /**
  * Testcase timeout
  */
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
 
 /**
  * How long until we give up on transmitting the message?
  */
-#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply 
(GNUNET_TIME_UNIT_SECONDS, 60)
+#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply 
(GNUNET_TIME_UNIT_SECONDS, 5)
 
-#define DURATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
 
+static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
 
-/**
- * Timeout task to send messages
- */
-static struct GNUNET_SCHEDULER_Task *die_task;
+static struct GNUNET_SCHEDULER_Task *measure_task;
 
+static struct GNUNET_TRANSPORT_TransmitHandle *th;
 
-static struct GNUNET_SCHEDULER_Task *delayed_end_task;
-
 /**
- * Measurement task to send messages
+ * Statistics we track per peer.
  */
-static struct GNUNET_SCHEDULER_Task *measure_task;
+struct PeerStats
+{
+  struct GNUNET_STATISTICS_Handle *stat;
 
+  unsigned int addresses_avail;
 
-static struct GNUNET_TRANSPORT_TESTING_PeerContext *p1;
-static char *cfg_file_p1;
-static struct GNUNET_STATISTICS_Handle *p1_stat;
+  unsigned int switch_attempts;
 
-static struct GNUNET_TRANSPORT_TESTING_PeerContext *p2;
-static char *cfg_file_p2;
-static struct GNUNET_STATISTICS_Handle *p2_stat;
+  unsigned int switch_success;
 
-static struct GNUNET_TRANSPORT_TESTING_PeerContext *sender;
+  unsigned int switch_fail;
+};
 
-static struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver;
+static struct PeerStats stats[2];
 
-static struct GNUNET_TRANSPORT_TransmitHandle *th;
-
-static struct GNUNET_TRANSPORT_TESTING_Handle *tth;
-
-static struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cc;
-
-static int test_connected;
-
-static int res;
-
-
-/**
- * Statistics about peer 1
- */
-static unsigned int p1_addresses_avail;
-static unsigned int p1_switch_attempts;
-static unsigned int p1_switch_success;
-static unsigned int p1_switch_fail;
-
-
-/**
- * Statistics about peer 2
- */
-static unsigned int p2_switch_attempts;
-static unsigned int p2_switch_success;
-static unsigned int p2_switch_fail;
-static unsigned int p2_addresses_avail;
-
-/**
- * Transmission statistics
- */
-
 /* Amount of data transfered since last switch attempt */
 static unsigned long long bytes_sent_after_switch;
+
 static unsigned long long bytes_recv_after_switch;
 
 
-#if VERBOSE
-#define OKPP do { ok++; FPRINTF (stderr, "Now at stage %u at %s:%u\n", ok, 
__FILE__, __LINE__); } while (0)
-#else
-#define OKPP do { ok++; } while (0)
-#endif
-
-
 static int
 stat_start_attempt_cb (void *cls,
                        const char *subsystem,
@@ -155,17 +114,12 @@
                        uint64_t value,
                        int is_persistent)
 {
-  if (cls == p1)
-  {
-    p1_switch_attempts++;
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "(1:s)");
-  }
-  else if (cls == p2)
-  {
-    p2_switch_attempts++;
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "(2:s)");
-  }
+  struct PeerStats *stat = cls;
 
+  stat->switch_attempts++;
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "Switch attempted (%p)",
+              stat);
   bytes_recv_after_switch = 0;
   bytes_sent_after_switch = 0;
 
@@ -180,17 +134,12 @@
                          uint64_t value,
                          int is_persistent)
 {
-  if (cls == p1)
-  {
-    p1_switch_success++;
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "(1:+)");
-  }
-  if (cls == p2)
-  {
-    p2_switch_success++;
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "(2:+)");
-  }
+  struct PeerStats *stat = cls;
 
+  stat->switch_success++;
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "Switch succeeded (%p)",
+              stat);
   return GNUNET_OK;
 }
 
@@ -202,20 +151,15 @@
                       uint64_t value,
                       int is_persistent)
 {
+  struct PeerStats *stat = cls;
+
   if (value == 0)
     return GNUNET_OK;
 
-  if (cls == p1)
-  {
-    p1_switch_fail++;
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "(1:-)");
-  }
-  if (cls == p2)
-  {
-    p2_switch_fail++;
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "(2:-)");
-  }
-
+  stat->switch_fail++;
+  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+              "Switch failed (%p)",
+              stat);
   return GNUNET_OK;
 }
 
@@ -227,206 +171,148 @@
                           uint64_t value,
                           int is_persistent)
 {
-  if (cls == p1)
-  {
-    p1_addresses_avail++;
-  }
-  if (cls == p2)
-  {
-    p2_addresses_avail++;
-  }
+  struct PeerStats *stat = cls;
+
+  stat->addresses_avail++;
   return GNUNET_OK;
 }
 
 
+/**
+ * List of statistics entries we care about.
+ */
+static struct WatchEntry {
+
+  /**
+   * Name of the statistic we watch.
+   */
+  const char *stat_name;
+
+  /**
+   * Handler to register;
+   */
+  GNUNET_STATISTICS_Iterator stat_handler;
+} watches[] = {
+  { "# Attempts to switch addresses", &stat_start_attempt_cb },
+  { "# Successful attempts to switch addresses", &stat_success_attempt_cb },
+  { "# Failed attempts to switch addresses (failed to send CONNECT CONT)", 
&stat_fail_attempt_cb },
+  { "# Failed attempts to switch addresses (failed to send CONNECT)", 
&stat_fail_attempt_cb },
+  { "# Failed attempts to switch addresses (no response)", 
&stat_fail_attempt_cb },
+  { "# transport addresses", &stat_addresses_available },
+  { NULL, NULL }
+};
+
+
 static void
-clean_up ()
+custom_shutdown (void *cls)
 {
-  if (measure_task != NULL)
+  int result;
+
+  if (NULL != measure_task)
   {
     GNUNET_SCHEDULER_cancel (measure_task);
     measure_task = NULL;
   }
-
-  if (delayed_end_task != NULL)
+  if (0 == stats[0].switch_attempts + stats[1].switch_attempts)
   {
-    GNUNET_SCHEDULER_cancel (delayed_end_task);
-    delayed_end_task = NULL;
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Test did not work, as peers didn't switch (flawed 
testcase)!\n");
+    ccc->global_ret = 77;
   }
-
-  if (die_task != NULL)
+  else
   {
-    GNUNET_SCHEDULER_cancel (die_task);
-    die_task = NULL;
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Fail (timeout)! No transmission after switch! Stopping 
peers\n");
+    ccc->global_ret = GNUNET_SYSERR;
   }
 
-  if (NULL != p1_stat)
+  /* stop statistics */
+  for (unsigned int i=0;i<2;i++)
   {
-    GNUNET_STATISTICS_watch_cancel (p1_stat, "transport",
-        "# Attempts to switch addresses",
-        stat_start_attempt_cb, p1);
-    GNUNET_STATISTICS_watch_cancel (p1_stat, "transport",
-        "# Successful attempts to switch addresses",
-        stat_success_attempt_cb, p1);
-    GNUNET_STATISTICS_watch_cancel (p1_stat, "transport",
-        "# Failed attempts to switch addresses (failed to send CONNECT CONT)",
-        stat_fail_attempt_cb, p1);
-    GNUNET_STATISTICS_watch_cancel (p1_stat, "transport",
-        "# Failed attempts to switch addresses (failed to send CONNECT)",
-        stat_fail_attempt_cb, p1);
-    GNUNET_STATISTICS_watch_cancel (p1_stat, "transport",
-        "# Failed attempts to switch addresses (no response)",
-        stat_fail_attempt_cb, p1);
-    GNUNET_STATISTICS_watch (p1_stat, "transport",
-        "# transport addresses",
-        stat_addresses_available, p1);
-    GNUNET_STATISTICS_destroy (p1_stat, GNUNET_NO);
-    p1_stat = NULL;
+    if (NULL != stats[i].stat)
+    {
+      for (unsigned int j=0;NULL != watches[j].stat_name; j++)
+        GNUNET_STATISTICS_watch_cancel (stats[i].stat,
+                                        "transport",
+                                        watches[j].stat_name,
+                                        watches[j].stat_handler,
+                                        &stats[i]);
+
+      GNUNET_STATISTICS_destroy (stats[i].stat,
+                                 GNUNET_NO);
+      stats[i].stat = NULL;
+    }
   }
-  if (NULL != p2_stat)
+  if (NULL != th)
   {
-    GNUNET_STATISTICS_watch_cancel (p2_stat, "transport",
-        "# Attempts to switch addresses", stat_start_attempt_cb, p2);
-    GNUNET_STATISTICS_watch_cancel (p2_stat, "transport",
-        "# Successful attempts to switch addresses", stat_success_attempt_cb, 
p2);
-    GNUNET_STATISTICS_watch_cancel (p2_stat, "transport",
-        "# Failed attempts to switch addresses (failed to send CONNECT CONT)",
-        stat_fail_attempt_cb, p2);
-    GNUNET_STATISTICS_watch_cancel (p2_stat, "transport",
-        "# Failed attempts to switch addresses (failed to send CONNECT)",
-        stat_fail_attempt_cb, p2);
-    GNUNET_STATISTICS_watch_cancel (p2_stat, "transport",
-        "# Failed attempts to switch addresses (no response)",
-        stat_fail_attempt_cb, p2);
-    GNUNET_STATISTICS_watch (p2_stat, "transport",
-        "# transport addresses",
-        stat_addresses_available, p2);
-    GNUNET_STATISTICS_destroy (p2_stat, GNUNET_NO);
-    p2_stat = NULL;
-  }
-
-  if (th != NULL)
-  {
     GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
     th = NULL;
   }
-  if (cc != NULL)
-  {
-    GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc);
-    cc = NULL;
-  }
-  if (p1 != NULL)
-  {
-    GNUNET_TRANSPORT_TESTING_stop_peer (p1);
-    p1 = NULL;
-  }
-  if (p2 != NULL)
-  {
-    GNUNET_TRANSPORT_TESTING_stop_peer (p2);
-    p2 = NULL;
-  }
-}
 
-
-static void
-end ()
-{
-  int result = 0;
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Stopping peers\n");
-
-  delayed_end_task = NULL;
+  result = 0;
   FPRINTF (stderr, "\n");
-  if (p1_switch_attempts > 0)
+  if (stats[0].switch_attempts > 0)
   {
     FPRINTF (stderr,
              "Peer 1 tried %u times to switch and succeeded %u times, failed 
%u times\n",
-             p1_switch_attempts,
-             p1_switch_success,
-             p1_switch_fail);
-    if (p1_switch_success != p1_switch_attempts)
+             stats[0].switch_attempts,
+             stats[0].switch_success,
+             stats[0].switch_fail);
+    if (stats[0].switch_success != stats[0].switch_attempts)
     {
       GNUNET_break (0);
       result ++;
     }
   }
-  else if (p1_addresses_avail > 1)
+  else if (stats[0].addresses_avail > 1)
   {
     FPRINTF (stderr,
              "Peer 1 had %u addresses available, but did not try to switch\n",
-             p1_addresses_avail);
+             stats[0].addresses_avail);
   }
-  if (p2_switch_attempts > 0)
+  if (stats[1].switch_attempts > 0)
   {
     FPRINTF (stderr,
              "Peer 2 tried %u times to switch and succeeded %u times, failed 
%u times\n",
-             p2_switch_attempts,
-             p2_switch_success,
-             p2_switch_fail);
-    if (p2_switch_success != p2_switch_attempts)
+             stats[1].switch_attempts,
+             stats[1].switch_success,
+             stats[1].switch_fail);
+    if (stats[1].switch_success != stats[1].switch_attempts)
     {
       GNUNET_break (0);
       result++;
     }
   }
-  else if (p2_addresses_avail > 1)
+  else if (stats[1].addresses_avail > 1)
   {
     FPRINTF (stderr,
              "Peer 2 had %u addresses available, but did not try to switch\n",
-             p2_addresses_avail);
+             stats[1].addresses_avail);
   }
 
-  if ( ((p1_switch_attempts > 0) || (p2_switch_attempts > 0)) &&
+  if ( ((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) &&
        (bytes_sent_after_switch == 0) )
   {
     FPRINTF (stderr, "No data sent after switching!\n");
     GNUNET_break (0);
-    res++;
+    result++;
   }
-  if ( ((p1_switch_attempts > 0) || (p2_switch_attempts > 0)) &&
+  if ( ((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) &&
        (bytes_recv_after_switch == 0) )
   {
     FPRINTF (stderr, "No data received after switching!\n");
     GNUNET_break (0);
-    res++;
+    result++;
   }
-
-  clean_up();
-
-  res = result;
+  if (0 != result)
+    ccc->global_ret = GNUNET_SYSERR;
 }
 
 
 static void
-end_badly ()
-{
-  die_task = NULL;
-  clean_up();
-  if (0 == p1_switch_attempts + p2_switch_attempts)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "Test did not work, as peers didn't switch (flawed 
testcase)!\n");
-    res = 0;
-  }
-  else
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-              "Fail (timeout)! No transmission after switch! Stopping 
peers\n");
-    res = GNUNET_YES;
-  }
-  if (test_connected == GNUNET_YES)
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Peers got connected\n");
-  else
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Peers got NOT EVEN connected\n");
-}
-
-
-static void
 notify_receive (void *cls,
-                const struct GNUNET_PeerIdentity *peer,
+                struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
+                const struct GNUNET_PeerIdentity *sender,
                 const struct GNUNET_MessageHeader *message)
 {
   const struct TestMessage *hdr;
@@ -435,17 +321,21 @@
   if (MTYPE != ntohs (message->type))
     return;
 
-  struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
-  char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
+  {
+    char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id));
 
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              "Peer %u (`%s') got message %u of size %u from peer (`%s')\n", 
p->no, ps,
-              ntohl (hdr->num),
-              ntohs (message->size),
-              GNUNET_i2s (peer));
-  if ( ((p1_switch_attempts >= 1) || (p2_switch_attempts >= 1)) &&
-        (p1_switch_attempts == p1_switch_fail + p1_switch_success) &&
-        (p2_switch_attempts == p2_switch_fail + p2_switch_success) )
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                "Peer %u (`%s') got message %u of size %u from peer (`%s')\n",
+                receiver->no,
+                ps,
+                ntohl (hdr->num),
+                ntohs (message->size),
+                GNUNET_i2s (sender));
+    GNUNET_free (ps);
+  }
+  if ( ((stats[0].switch_attempts >= 1) || (stats[1].switch_attempts >= 1)) &&
+        (stats[0].switch_attempts == stats[0].switch_fail + 
stats[0].switch_success) &&
+        (stats[1].switch_attempts == stats[1].switch_fail + 
stats[1].switch_success) )
   {
     bytes_recv_after_switch += ntohs(hdr->header.size);
     if ((bytes_sent_after_switch > 0) && (bytes_recv_after_switch > 0))
@@ -452,11 +342,9 @@
     {
       /* A peer switched addresses and sent and received data after the
        * switch operations */
-      end ();
+      GNUNET_SCHEDULER_shutdown ();
     }
   }
-
-  GNUNET_free(ps);
 }
 
 
@@ -472,10 +360,8 @@
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                "Timeout occurred while waiting for transmit_ready for 
message\n");
-    if (NULL != die_task)
-      GNUNET_SCHEDULER_cancel (die_task);
-    die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
-    res = 1;
+    ccc->global_ret = GNUNET_SYSERR;
+    GNUNET_SCHEDULER_shutdown ();
     return 0;
   }
 
@@ -489,27 +375,32 @@
   GNUNET_memcpy (&cbuf[0], &hdr, sizeof(struct TestMessage));
   memset (&cbuf[sizeof(struct TestMessage)], '0', MSIZE - sizeof(struct 
TestMessage));
 
-  char *receiver_s = GNUNET_strdup (GNUNET_i2s (&receiver->id));
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              "Sending message %u of size %u from peer %u (`%4s') -> peer %u 
(`%s') !\n",
-              (unsigned int) (counter - 1),
-              MSIZE,
-              sender->no,
-              GNUNET_i2s (&sender->id),
-              receiver->no,
-              receiver_s);
-  GNUNET_free(receiver_s);
+  {
+    char *receiver_s = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id));
 
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                "Sending message %u of size %u from peer %u (`%4s') -> peer %u 
(`%s') !\n",
+                (unsigned int) (counter - 1),
+                MSIZE,
+                ccc->p[1]->no,
+                GNUNET_i2s (&ccc->p[1]->id),
+                ccc->p[0]->no,
+                receiver_s);
+    GNUNET_free(receiver_s);
+  }
+
   if (th == NULL)
-    th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th,
-                                                 &p1->id,
+    th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th,
+                                                 &ccc->p[0]->id,
                                                  MSIZE,
                                                  TIMEOUT_TRANSMIT,
-                                                 &notify_ready, NULL);
+                                                 &notify_ready,
+                                                 NULL);
 
-  if ( ((p1_switch_attempts >= 1) || (p2_switch_attempts >= 1)) &&
-        (p1_switch_attempts == p1_switch_fail + p1_switch_success) &&
-        (p2_switch_attempts == p2_switch_fail + p2_switch_success) )
+  if ( ( (stats[0].switch_attempts >= 1) ||
+         (stats[1].switch_attempts >= 1) ) &&
+       (stats[0].switch_attempts == stats[0].switch_fail + 
stats[0].switch_success) &&
+       (stats[1].switch_attempts == stats[1].switch_fail + 
stats[1].switch_success) )
   {
     bytes_sent_after_switch += MSIZE;
   }
@@ -518,32 +409,10 @@
 
 
 static void
-notify_connect (void *cls,
-                const struct GNUNET_PeerIdentity *peer)
-{
-  struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Peer %u (`%4s') connected to us!\n",
-              p->no,
-              GNUNET_i2s (peer));
-}
-
-
-static void
 notify_disconnect (void *cls,
-                   const struct GNUNET_PeerIdentity *peer)
+                   struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
+                   const struct GNUNET_PeerIdentity *other)
 {
-  struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
-
-  if (NULL != p1)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Peer %u (`%4s') disconnected early!\n",
-                p->no,
-                GNUNET_i2s (peer));
-    GNUNET_SCHEDULER_shutdown ();
-  }
   if (NULL != th)
   {
     GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
@@ -553,17 +422,6 @@
 
 
 static void
-sendtask ()
-{
-  /* Transmit test messages */
-  th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th,
-                                               &p1->id, MSIZE,
-                                               TIMEOUT_TRANSMIT,
-                                               &notify_ready, NULL);
-}
-
-
-static void
 progress_indicator (void *cls)
 {
   static int counter;
@@ -570,7 +428,7 @@
 
   measure_task = NULL;
   counter++;
-  if ((DURATION.rel_value_us / 1000 / 1000LL) < counter)
+  if ((TIMEOUT.rel_value_us / 1000 / 1000LL) < counter)
   {
     FPRINTF (stderr, "%s", ".\n");
   }
@@ -578,184 +436,73 @@
   {
     FPRINTF (stderr, "%s", ".");
     measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
-                                                 &progress_indicator, NULL);
+                                                 &progress_indicator,
+                                                 NULL);
   }
 }
 
 
 static void
-testing_connect_cb (void *cls)
+connected_cb (void *cls)
 {
-  char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id));
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Peers connected: %u (%s) <-> %u (%s)\n",
-              p1->no, p1_c, p2->no,
-              GNUNET_i2s (&p2->id));
-  GNUNET_free (p1_c);
-
-  cc = NULL;
-  test_connected = GNUNET_YES;
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "(i:s/+/-) \t i == peer 1/2, s/+/- : switch attempt/switch 
ok/switch fail\n");
-
+  for (unsigned int i=0;i<2;i++)
+  {
+    stats[i].stat = GNUNET_STATISTICS_create ("transport",
+                                              ccc->p[i]->cfg);
+    if (NULL == stats[i].stat)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "Fail! Could not create statistics for peers!\n");
+      ccc->global_ret = GNUNET_SYSERR;
+      GNUNET_SCHEDULER_shutdown ();
+      return;
+    }
+    for (unsigned int j=0;NULL != watches[j].stat_name; j++)
+    {
+      GNUNET_STATISTICS_watch (stats[i].stat,
+                               "transport",
+                               watches[j].stat_name,
+                               watches[j].stat_handler,
+                               &stats[i]);
+    }
+  }
   /* Show progress */
+  ccc->global_ret = GNUNET_OK;
   measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
                                                &progress_indicator,
                                                NULL);
   /* Peers are connected, start transmit test messages */
-  GNUNET_SCHEDULER_add_now (&sendtask, NULL);
-}
+  th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th,
+                                               &ccc->p[0]->id, MSIZE,
+                                               TIMEOUT_TRANSMIT,
+                                               &notify_ready, NULL);
 
-
-static void
-start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, void *cls)
-{
-  static int started;
-  started++;
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Peer %u (`%s') started\n",
-              p->no,
-              GNUNET_i2s (&p->id));
-  if (started != 2)
-    return;
-
-  test_connected = GNUNET_NO;
-  sender = p2;
-  receiver = p1;
-
-  char *sender_c = GNUNET_strdup (GNUNET_i2s (&sender->id));
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Test tries to send from %u (%s) -> peer %u (%s)\n",
-              sender->no,
-              sender_c,
-              receiver->no,
-              GNUNET_i2s (&receiver->id));
-  GNUNET_free (sender_c);
-
-  /* Connect the peers */
-  cc = GNUNET_TRANSPORT_TESTING_connect_peers (p1,
-                                               p2,
-                                               &testing_connect_cb,
-                                               NULL);
 }
 
 
-static void
-run (void *cls,
-     char * const *args,
-     const char *cfgfile,
-     const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
-  die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
-
-  p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1,
-      &notify_receive, &notify_connect, &notify_disconnect, &start_cb, NULL);
-
-  p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2,
-      &notify_receive, &notify_connect, &notify_disconnect, &start_cb, NULL);
-
-  if ((p1 == NULL )|| (p2 == NULL))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n");
-    GNUNET_SCHEDULER_shutdown ();
-    return;
-  }
-
-  /* Start to watch statistics for peer 1 */
-  p1_stat = GNUNET_STATISTICS_create ("transport", p1->cfg);
-  GNUNET_STATISTICS_watch (p1_stat, "transport",
-      "# Attempts to switch addresses",
-      stat_start_attempt_cb, p1);
-  GNUNET_STATISTICS_watch (p1_stat, "transport",
-      "# Successful attempts to switch addresses",
-      stat_success_attempt_cb, p1);
-  GNUNET_STATISTICS_watch (p1_stat, "transport",
-      "# Failed attempts to switch addresses (failed to send CONNECT CONT)",
-      stat_fail_attempt_cb, p1);
-  GNUNET_STATISTICS_watch (p1_stat, "transport",
-      "# Failed attempts to switch addresses (failed to send CONNECT)",
-      stat_fail_attempt_cb, p1);
-  GNUNET_STATISTICS_watch (p1_stat, "transport",
-      "# Failed attempts to switch addresses (no response)",
-      stat_fail_attempt_cb, p1);
-  GNUNET_STATISTICS_watch (p1_stat, "transport",
-      "# transport addresses",
-      stat_addresses_available, p1);
-
-  /* Start to watch statistics for peer 2  */
-  p2_stat = GNUNET_STATISTICS_create ("transport", p2->cfg);
-  GNUNET_STATISTICS_watch (p2_stat, "transport",
-      "# Attempts to switch addresses",
-      stat_start_attempt_cb, p2);
-  GNUNET_STATISTICS_watch (p2_stat, "transport",
-      "# Successful attempts to switch addresses",
-      stat_success_attempt_cb, p2);
-  GNUNET_STATISTICS_watch (p2_stat, "transport",
-      "# Failed attempts to switch addresses (failed to send CONNECT CONT)",
-      stat_fail_attempt_cb, p2);
-  GNUNET_STATISTICS_watch (p2_stat, "transport",
-      "# Failed attempts to switch addresses (failed to send CONNECT)",
-      stat_fail_attempt_cb, p2);
-  GNUNET_STATISTICS_watch (p2_stat, "transport",
-      "# Failed attempts to switch addresses (no response)",
-      stat_fail_attempt_cb, p2);
-  GNUNET_STATISTICS_watch (p2_stat, "transport",
-      "# transport addresses",
-      stat_addresses_available, p2);
-
-  if ((p1_stat == NULL )|| (p2_stat == NULL))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Fail! Could not create statistics for peers!\n");
-    GNUNET_SCHEDULER_shutdown ();
-    return;
-  }
-}
-
 int
-main (int argc, char *argv[])
+main (int argc,
+      char *argv[])
 {
-  char *test_plugin;
-  char *test_source;
-  char *test_name;
+  struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
+    .connect_continuation = &connected_cb,
+    .config_file = "test_transport_startonly.conf",
+    .rec = &notify_receive,
+    .nc = &GNUNET_TRANSPORT_TESTING_log_connect,
+    .nd = &notify_disconnect,
+    .shutdown_task = &custom_shutdown,
+    .timeout = TIMEOUT
+  };
+  ccc = &my_ccc;
+  int ret;
 
-  static char *argv_new[] = { "test-transport-address-switch", "-c",
-      "test_transport_startonly.conf", NULL };
-
-  static struct GNUNET_GETOPT_CommandLineOption options[] = {
-      GNUNET_GETOPT_OPTION_END };
-
-  test_name = GNUNET_TRANSPORT_TESTING_get_test_name (argv[0]);
-
-  GNUNET_log_setup (test_name, "WARNING", NULL );
-
-  test_source = GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__);
-  test_plugin = GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0],
-                                                               test_source);
-
-  tth = GNUNET_TRANSPORT_TESTING_init ();
-
-  cfg_file_p1 = GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], 1);
-  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Using cfg [%u] : %s \n", 1, 
cfg_file_p1);
-  cfg_file_p2 = GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], 2);
-  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Using cfg [%u] : %s \n", 2, 
cfg_file_p2);
-
-  GNUNET_PROGRAM_run ((sizeof(argv_new) / sizeof(char *)) - 1, argv_new,
-      test_name, "nohelp", options, &run, NULL );
-
-  GNUNET_free(cfg_file_p1);
-  GNUNET_free(cfg_file_p2);
-
-  GNUNET_free(test_source);
-  GNUNET_free(test_plugin);
-  GNUNET_free(test_name);
-
-  GNUNET_TRANSPORT_TESTING_done (tth);
-
-  return res;
+  ret = GNUNET_TRANSPORT_TESTING_main (2,
+                                       &GNUNET_TRANSPORT_TESTING_connect_check,
+                                       ccc);
+  if (77 == ret)
+    return 77;
+  if (GNUNET_OK != ret)
+    return 1;
+  return 0;
 }
-
 /* end of test_transport_address_switch.c */

Modified: gnunet/src/transport/test_transport_api_disconnect.c
===================================================================
--- gnunet/src/transport/test_transport_api_disconnect.c        2016-07-10 
14:56:13 UTC (rev 37521)
+++ gnunet/src/transport/test_transport_api_disconnect.c        2016-07-10 
14:58:37 UTC (rev 37522)
@@ -21,7 +21,9 @@
  * @file transport/test_transport_api_disconnect.c
  * @brief base test case for transport implementations
  *
- * This test case tests disconnect notifications in peer shutdown
+ * This test case tests disconnect notifications in peer shutdown.
+ * Starts two peers, has them connect, sends a message in between,
+ * stops one peer, expects the others to send a disconnect notification.
  */
 #include "platform.h"
 #include "gnunet_transport_service.h"

Modified: gnunet/src/transport/test_transport_testing_restart.c
===================================================================
--- gnunet/src/transport/test_transport_testing_restart.c       2016-07-10 
14:56:13 UTC (rev 37521)
+++ gnunet/src/transport/test_transport_testing_restart.c       2016-07-10 
14:58:37 UTC (rev 37522)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2009, 2010 GNUnet e.V.
+     Copyright (C) 2009, 2010, 2016 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -21,52 +21,48 @@
  * @file transport/test_transport_testing_restart.c
  * @brief test case for transport testing library:
  * start the peer, get the HELLO message, restart and stop the peer
- *
  */
 #include "platform.h"
 #include "gnunet_transport_service.h"
 #include "transport-testing.h"
 
-/**
- * How long until we give up on transmitting the message?
- */
 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
 
-struct GNUNET_SCHEDULER_Task * timeout_task;
 
+static struct GNUNET_SCHEDULER_Task *timeout_task;
+
 static struct GNUNET_TRANSPORT_TESTING_PeerContext *p;
 
-struct GNUNET_TRANSPORT_TESTING_Handle *tth;
+static struct GNUNET_TRANSPORT_TESTING_Handle *tth;
 
-static int ret = 0;
+static int ret;
 
+
 static void
 end ()
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n");
-
-  if (timeout_task != NULL)
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Stopping peers\n");
+  if (NULL != timeout_task)
     GNUNET_SCHEDULER_cancel (timeout_task);
-
-  GNUNET_TRANSPORT_TESTING_stop_peer (p);
-  GNUNET_TRANSPORT_TESTING_done (tth);
+  if (NULL != p)
+    GNUNET_TRANSPORT_TESTING_stop_peer (p);
+  if (NULL != tth)
+    GNUNET_TRANSPORT_TESTING_done (tth);
 }
 
+
 static void
 end_badly ()
 {
   timeout_task = NULL;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n");
-
-  if (NULL != p)
-    GNUNET_TRANSPORT_TESTING_stop_peer (p);
-
-  if (NULL != tth)
-    GNUNET_TRANSPORT_TESTING_done (tth);
-
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+              "Timeout!\n");
+  end ();
   ret = GNUNET_SYSERR;
 }
 
+
 static void
 restart_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p,
             void *cls)
@@ -76,7 +72,7 @@
               p->no,
               GNUNET_i2s (&p->id));
   ret = 0;
-  GNUNET_SCHEDULER_add_now (&end, NULL);
+  end ();
 }
 
 
@@ -84,7 +80,7 @@
 restart_task ()
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Peer %u (`%s') restarting, \n",
+              "Peer %u (`%s') restarting\n",
               p->no,
               GNUNET_i2s (&p->id));
   GNUNET_TRANSPORT_TESTING_restart_peer (p,
@@ -94,18 +90,22 @@
 
 
 static void
-start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, void *cls)
+start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p,
+          void *cls)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') successfully started\n",
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Peer %u (`%s') successfully started\n",
               p->no,
               GNUNET_i2s (&p->id));
-
-  GNUNET_SCHEDULER_add_now (&restart_task, NULL);
+  GNUNET_SCHEDULER_add_now (&restart_task,
+                            NULL);
 }
 
 
 static void
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
+     char *const *args,
+     const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   ret = 1;
@@ -112,8 +112,8 @@
   tth = GNUNET_TRANSPORT_TESTING_init ();
   GNUNET_assert (NULL != tth);
 
-  timeout_task =
-      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
+  timeout_task
+    = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
                                     &end_badly,
                                     NULL);
   p = GNUNET_TRANSPORT_TESTING_start_peer(tth,
@@ -126,33 +126,37 @@
                                           NULL); /* closure */
   if (NULL == p)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start peer\n");
-    if (timeout_task != NULL)
-      GNUNET_SCHEDULER_cancel (timeout_task);
-    timeout_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Failed to start peer\n");
+    end ();
+    ret = 1;
   }
 }
 
+
 int
-main (int argc, char *argv[])
+main (int argc,
+      char *argv[])
 {
-  GNUNET_log_setup ("test_transport_testing_restart",
-                    "WARNING",
-                    NULL);
-
   char *const argv_1[] = { "test_transport_testing_restart",
     "-c",
     "test_transport_api_data.conf",
     NULL
   };
-
   struct GNUNET_GETOPT_CommandLineOption options[] = {
     GNUNET_GETOPT_OPTION_END
   };
 
-  GNUNET_PROGRAM_run ((sizeof (argv_1) / sizeof (char *)) - 1, argv_1,
-                      "test_transport_testing_restart", "nohelp", options, 
&run, &ret);
-
+  GNUNET_log_setup ("test_transport_testing_restart",
+                    "WARNING",
+                    NULL);
+  GNUNET_PROGRAM_run ((sizeof (argv_1) / sizeof (char *)) - 1,
+                      argv_1,
+                      "test_transport_testing_restart",
+                      "nohelp",
+                      options,
+                      &run,
+                      NULL);
   return ret;
 }
 

Modified: gnunet/src/transport/test_transport_testing_startstop.c
===================================================================
--- gnunet/src/transport/test_transport_testing_startstop.c     2016-07-10 
14:56:13 UTC (rev 37521)
+++ gnunet/src/transport/test_transport_testing_startstop.c     2016-07-10 
14:58:37 UTC (rev 37522)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2009, 2010 GNUnet e.V.
+     Copyright (C) 2009, 2010, 2016 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -21,67 +21,65 @@
  * @file transport/test_transport_testing_startstop.c
  * @brief test case for transport testing library:
  * start the peer, get the HELLO message and stop the peer
- *
  */
 #include "platform.h"
 #include "gnunet_transport_service.h"
 #include "transport-testing.h"
 
-/**
- * How long until we give up on transmitting the message?
- */
 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
 
-struct GNUNET_SCHEDULER_Task * timeout_task;
 
+static struct GNUNET_SCHEDULER_Task *timeout_task;
+
 static struct GNUNET_TRANSPORT_TESTING_PeerContext *p;
 
-struct GNUNET_TRANSPORT_TESTING_Handle *tth;
+static struct GNUNET_TRANSPORT_TESTING_Handle *tth;
 
-static int ret = 0;
+static int ret;
 
+
 static void
 end ()
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n");
-
-  if (timeout_task != NULL)
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Stopping peers\n");
+  if (NULL != timeout_task)
     GNUNET_SCHEDULER_cancel (timeout_task);
-
-  GNUNET_TRANSPORT_TESTING_stop_peer (p);
-  GNUNET_TRANSPORT_TESTING_done (tth);
+  if (NULL != p)
+    GNUNET_TRANSPORT_TESTING_stop_peer (p);
+  if (NULL != tth)
+    GNUNET_TRANSPORT_TESTING_done (tth);
 }
 
+
 static void
 end_badly ()
 {
   timeout_task = NULL;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n");
-
-  if (NULL != p)
-    GNUNET_TRANSPORT_TESTING_stop_peer (p);
-
-  if (NULL != tth)
-    GNUNET_TRANSPORT_TESTING_done (tth);
-
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+              "Timeout!\n");
+  end ();
   ret = GNUNET_SYSERR;
 }
 
 
 static void
-start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, void *cls)
+start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p,
+          void *cls)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') successfully started\n",
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Peer %u (`%s') successfully started\n",
               p->no,
               GNUNET_i2s (&p->id));
-
   ret = 0;
-  GNUNET_SCHEDULER_add_now (&end, NULL);
+  end ();
 }
 
 
 static void
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
+     char *const *args,
+     const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   ret = 1;
@@ -110,25 +108,28 @@
   }
 }
 
+
 int
 main (int argc, char *argv[])
 {
-  GNUNET_log_setup ("test_transport_testing_startstop",
-                    "WARNING",
-                    NULL);
-
   char *const argv_1[] = { "test_transport_testing",
     "-c",
     "test_transport_api_data.conf",
     NULL
   };
-
   struct GNUNET_GETOPT_CommandLineOption options[] = {
     GNUNET_GETOPT_OPTION_END
   };
 
-  GNUNET_PROGRAM_run ((sizeof (argv_1) / sizeof (char *)) - 1, argv_1,
-                      "test_transport_testing_startstop", "nohelp", options, 
&run, &ret);
+  GNUNET_log_setup ("test_transport_testing_startstop",
+                    "WARNING",
+                    NULL);
+  GNUNET_PROGRAM_run ((sizeof (argv_1) / sizeof (char *)) - 1,
+                      argv_1,
+                      "test_transport_testing_startstop", "nohelp",
+                      options,
+                      &run,
+                      &ret);
 
   return ret;
 }

Modified: gnunet/src/transport/transport-testing-main.c
===================================================================
--- gnunet/src/transport/transport-testing-main.c       2016-07-10 14:56:13 UTC 
(rev 37521)
+++ gnunet/src/transport/transport-testing-main.c       2016-07-10 14:58:37 UTC 
(rev 37522)
@@ -113,7 +113,8 @@
   struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls;
 
   ccc->timeout_task = NULL;
-  GNUNET_break (0); /* signal timeout */
+  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+              "Testcase timed out\n");
   ccc->global_ret = GNUNET_SYSERR;
   GNUNET_SCHEDULER_shutdown ();
 }

Modified: gnunet/src/transport/transport-testing.c
===================================================================
--- gnunet/src/transport/transport-testing.c    2016-07-10 14:56:13 UTC (rev 
37521)
+++ gnunet/src/transport/transport-testing.c    2016-07-10 14:58:37 UTC (rev 
37522)
@@ -637,6 +637,8 @@
   struct GNUNET_TRANSPORT_TESTING_PeerContext *p;
   struct GNUNET_TRANSPORT_TESTING_PeerContext *t;
 
+  if (NULL == tth)
+    return;
   cc = tth->cc_head;
   while (NULL != cc)
   {




reply via email to

[Prev in Thread] Current Thread [Next in Thread]