Quota compliance testcases should ready to be commited...
authorMatthias Wachs <wachs@net.in.tum.de>
Wed, 17 Nov 2010 15:58:30 +0000 (15:58 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Wed, 17 Nov 2010 15:58:30 +0000 (15:58 +0000)
src/core/Makefile.am
src/core/core.h
src/core/test_core_api.c
src/core/test_core_quota_compliance.c
src/core/test_core_quota_peer1.conf
src/core/test_core_quota_peer2.conf

index 0b8a34ff960811a264915b20949baeedf4d87607..de96167379af44a2e1546a046776ce82c8cb136c 100644 (file)
@@ -36,12 +36,14 @@ gnunet_service_core_LDADD = \
   $(top_builddir)/src/transport/libgnunettransport.la \
   $(top_builddir)/src/util/libgnunetutil.la \
   $(GN_LIBINTL)
-
-
+  
 check_PROGRAMS = \
  test_core_api_start_only \
  test_core_api \
- test_core_api_reliability
+ test_core_api_reliability \
+ test_core_quota_compliance_symmetric \
+ test_core_quota_compliance_asymmetric_send_limited \
+ test_core_quota_compliance_asymmetric_recv_limited
 
 if !DISABLE_TEST_RUN
 TESTS = $(check_PROGRAMS)
@@ -65,8 +67,31 @@ test_core_api_start_only_SOURCES = \
  test_core_api_start_only.c
 test_core_api_start_only_LDADD = \
  $(top_builddir)/src/core/libgnunetcore.la \
- $(top_builddir)/src/util/libgnunetutil.la  
+ $(top_builddir)/src/util/libgnunetutil.la
+test_core_quota_compliance_symmetric_SOURCES = \
+ test_core_quota_compliance.c
+test_core_quota_compliance_symmetric_LDADD = \
+ $(top_builddir)/src/core/libgnunetcore.la \
+ $(top_builddir)/src/transport/libgnunettransport.la \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/statistics/libgnunetstatistics.la
 
+test_core_quota_compliance_asymmetric_send_limited_SOURCES = \
+ test_core_quota_compliance.c
+test_core_quota_compliance_asymmetric_send_limited_LDADD = \
+ $(top_builddir)/src/core/libgnunetcore.la \
+ $(top_builddir)/src/transport/libgnunettransport.la \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/statistics/libgnunetstatistics.la
+
+test_core_quota_compliance_asymmetric_recv_limited_SOURCES = \
+ test_core_quota_compliance.c
+test_core_quota_compliance_asymmetric_recv_limited_LDADD = \
+ $(top_builddir)/src/core/libgnunetcore.la \
+ $(top_builddir)/src/transport/libgnunettransport.la \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/statistics/libgnunetstatistics.la
 
 EXTRA_DIST = \
   test_core_api_data.conf \
index 6fd595b8b7a6df48e1a4b54450be587de10cb44e..a8d90b81a6b50ce13671d48e06d0c7cca2d96550 100644 (file)
 /**
  * General core debugging.
  */
-#define DEBUG_CORE GNUNET_YES
+#define DEBUG_CORE GNUNET_NO
 
 /**
  * Debugging interaction core-clients.
  */
-#define DEBUG_CORE_CLIENT GNUNET_YES
+#define DEBUG_CORE_CLIENT GNUNET_NO
 
 /**
  * Definition of bits in the InitMessage's options field that specify
index f153cb5eb95cbf7a30bb39ca0b17d0970df4cdbb..814ebe889e8f0a513ee8b9a530718ec43d10075d 100644 (file)
@@ -35,7 +35,6 @@
 #include "gnunet_transport_service.h"
 
 #define VERBOSE GNUNET_NO
-
 #define START_ARM GNUNET_YES
 
 #define MTYPE 12345
@@ -319,7 +318,6 @@ run (void *cls,
                        GNUNET_YES, &outbound_notify, GNUNET_YES, handlers);
 }
 
-
 static void
 stop_arm (struct PeerContext *p)
 {
index a54cf4e0b1bc560e5c5c63aa6ea37593e8da33fc..efdcefac5fc0ba08e1f659802289f2818944955a 100644 (file)
@@ -34,8 +34,9 @@
 #include "gnunet_program_lib.h"
 #include "gnunet_scheduler_lib.h"
 #include "gnunet_transport_service.h"
+#include "gnunet_statistics_service.h"
 
-#define VERBOSE GNUNET_YES
+#define VERBOSE GNUNET_NO
 #define DEBUG_TRANSMISSION GNUNET_NO
 
 #define SYMMETRIC 0
@@ -84,6 +85,7 @@ struct PeerContext
   struct GNUNET_PeerIdentity id;   
   struct GNUNET_TRANSPORT_Handle *th;
   struct GNUNET_MessageHeader *hello;
+  struct GNUNET_STATISTICS_Handle *stats;
   int connect_status;
 #if START_ARM
   struct GNUNET_OS_Process *arm_proc;
@@ -151,6 +153,37 @@ terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   ok = 42;
 }
 
+
+/**
+ * Callback function to process statistic values.
+ *
+ * @param cls closure
+ * @param subsystem name of subsystem that created the statistic
+ * @param name the name of the datum
+ * @param value the current value
+ * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
+ * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
+ */
+static int
+print_stat (void *cls,
+           const char *subsystem,
+           const char *name,
+           uint64_t value,
+           int is_persistent)
+{
+  if (cls==&p1)
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+          "Peer1 %50s = %12llu\n",
+          name,
+          (unsigned long long) value);
+  if (cls==&p2)
+         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "Peer2 %50s = %12llu\n",
+                  name,
+                  (unsigned long long) value);
+  return GNUNET_OK;
+}
+
 static void
 measurement_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
