stuff
[oweals/gnunet.git] / src / transport / test_transport_api_reliability.c
index 7fc9d43b4e7eb0637f5ed9ef15efa633dae1063d..32697e52c4537f9c48197ffdf6c199887b27162b 100644 (file)
@@ -49,7 +49,7 @@
  * 'MAX_PENDING' in 'gnunet-service-transport.c', otherwise
  * messages may be dropped even for a reliable transport.
  */
-#define TOTAL_MSGS (10000 * 2)
+#define TOTAL_MSGS (1024 * 2)
 
 /**
  * How long until we give up on transmitting the message?
@@ -80,6 +80,8 @@ static int is_wlan;
 
 static int connected;
 
+static int test_failed;
+
 static unsigned long long total_bytes;
 
 static struct GNUNET_TIME_Absolute start_time;
@@ -163,14 +165,18 @@ stop_arm (struct PeerContext *p)
 
 static void
 end_badly (void *cls,
-          const struct GNUNET_SCHEDULER_TaskContext *tc)
+           const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-             "Reliability failed: Last message sent %u, Next message scheduled %u, Last message received %u, Message expected %u\n",
-             msg_sent, 
-             msg_scheduled, 
-             msg_recv, 
-             msg_recv_expected);
+  if (test_failed == GNUNET_NO)
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Testcase timeout\n");
+    else
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+              "Reliability failed: Last message sent %u, Next message scheduled %u, Last message received %u, Message expected %u\n",
+              msg_sent,
+              msg_scheduled,
+              msg_recv,
+              msg_recv_expected);
   if (th_p2 != NULL)
     GNUNET_TRANSPORT_notify_transmit_ready_cancel(th_p2);
   th_p2 = NULL;
@@ -187,6 +193,7 @@ end_badly (void *cls,
 }
 
 
+
 struct TestMessage
 {
   struct GNUNET_MessageHeader header;
@@ -199,8 +206,6 @@ get_size (unsigned int iter)
 {
   unsigned int ret;
 
-  if (iter < 60000)
-    return iter + sizeof (struct TestMessage);
   ret = (iter * iter * iter);
   return sizeof (struct TestMessage) + (ret % 60000);
 }
@@ -233,6 +238,7 @@ notify_receive (void *cls,
                  ntohl (hdr->num));
       if (die_task != GNUNET_SCHEDULER_NO_TASK)
         GNUNET_SCHEDULER_cancel (die_task);
+      test_failed = GNUNET_YES;
       die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
       return;
     }
@@ -245,6 +251,7 @@ notify_receive (void *cls,
                  ntohl (hdr->num));
       if (die_task != GNUNET_SCHEDULER_NO_TASK)
         GNUNET_SCHEDULER_cancel (die_task);
+      test_failed = GNUNET_YES;
       die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
       return;
     }
@@ -258,6 +265,7 @@ notify_receive (void *cls,
                  n, (unsigned char) n);
       if (die_task != GNUNET_SCHEDULER_NO_TASK)
         GNUNET_SCHEDULER_cancel (die_task);
+      test_failed = GNUNET_YES;
       die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
       return;
     }
@@ -362,7 +370,10 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
              GNUNET_i2s (peer), cls);
 #endif
   if (th_p2 != NULL)
-    GNUNET_TRANSPORT_notify_transmit_ready_cancel(th_p2);
+    {
+      GNUNET_TRANSPORT_notify_transmit_ready_cancel(th_p2);
+      th_p2 = NULL;
+    }
 }
 
 
@@ -372,11 +383,11 @@ exchange_hello_last (void *cls,
 {
   struct PeerContext *me = cls;
 
+  GNUNET_assert (message != NULL);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Exchanging HELLO of size %d with peer (%s)!\n", 
              (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message),
              GNUNET_i2s (&me->id));
-  GNUNET_assert (message != NULL);
   GNUNET_assert (GNUNET_OK ==
                  GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
                                       message, &me->id));
@@ -464,8 +475,13 @@ setup_peer (struct PeerContext *p, const char *cfgname)
   p->cfg = GNUNET_CONFIGURATION_create ();
   GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
   if (GNUNET_CONFIGURATION_have_value (p->cfg,"PATHS", "SERVICEHOME"))
-      GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", "SERVICEHOME", &p->servicehome);
-  GNUNET_DISK_directory_remove (p->servicehome);
+    {
+      GNUNET_assert (GNUNET_OK ==
+                    GNUNET_CONFIGURATION_get_value_string (p->cfg, 
+                                                           "PATHS", "SERVICEHOME",
+                                                           &p->servicehome));
+      GNUNET_DISK_directory_remove (p->servicehome);
+    }
 
 #if START_ARM
   p->arm_proc = GNUNET_OS_start_process (NULL, NULL,
@@ -828,8 +844,6 @@ check ()
     GNUNET_free(key_file_p2);
     GNUNET_free(cert_file_p1);
     GNUNET_free(cert_file_p2);
-    GNUNET_free(p1.servicehome);
-    GNUNET_free(p2.servicehome);
   }
 
   return ok;
@@ -840,9 +854,8 @@ int
 main (int argc, char *argv[])
 {
   int ret;
-#ifdef MINGW
-  return GNUNET_SYSERR;
-#endif
+
+  test_failed = GNUNET_NO;
 
   if (strstr(argv[0], "tcp_nat") != NULL)
     {
@@ -886,8 +899,16 @@ main (int argc, char *argv[])
 #endif
                     NULL);
   ret = check ();
-  GNUNET_DISK_directory_remove (p1.servicehome);
-  GNUNET_DISK_directory_remove (p2.servicehome);
+  if (p1.servicehome != NULL)
+    {
+      GNUNET_DISK_directory_remove (p1.servicehome);
+      GNUNET_free (p1.servicehome);
+    }
+  if (p2.servicehome != NULL)
+    {   
+      GNUNET_DISK_directory_remove (p2.servicehome);
+      GNUNET_free (p2.servicehome);
+    }
   return ret;
 }