removing fprintfs -- with bad %fmt statements giving warnings
[oweals/gnunet.git] / src / transport / test_quota_compliance.c
index 77279897d3109e73b4a8a8b41fb65fa8657a4492..e4b728007a0f727a69aafd703ac166954d02f605 100644 (file)
@@ -42,7 +42,7 @@
 #define DEBUG_MEASUREMENT GNUNET_NO
 #define DEBUG_CONNECTIONS GNUNET_NO
 
-#define MEASUREMENT_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2)
+#define MEASUREMENT_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
 #define MEASUREMENT_MSG_SIZE 1024
 #define MEASUREMENT_MSG_SIZE_BIG 32768
 #define MEASUREMENT_MAX_QUOTA 1024 * 1024 * 1024
@@ -121,8 +121,6 @@ static struct PeerContext p1;
 
 static struct PeerContext p2;
 
-static struct GNUNET_SCHEDULER_Handle *sched;
-
 static int ok;
 
 static int connected;
@@ -165,20 +163,21 @@ end_send ()
 static void
 end ()
 {
-  GNUNET_SCHEDULER_cancel (sched, die_task);
+  GNUNET_SCHEDULER_cancel (die_task);
   die_task = GNUNET_SCHEDULER_NO_TASK;
 
   if (measurement_task != GNUNET_SCHEDULER_NO_TASK)
   {
-           GNUNET_SCHEDULER_cancel (sched, measurement_task);
+           GNUNET_SCHEDULER_cancel (measurement_task);
            measurement_task = GNUNET_SCHEDULER_NO_TASK;
   }
   if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK)
   {
-           GNUNET_SCHEDULER_cancel (sched, measurement_counter_task);
+           GNUNET_SCHEDULER_cancel (measurement_counter_task);
            measurement_counter_task = GNUNET_SCHEDULER_NO_TASK;
   }
-  GNUNET_SCHEDULER_shutdown (sched);
+  fprintf(stderr,"\n");
+  GNUNET_SCHEDULER_shutdown ();
 #if DEBUG_CONNECTIONS
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n");
 #endif
@@ -188,7 +187,7 @@ end ()
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Transports disconnected, returning success!\n");
 #endif
-  GNUNET_SCHEDULER_shutdown (sched);
+  GNUNET_SCHEDULER_shutdown ();
 }
 
 
@@ -213,12 +212,12 @@ end_badly (void *cls,
 {
   if (measurement_task != GNUNET_SCHEDULER_NO_TASK)
   {
-           GNUNET_SCHEDULER_cancel (sched, measurement_task);
+           GNUNET_SCHEDULER_cancel (measurement_task);
            measurement_task = GNUNET_SCHEDULER_NO_TASK;
   }
   if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK)
   {
-           GNUNET_SCHEDULER_cancel (sched, measurement_counter_task);
+           GNUNET_SCHEDULER_cancel (measurement_counter_task);
            measurement_counter_task = GNUNET_SCHEDULER_NO_TASK;
   }
   GNUNET_break (0);
@@ -245,8 +244,7 @@ static void
 notify_receive_new (void *cls,
                 const struct GNUNET_PeerIdentity *peer,
                 const struct GNUNET_MessageHeader *message,
-                struct GNUNET_TIME_Relative latency,
-               uint32_t distance)
+                const struct GNUNET_TRANSPORT_ATS_Information *ats, uint32_t ats_count)
 {
   unsigned int s;
   const struct TestMessage *hdr;
@@ -352,11 +350,8 @@ static void measurement_counter
   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
        return;
 
-#if VERBOSE
   fprintf(stderr,".");
-#endif
-  measurement_counter_task = GNUNET_SCHEDULER_add_delayed (sched,
-                                                          GNUNET_TIME_UNIT_SECONDS,
+  measurement_counter_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
                                                           &measurement_counter,
                                                           NULL);
 }
@@ -379,12 +374,9 @@ measurement_end (void *cls,
 
   if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK)
   {
-    GNUNET_SCHEDULER_cancel (sched, measurement_counter_task);
+    GNUNET_SCHEDULER_cancel (measurement_counter_task);
     measurement_counter_task = GNUNET_SCHEDULER_NO_TASK;
   }
