From 8d1e110fce531925bf66a70722198081370799cd Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Wed, 17 Nov 2010 15:58:30 +0000 Subject: [PATCH] Quota compliance testcases should ready to be commited... --- src/core/Makefile.am | 33 ++++++- src/core/core.h | 4 +- src/core/test_core_api.c | 2 - src/core/test_core_quota_compliance.c | 120 ++++++++++++++++++++++---- src/core/test_core_quota_peer1.conf | 7 +- src/core/test_core_quota_peer2.conf | 4 +- 6 files changed, 141 insertions(+), 29 deletions(-) diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 0b8a34ff9..de9616737 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -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 \ diff --git a/src/core/core.h b/src/core/core.h index 6fd595b8b..a8d90b81a 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -41,12 +41,12 @@ /** * 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 diff --git a/src/core/test_core_api.c b/src/core/test_core_api.c index f153cb5eb..814ebe889 100644 --- a/src/core/test_core_api.c +++ b/src/core/test_core_api.c @@ -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) { diff --git a/src/core/test_core_quota_compliance.c b/src/core/test_core_quota_compliance.c index a54cf4e0b..efdcefac5 100644 --- a/src/core/test_core_quota_compliance.c +++ b/src/core/test_core_quota_compliance.c @@ -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"); diff --git a/src/core/test_core_quota_peer1.conf b/src/core/test_core_quota_peer1.conf index 492a41b9d..5c0f853f1 100644 --- a/src/core/test_core_quota_peer1.conf +++ b/src/core/test_core_quota_peer1.conf @@ -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 diff --git a/src/core/test_core_quota_peer2.conf b/src/core/test_core_quota_peer2.conf index d9820ed1d..26f8e72f5 100644 --- a/src/core/test_core_quota_peer2.conf +++ b/src/core/test_core_quota_peer2.conf @@ -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] -- 2.25.1