@@ -185,33 +218,86 @@ measurement_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
          quota_delta = max_quota_out / 10;
 
   if ((throughput_out < (max_quota_out/1024)) && (throughput_out < (max_quota_in/1024)))
-  {
          ok = 0;
-  }
   else
-  {
          ok = 1;
+
+  GNUNET_STATISTICS_get (p1.stats,
+                    "core",
+                    "# discarded CORE_SEND requests",
+                    GNUNET_TIME_UNIT_FOREVER_REL,
+                    NULL,
+                    &print_stat, &p1);
+
+  GNUNET_STATISTICS_get (p1.stats,
+                    "core",
+                    "# discarded CORE_SEND request bytes",
+                    GNUNET_TIME_UNIT_FOREVER_REL,
+                    NULL,
+                    &print_stat, &p1);
+  GNUNET_STATISTICS_get (p1.stats,
+                    "core",
+                    "# discarded lower priority CORE_SEND requests",
+                    GNUNET_TIME_UNIT_FOREVER_REL,
+                    NULL,
+                    &print_stat, NULL);
+  GNUNET_STATISTICS_get (p1.stats,
+                    "core",
+                    "# discarded lower priority CORE_SEND request bytes",
+                    GNUNET_TIME_UNIT_FOREVER_REL,
+                    NULL,
+                    &print_stat, &p1);
+  GNUNET_STATISTICS_get (p2.stats,
+                    "core",
+                    "# discarded CORE_SEND requests",
+                    GNUNET_TIME_UNIT_FOREVER_REL,
+                    NULL,
+                    &print_stat, &p2);
+
+  GNUNET_STATISTICS_get (p2.stats,
+                    "core",
+                    "# discarded CORE_SEND request bytes",
+                    GNUNET_TIME_UNIT_FOREVER_REL,
+                    NULL,
+                    &print_stat, &p2);
+  GNUNET_STATISTICS_get (p2.stats,
+                    "core",
+                    "# discarded lower priority CORE_SEND requests",
+                    GNUNET_TIME_UNIT_FOREVER_REL,
+                    NULL,
+                    &print_stat, &p2);
+  GNUNET_STATISTICS_get (p2.stats,
+                    "core",
+                    "# discarded lower priority CORE_SEND request bytes",
+                    GNUNET_TIME_UNIT_FOREVER_REL,
+                    NULL,
+                    &print_stat, &p2);
+
+  enum GNUNET_ErrorType kind = GNUNET_ERROR_TYPE_DEBUG;
+  if (ok==1)
+  {
+         kind = GNUNET_ERROR_TYPE_ERROR;
   }
   switch (test)
   {
   case SYMMETRIC:
-         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Core quota compliance test with symmetric quotas\n");
+         GNUNET_log (kind,"Core quota compliance test with symmetric quotas: %s\n", (ok==0)?"PASSED":"FAILED");
          break;
   case ASYMMETRIC_SEND_LIMITED:
-         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Core quota compliance test with limited sender quota\n",throughput_in,total_bytes_recv, delta/1000);
+         GNUNET_log (kind,"Core quota compliance test with limited sender quota: %s\n", (ok==0)?"PASSED":"FAILED");
          break;
-         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Core quota compliance test with limited receiver quota\n",throughput_in,total_bytes_recv, delta/1000);
   case ASYMMETRIC_RECV_LIMITED:
+         GNUNET_log (kind,"Core quota compliance test with limited receiver quota: %s\n", (ok==0)?"PASSED":"FAILED");
          break;
   };
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Peer 1 send    rate: %llu kB/s (%llu Bytes in %u sec.)\n",throughput_out,total_bytes_sent, delta/1000);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Peer 2 receive rate: %llu kB/s (%llu Bytes in %u sec.)\n",throughput_in,total_bytes_recv, delta/1000);
-
-
+  GNUNET_log (kind,"Peer 1 send  rate: %llu kB/s (%llu Bytes in %u sec.)\n",throughput_out,total_bytes_sent, delta/1000);
+  GNUNET_log (kind,"Peer 1 send quota: %llu kB/s\n",current_quota_p1_out / 1024);
+  GNUNET_log (kind,"Peer 2 receive  rate: %llu kB/s (%llu Bytes in %u sec.)\n",throughput_in,total_bytes_recv, delta/1000);
+  GNUNET_log (kind,"Peer 2 receive quota: %llu kB/s\n",current_quota_p2_in / 1024);
+/*
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. inbound  quota allowed: %llu kB/s\n",max_quota_in /1024);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. outbound quota allowed: %llu kB/s\n",max_quota_out/1024);
-
+*/
   GNUNET_SCHEDULER_cancel (err_task);
   GNUNET_SCHEDULER_add_now (&terminate_task, NULL);
 