-#if VERBOSE
-  fprintf(stderr,"\n");
-#endif
 
   if (transmit_handle != NULL)
   {
@@ -403,6 +395,23 @@ measurement_end (void *cls,
   else
          delta = (quota_allowed/10);
 
+  /* Throughput is far too slow. This is to prevent the test to exit with success when throughput is 0 */
+  if ((total_bytes_sent/(duration.rel_value / 1000)) < 100)
+  {
+         GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                         "\nQuota compliance failed: \n"\
+                         "Hard quota limit allowed: %10llu kB/s (%llu B/s)\n"\
+                         "Soft quota limit allowed: %10llu kB/s (%llu B/s)\n"\
+                         "Throughput              : %10llu kB/s (%llu B/s)\n",
+                         (quota_allowed / (1024)), quota_allowed,
+                         ((quota_allowed+delta) / (1024)),  quota_allowed+delta,
+                         (total_bytes_sent/(duration.rel_value / 1000)/1024),
+                         total_bytes_sent/(duration.rel_value / 1000));
+         ok = 1;
+         end();
+  }
+
+  /* Throughput is bigger than allowed quota + some extra*/
   if ((total_bytes_sent/(duration.rel_value / 1000)) > (quota_allowed + delta))
   {
          GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -498,19 +507,16 @@ static void measure (unsigned long long quota_p1, unsigned long long quota_p2 )
                          GNUNET_TIME_UNIT_FOREVER_REL,
                          NULL, NULL);
 
-               GNUNET_SCHEDULER_cancel (sched, die_task);
-               die_task = GNUNET_SCHEDULER_add_delayed (sched,
-                                                  TIMEOUT,
+               GNUNET_SCHEDULER_cancel (die_task);
+               die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
                                                   &end_badly,
                                                   NULL);
                if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK)
-                 GNUNET_SCHEDULER_cancel (sched, measurement_counter_task);
-               measurement_counter_task = GNUNET_SCHEDULER_add_delayed (sched,
-                                                                  GNUNET_TIME_UNIT_SECONDS,
+                 GNUNET_SCHEDULER_cancel (measurement_counter_task);
+               measurement_counter_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
                                                                   &measurement_counter,
                                                                   NULL);
-               measurement_task = GNUNET_SCHEDULER_add_delayed (sched,
-                                                  MEASUREMENT_INTERVALL,
+               measurement_task = GNUNET_SCHEDULER_add_delayed (MEASUREMENT_INTERVALL,
                                                   &measurement_end,
                                                   NULL);
                total_bytes_sent = 0;
@@ -531,8 +537,7 @@ static void measure (unsigned long long quota_p1, unsigned long long quota_p2 )
 static void
 notify_connect (void *cls,
                 const struct GNUNET_PeerIdentity *peer,
-                struct GNUNET_TIME_Relative latency,
-               uint32_t distance)
+                const struct GNUNET_TRANSPORT_ATS_Information *ats, uint32_t ats_count)
 {
   if (cls == &p1)
     {
@@ -588,7 +593,7 @@ setup_peer (struct PeerContext *p, const char *cfgname)
 #endif
 
   GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
-  p->th = GNUNET_TRANSPORT_connect (sched, p->cfg, NULL,
+  p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL,
                                     p,
                                     &notify_receive_new,
                                     &notify_connect,
@@ -634,16 +639,13 @@ exchange_hello (void *cls,
 
 static void
 run (void *cls,
-     struct GNUNET_SCHEDULER_Handle *s,
      char *const *args,
      const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   GNUNET_assert (ok == 1);
   OKPP;
-  sched = s;
 
-  die_task = GNUNET_SCHEDULER_add_delayed (sched,
-                                          TIMEOUT,
+  die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
                                           &end_badly,
                                           NULL);
   measurement_running = GNUNET_NO;
@@ -791,6 +793,10 @@ main (int argc, char *argv[])
          else
                  GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","https","symmetric");
   }
+
+  GNUNET_DISK_directory_remove ("/tmp/test_quota_compliance_peer1");
+  GNUNET_DISK_directory_remove ("/tmp/test_quota_compliance_peer2");
+
   fprintf(stderr,  "Running `%s'\n", logger);
   GNUNET_log_setup ("test-quota-compliance",
 #if VERBOSE