@@ -293,6 +379,7 @@ connect_notify (void *cls,
                   "Asking core (1) for transmission to peer `%4s'\n",
                   GNUNET_i2s (&p2.id));
 #endif
+      if (err_task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (err_task);
       err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
                                      &terminate_task_error,
                                      NULL);
@@ -515,6 +602,8 @@ setup_peer (struct PeerContext *p, const char *cfgname)
                                         "-c", cfgname, NULL);
 #endif
   GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
+  p->stats = GNUNET_STATISTICS_create ("core",p->cfg);
+  GNUNET_assert (p->stats!=NULL);
   p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL);
   GNUNET_assert (p->th != NULL);
   GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p);
@@ -529,6 +618,9 @@ run (void *cls,
 {
   GNUNET_assert (ok == 1);
   OKPP;
+  err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+                             &terminate_task_error,
+                             NULL);
   if (test == SYMMETRIC)
     {
       setup_peer (&p1, "test_core_quota_peer1.conf");
@@ -640,8 +732,6 @@ main (int argc, char *argv[])
                     "WARNING",
 #endif
                     NULL);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "argv[0] %s",argv[0]);
   ret = check ();
   GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1");
   GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2");
index 492a41b9de793226b0af4b86fd420d9565192929..5c0f853f196306e248efa2955f025dfebb7fbcc6 100644 (file)
@@ -1,6 +1,6 @@
 [PATHS]
-SERVICEHOME = /tmp/test-gnunet-core-peer-1/
-DEFAULTCONFIG = test_core_api_peer1.conf
+SERVICEHOME = /tmp/test-gnunet-core-quote-peer-1/
+DEFAULTCONFIG = test_core_quota_peer1.conf
 
 [resolver]
 PORT = 12464
@@ -50,8 +50,7 @@ UNIXPATH = /tmp/gnunet-p1-service-core.sock
 #OPTIONS = -l log-core-1
 #PREFIX = xterm -e xterm -T core1 -e gdb --args
 #PREFIX = xterm -T core1 -e 
-#DEBUG = YES
-#BINARY=/home/grothoff/bin/gnunet-service-core
+DEBUG = NO
 
 [testing]
 WEAKRANDOM = YES
index d9820ed1d06da9ea97cd5266f02aabef11c86300..26f8e72f51310f2d071a64cd8e6cd4341d147dcf 100644 (file)
@@ -1,5 +1,5 @@
 [PATHS]
-SERVICEHOME = /tmp/test-gnunet-core-peer-2/
+SERVICEHOME = /tmp/test-gnunet-core-quote-peer-2/
 DEFAULTCONFIG = test_core_api_peer2.conf
 
 [resolver]
@@ -49,7 +49,7 @@ TOTAL_QUOTA_OUT = 10240
 UNIXPATH = /tmp/gnunet-p2-service-core.sock
 #PREFIX = xterm -T core2 -e
 #PREFIX = valgrind --tool=memcheck
-#DEBUG = YES
+DEBUG = NO
 #BINARY=/home/grothoff/bin/gnunet-service-core
 
 [testing]