gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r4823 - in GNUnet: . src/applications/dht/module src/applic


From: gnunet
Subject: [GNUnet-SVN] r4823 - in GNUnet: . src/applications/dht/module src/applications/dht/tools src/applications/identity src/applications/session src/applications/tbench src/applications/testing src/include src/util/disk
Date: Sun, 27 May 2007 22:41:30 -0600 (MDT)

Author: grothoff
Date: 2007-05-27 22:41:30 -0600 (Sun, 27 May 2007)
New Revision: 4823

Removed:
   GNUnet/src/applications/tbench/peer1-udp/
   GNUnet/src/applications/tbench/peer1.conf
   GNUnet/src/applications/tbench/peer1/
   GNUnet/src/applications/tbench/peer1udp.conf
   GNUnet/src/applications/tbench/peer2-udp/
   GNUnet/src/applications/tbench/peer2.conf
   GNUnet/src/applications/tbench/peer2/
   GNUnet/src/applications/tbench/peer2udp.conf
Modified:
   GNUnet/ChangeLog
   GNUnet/src/applications/dht/module/service.c
   GNUnet/src/applications/dht/tools/dht_api.c
   GNUnet/src/applications/dht/tools/dhttest2.c
   GNUnet/src/applications/identity/hostkey.c
   GNUnet/src/applications/session/sessiontest.c
   GNUnet/src/applications/tbench/Makefile.am
   GNUnet/src/applications/tbench/tbenchtest.c
   GNUnet/src/applications/tbench/tbenchtest_udp.c
   GNUnet/src/applications/testing/testing.c
   GNUnet/src/applications/testing/testingtest.c
   GNUnet/src/include/gnunet_testing_lib.h
   GNUnet/src/util/disk/storage.c
   GNUnet/todo
Log:
applying test harness widely

Modified: GNUnet/ChangeLog
===================================================================
--- GNUnet/ChangeLog    2007-05-28 04:32:11 UTC (rev 4822)
+++ GNUnet/ChangeLog    2007-05-28 04:41:30 UTC (rev 4823)
@@ -1,3 +1,10 @@
+Sun May 27 22:39:48 MDT 2007
+       Added new API gnunet_testing_lib.h to make it
+       easier to write testcases that need to start 
+       gnunetd.  API is now used everywhere and the
+       ugly peer.conf files and directories are gone.
+       Fixed a bug with inserting empty directories.
+
 Sat May 26 18:24:15 MDT 2007
        Fixed bugs with testcases (changes in names and
        structure of options were not reflected in .conf 

Modified: GNUnet/src/applications/dht/module/service.c
===================================================================
--- GNUnet/src/applications/dht/module/service.c        2007-05-28 04:32:11 UTC 
(rev 4822)
+++ GNUnet/src/applications/dht/module/service.c        2007-05-28 04:41:30 UTC 
(rev 4823)
@@ -35,6 +35,8 @@
  */
 static CoreAPIForApplication * coreAPI;
 
+static struct CronManager * cron;
+
 typedef struct DHT_GET_RECORD {
   /**
    * Key that we are looking for.
@@ -131,7 +133,7 @@
   ret->callbackComplete = callbackComplete;
   ret->closure = closure;
   ret->type = type;
-  cron_add_job(coreAPI->cron,
+  cron_add_job(cron,
               &timeout_callback,
               timeout,
               0,
@@ -148,13 +150,13 @@
  */
 static int
 dht_get_async_stop(struct DHT_GET_RECORD * record) {
-  cron_suspend(coreAPI->cron,
+  cron_suspend(cron,
               YES);
-  cron_del_job(coreAPI->cron,
+  cron_del_job(cron,
               &timeout_callback,
               0,
               record);         
-  cron_resume_jobs(coreAPI->cron,
+  cron_resume_jobs(cron,
                   YES);
   dht_get_stop(&record->key,
               record->type,
@@ -175,6 +177,8 @@
 provide_module_dht(CoreAPIForApplication * capi) {
   static DHT_ServiceAPI api;
 
+  cron = cron_create(capi->ectx);
+  cron_start(cron);
   if (OK != init_dht_store(1024 * 1024,
                           capi))
     return NULL;
@@ -198,9 +202,11 @@
  * Shutdown DHT service.
  */
 int release_module_dht() {
+  cron_stop(cron);
   done_dht_routing();
   done_dht_table();
   done_dht_store();
+  cron_destroy(cron);
   return OK;
 }
 

Modified: GNUnet/src/applications/dht/tools/dht_api.c
===================================================================
--- GNUnet/src/applications/dht/tools/dht_api.c 2007-05-28 04:32:11 UTC (rev 
4822)
+++ GNUnet/src/applications/dht/tools/dht_api.c 2007-05-28 04:41:30 UTC (rev 
4823)
@@ -189,6 +189,7 @@
   PTHREAD_JOIN(thread, &unused);
   PTHREAD_REL_SELF(info.parent);
   connection_destroy(sock);
+  printf("Returning %d\n", info.total);
   return info.total;
 }
        

Modified: GNUnet/src/applications/dht/tools/dhttest2.c
===================================================================
--- GNUnet/src/applications/dht/tools/dhttest2.c        2007-05-28 04:32:11 UTC 
(rev 4822)
+++ GNUnet/src/applications/dht/tools/dhttest2.c        2007-05-28 04:41:30 UTC 
(rev 4823)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2005, 2006 Christian Grothoff (and other contributing authors)
+     (C) 2005, 2006, 2007 Christian Grothoff (and other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -36,6 +36,21 @@
 
 #define START_PEERS 1
 
+
+static int ok;
+
+static int waitForConnect(const char * name,
+                         unsigned long long value,
+                         void * cls) {
+  if ( (value > 0) &&
+       (0 == strcmp(_("# dht connections"),
+                   name)) ) {
+    ok = 1;
+    return SYSERR;
+  }
+  return OK;
+}
+
 #define CHECK(a) do { if (!(a)) { ret = 1; GE_BREAK(ectx, 0); goto FAILURE; } 
} while(0)
 
 /**
@@ -47,12 +62,14 @@
 #if START_PEERS
   struct DaemonContext * peers;
 #endif
-  int ret;
+  int ret = 0;
   HashCode512 key;
   DataContainer * value;
   struct GE_Context * ectx;
   struct GC_Configuration * cfg;
-
+  struct ClientServerConnection * sock;
+  int left;
+ 
   ectx = NULL;
   cfg = GC_create_C_impl();
   if (-1 == GC_parse_configuration(cfg,
@@ -62,8 +79,8 @@
   }
 #if START_PEERS
   peers = gnunet_testing_start_daemons("tcp",
-                                      "advertising dht stats",                 
               
-                                      "/tmp/dht-test",
+                                      "advertising dht stats",
+                                      "/tmp/gnunet-dht-test",
                                       2087,
                                       10000,
                                       2);
@@ -72,9 +89,78 @@
     return -1;
   }
 #endif
-  gnunet_testing_connect_daemons(2087,
-                                12087);
+  if (OK != gnunet_testing_connect_daemons(2087,
+                                          12087)) {
+    gnunet_testing_stop_daemons(peers);
+    fprintf(stderr,
+           "Failed to connect the peers!\n");
+    GC_free(cfg);
+    return -1;
+  }
 
+  /* wait for DHT's to find each other! */
+  sock = client_connection_create(NULL,
+                                 cfg);
+  left = 30; /* how many iterations should we wait? */
+  while (OK == STATS_getStatistics(NULL,
+                                  sock,
+                                  &waitForConnect,
+                                  NULL)) {
+    printf("Waiting for peers to DHT-connect (%u iterations left)...\n",
+          left);
+    sleep(5);
+    left--;
+    if (left == 0) 
+      break;    
+  }
+  connection_destroy(sock);
+  if (ok == 0) {
+    gnunet_testing_stop_daemons(peers);
+    fprintf(stderr,
+           "Peers' DHTs failed to DHT-connect!\n");
+    GC_free(cfg);
+    return -1;
+  }
+
+  /* switch to peer2 */
+  GC_set_configuration_value_string(cfg,
+                                   ectx,
+                                   "NETWORK",
+                                   "HOST",
+                                   "localhost:12087");
+  /* verify that peer2 also sees the other DHT! */
+  ok = 0;
+  sock = client_connection_create(NULL,
+                                 cfg);
+  left = 30; /* how many iterations should we wait? */
+  while (OK == STATS_getStatistics(NULL,
+                                  sock,
+                                  &waitForConnect,
+                                  NULL)) {
+    printf("Waiting for peers to DHT-connect (%u iterations left)...\n",
+          left);
+    sleep(5);
+    left--;
+    if (left == 0) 
+      break;    
+  }
+  connection_destroy(sock);
+  if (ok == 0) {
+    gnunet_testing_stop_daemons(peers);
+    fprintf(stderr,
+           "Peers' DHTs failed to DHT-connect!\n");
+    GC_free(cfg);
+    return -1;
+  }
+
+
+  /* switch to peer1 */
+  GC_set_configuration_value_string(cfg,
+                                   ectx,
+                                   "NETWORK",
+                                   "HOST",
+                                   "localhost:2087");
+
   /* actual test code */
   hash("key2", 4, &key);
   value = MALLOC(8);
@@ -87,18 +173,16 @@
                          ectx,
                          &key,
                          DHT_STRING2STRING_BLOCK,
-                         5 * cronSECONDS,
+                         get_time() + 5 * cronMINUTES,
                          value));
   printf("Peer1 gets key2\n");
   CHECK(1 == DHT_LIB_get(cfg,
                         ectx,
                         DHT_STRING2STRING_BLOCK,
                         &key,
-                        10 * cronSECONDS,
+                        2 * cronSECONDS,
                         NULL,
                         NULL));
-  hash("key", 3, &key);
-  
   /* switch to peer2 */
   GC_set_configuration_value_string(cfg,
                                    ectx,
@@ -116,14 +200,14 @@
                          ectx,
                          &key,
                          DHT_STRING2STRING_BLOCK,
-                         5 * cronSECONDS,
+                         get_time() + 5 * cronMINUTES,
                          value));
   printf("Peer2 gets key.\n");
   CHECK(1 == DHT_LIB_get(cfg,
                         ectx,
                         DHT_STRING2STRING_BLOCK,
                         &key,
-                        10 * cronSECONDS,
+                        2 * cronSECONDS,
                         NULL,
                         NULL));
   
@@ -133,11 +217,9 @@
                         ectx,
                         DHT_STRING2STRING_BLOCK,
                         &key,
-                        60 * cronSECONDS,
+                        30 * cronSECONDS,
                         NULL,
                         NULL));
-  printf("Peer2 tests successful.\n");
-
   /* switch to peer1 */
   GC_set_configuration_value_string(cfg,
                                    ectx,
@@ -149,10 +231,9 @@
                         ectx,
                         DHT_STRING2STRING_BLOCK,
                         &key,
-                        60 * cronSECONDS,
+                        30 * cronSECONDS,
                         NULL,
                         NULL));
-  printf("Peer1 tests successful, shutting down.\n");
   /* end of actual test code */
 
  FAILURE:

Modified: GNUnet/src/applications/identity/hostkey.c
===================================================================
--- GNUnet/src/applications/identity/hostkey.c  2007-05-28 04:32:11 UTC (rev 
4822)
+++ GNUnet/src/applications/identity/hostkey.c  2007-05-28 04:41:30 UTC (rev 
4823)
@@ -139,10 +139,7 @@
                         hostkeyfile,
                         sizeof(unsigned short),
                         &len);
-  } else {
-    printf("Could not read host key at `%s', generating fresh key.\n",
-          hostkeyfile);
-  }
+  } 
   encPrivateKey = NULL;
   if (res == sizeof(unsigned short)) {
     encPrivateKey = (PrivateKeyEncoded*) MALLOC(ntohs(len));

Modified: GNUnet/src/applications/session/sessiontest.c
===================================================================
--- GNUnet/src/applications/session/sessiontest.c       2007-05-28 04:32:11 UTC 
(rev 4822)
+++ GNUnet/src/applications/session/sessiontest.c       2007-05-28 04:41:30 UTC 
(rev 4823)
@@ -73,7 +73,7 @@
 #if START_PEERS
   peers = gnunet_testing_start_daemons("tcp",
                                       "advertising stats",                     
               
-                                      "/tmp/session-test",
+                                      "/tmp/gnunet-session-test",
                                       2087,
                                       10000,
                                       2);

Modified: GNUnet/src/applications/tbench/Makefile.am
===================================================================
--- GNUnet/src/applications/tbench/Makefile.am  2007-05-28 04:32:11 UTC (rev 
4822)
+++ GNUnet/src/applications/tbench/Makefile.am  2007-05-28 04:41:30 UTC (rev 
4823)
@@ -41,6 +41,7 @@
   tbenchtest.c 
 tbenchtest_LDADD = \
   $(top_builddir)/src/applications/stats/libgnunetstats_api.la \
+  $(top_builddir)/src/applications/testing/libgnunettesting_api.la \
   $(top_builddir)/src/util/network_client/libgnunetutil_network_client.la \
   $(top_builddir)/src/util/loggers/libgnunetutil_logging.la \
   $(top_builddir)/src/util/crypto/libgnunetutil_crypto.la \
@@ -51,6 +52,7 @@
   tbenchtest_udp.c 
 tbenchtest_udp_LDADD = \
   $(top_builddir)/src/applications/stats/libgnunetstats_api.la \
+  $(top_builddir)/src/applications/testing/libgnunettesting_api.la \
   $(top_builddir)/src/util/network_client/libgnunetutil_network_client.la \
   $(top_builddir)/src/util/loggers/libgnunetutil_logging.la \
   $(top_builddir)/src/util/crypto/libgnunetutil_crypto.la \
@@ -58,12 +60,4 @@
   $(top_builddir)/src/util/libgnunetutil.la 
 
 EXTRA_DIST = \
-  check.conf \
-  peer1.conf \
-  peer2.conf \
-  peer1/.hostkey \
-  peer2/.hostkey \
-  peer1udp.conf \
-  peer2udp.conf \
-  peer1-udp/.hostkey \
-  peer2-udp/.hostkey 
+  check.conf 

Deleted: GNUnet/src/applications/tbench/peer1.conf
===================================================================
--- GNUnet/src/applications/tbench/peer1.conf   2007-05-28 04:32:11 UTC (rev 
4822)
+++ GNUnet/src/applications/tbench/peer1.conf   2007-05-28 04:41:30 UTC (rev 
4823)
@@ -1,61 +0,0 @@
-# This is the configuration for the GNUnet daemon when running
-# the test in this directory (make check).
-[PATHS]
-GNUNETD_HOME     = peer1
-
-[GNUNETD]
-GNUNETD_HOME     = peer1
-# VALGRIND        = 300
-HELLOEXPIRES     = 60
-LOGLEVEL        = WARNING
-LOGFILE         = $GNUNETD_HOME/logs
-KEEPLOG         = 0
-PIDFILE         = $GNUNETD_HOME/gnunetd.pid
-HOSTS          = $GNUNETD_HOME/data/hosts/
-APPLICATIONS = "advertising topology tbench stats"
-TRANSPORTS = "tcp"
-
-[MODULES]
-topology = "topology_default"
-
-[NETWORK]
-PORT = 2087
-INTERFACE = eth0
-HELOEXCHANGE = NO
-TRUSTED = 127.0.0.0/8;
-
-[LOAD]
-INTERFACES          = eth0
-BASICLIMITING       = YES
-MAXNETUPBPSTOTAL    = 50000000
-MAXNETDOWNBPSTOTAL  = 50000000
-MAXCPULOAD         = 100
-
-[TCP]
-PORT = 2086
-# BLACKLIST = 
-
-[UDP]
-PORT = 2086
-# BLACKLIST = 
-MTU = 1472
-
-[UDP6]
-# Default port is 2088 and MTU is 1452.
-PORT = 2088
-# BLACKLIST = 
-MTU = 1452
-
-[TCP6]
-
-# Default port is 2088 and MTU is 1440.
-PORT = 2088
-# BLACKLIST = 
-MTU = 1440
-
-[HTTP]
-# Default port is 1080 and MTU is 1400.
-PORT = 1080
-# BLACKLIST =
-
-

Deleted: GNUnet/src/applications/tbench/peer1udp.conf
===================================================================
--- GNUnet/src/applications/tbench/peer1udp.conf        2007-05-28 04:32:11 UTC 
(rev 4822)
+++ GNUnet/src/applications/tbench/peer1udp.conf        2007-05-28 04:41:30 UTC 
(rev 4823)
@@ -1,62 +0,0 @@
-# This is the configuration for the GNUnet daemon when running
-# the test in this directory (make check).
-[PATHS]
-GNUNETD_HOME     = peer1-udp
-
-
-[GNUNETD]
-GNUNETD_HOME     = peer1-udp
-# VALGRIND        = 300
-HELLOEXPIRES     = 60
-LOGLEVEL        = WARNING
-LOGFILE         = $GNUNETD_HOME/logs 
-KEEPLOG         = 0
-PIDFILE         = $GNUNETD_HOME/gnunetd.pid
-HOSTS          = $GNUNETD_HOME/data/hosts/
-APPLICATIONS = "advertising topology tbench stats"
-TRANSPORTS = "udp"
-
-[MODULES]
-topology = "topology_default"
-
-[NETWORK]
-PORT = 2087
-INTERFACE = eth0
-HELOEXCHANGE = NO
-TRUSTED = 127.0.0.0/8;
-
-[LOAD]
-INTERFACES          = eth0
-BASICLIMITING       = YES
-MAXNETUPBPSTOTAL    = 500000
-MAXNETDOWNBPSTOTAL  = 500000
-MAXCPULOAD         = 100
-
-[TCP]
-PORT = 2086
-# BLACKLIST = 
-
-[UDP]
-PORT = 2086
-# BLACKLIST = 
-MTU = 1472
-
-[UDP6]
-# Default port is 2088 and MTU is 1452.
-PORT = 2088
-# BLACKLIST = 
-MTU = 1452
-
-[TCP6]
-
-# Default port is 2088 and MTU is 1440.
-PORT = 2088
-# BLACKLIST = 
-MTU = 1440
-
-[HTTP]
-# Default port is 1080 and MTU is 1400.
-PORT = 1080
-# BLACKLIST =
-
-

Deleted: GNUnet/src/applications/tbench/peer2.conf
===================================================================
--- GNUnet/src/applications/tbench/peer2.conf   2007-05-28 04:32:11 UTC (rev 
4822)
+++ GNUnet/src/applications/tbench/peer2.conf   2007-05-28 04:41:30 UTC (rev 
4823)
@@ -1,61 +0,0 @@
-# This is the configuration for the GNUnet daemon when running
-# the test in this directory (make check).
-[PATHS]
-GNUNETD_HOME     = peer2
-
-[GNUNETD]
-GNUNETD_HOME     = peer2
-# VALGRIND        = 300
-HELLOEXPIRES     = 60
-LOGLEVEL        = WARNING
-LOGFILE         = $GNUNETD_HOME/logs
-KEEPLOG         = 0
-PIDFILE         = $GNUNETD_HOME/gnunetd.pid
-HOSTS          = $GNUNETD_HOME/data/hosts/
-APPLICATIONS = "advertising topology tbench"
-TRANSPORTS  = "tcp"
-
-[MODULES]
-topology = "topology_default"
-
-[NETWORK]
-PORT = 12087
-INTERFACE = eth0
-HELOEXCHANGE = NO
-TRUSTED = 127.0.0.0/8;
-
-[LOAD]
-INTERFACES          = eth0
-BASICLIMITING       = YES
-MAXNETUPBPSTOTAL    = 50000000
-MAXNETDOWNBPSTOTAL  = 50000000
-MAXCPULOAD         = 100
-
-[TCP]
-PORT = 12086
-# BLACKLIST = 
-
-[UDP]
-PORT = 12086
-# BLACKLIST = 
-MTU = 1472
-
-[UDP6]
-# Default port is 2088 and MTU is 1452.
-PORT = 12088
-# BLACKLIST = 
-MTU = 1452
-
-[TCP6]
-
-# Default port is 2088 and MTU is 1440.
-PORT = 12088
-# BLACKLIST = 
-MTU = 1440
-
-[HTTP]
-# Default port is 1080 and MTU is 1400.
-PORT = 11080
-# BLACKLIST =
-
-

Deleted: GNUnet/src/applications/tbench/peer2udp.conf
===================================================================
--- GNUnet/src/applications/tbench/peer2udp.conf        2007-05-28 04:32:11 UTC 
(rev 4822)
+++ GNUnet/src/applications/tbench/peer2udp.conf        2007-05-28 04:41:30 UTC 
(rev 4823)
@@ -1,62 +0,0 @@
-# This is the configuration for the GNUnet daemon when running
-# the test in this directory (make check).
-[PATHS]
-GNUNETD_HOME     = peer2-udp
-
-
-[GNUNETD]
-GNUNETD_HOME     = peer2-udp
-# VALGRIND        = 300
-HELLOEXPIRES     = 60
-LOGLEVEL        = WARNING
-LOGFILE         = $GNUNETD_HOME/logs
-KEEPLOG         = 0
-PIDFILE         = $GNUNETD_HOME/gnunetd.pid
-HOSTS          = $GNUNETD_HOME/data/hosts/
-APPLICATIONS = "advertising topology tbench"
-TRANSPORTS  = "udp"
-
-[MODULES]
-topology = "topology_default"
-
-[NETWORK]
-PORT = 12087
-INTERFACE = eth0
-HELOEXCHANGE = NO
-TRUSTED = 127.0.0.0/8;
-
-[LOAD]
-INTERFACES          = eth0
-BASICLIMITING       = YES
-MAXNETUPBPSTOTAL    = 500000
-MAXNETDOWNBPSTOTAL  = 500000
-MAXCPULOAD         = 100
-
-[TCP]
-PORT = 12086
-# BLACKLIST = 
-
-[UDP]
-PORT = 12086
-# BLACKLIST = 
-MTU = 1472
-
-[UDP6]
-# Default port is 2088 and MTU is 1452.
-PORT = 12088
-# BLACKLIST = 
-MTU = 1452
-
-[TCP6]
-
-# Default port is 2088 and MTU is 1440.
-PORT = 12088
-# BLACKLIST = 
-MTU = 1440
-
-[HTTP]
-# Default port is 1080 and MTU is 1400.
-PORT = 11080
-# BLACKLIST =
-
-

Modified: GNUnet/src/applications/tbench/tbenchtest.c
===================================================================
--- GNUnet/src/applications/tbench/tbenchtest.c 2007-05-28 04:32:11 UTC (rev 
4822)
+++ GNUnet/src/applications/tbench/tbenchtest.c 2007-05-28 04:41:30 UTC (rev 
4823)
@@ -27,11 +27,17 @@
 #include "platform.h"
 #include "gnunet_protocols.h"
 #include "gnunet_stats_lib.h"
+#include "gnunet_testing_lib.h"
 #include "gnunet_util_crypto.h"
 #include "gnunet_util_config_impl.h"
 #include "gnunet_util_network_client.h"
 #include "tbench.h"
 
+#define START_PEERS 1
+
+static PeerIdentity peer1;
+static PeerIdentity peer2;
+
 static int test(struct ClientServerConnection * sock,
                unsigned int messageSize,
                unsigned int messageCnt,
@@ -39,15 +45,11 @@
                cron_t messageSpacing,
                unsigned int messageTrainSize,
                cron_t messageTimeOut /* in milli-seconds */) {
-  PeerIdentity peer2;
   int ret;
   CS_tbench_request_MESSAGE msg;
   CS_tbench_reply_MESSAGE * buffer;
   float messagesPercentLoss;
 
-  
enc2hash("BV3AS3KMIIBVIFCGEG907N6NTDTH26B7T6FODUSLSGK5B2Q58IEU1VF5FTR838449CSHVBOAHLDVQAOA33O77FOPDA8F1VIKESLSNBO",
-          &peer2.hashPubKey);
-
   printf(_("Using %u messages of size %u for %u times.\n"),
         messageCnt,
         messageSize,
@@ -94,40 +96,6 @@
   return ret;
 }
 
-static int waitForConnect(const char * name,
-                         unsigned long long value,
-                         void * cls) {
-  if ( (value > 0) &&
-       (0 == strcmp(_("# of connected peers"),
-                   name)) )
-    return SYSERR;
-  return OK;
-}
-
-static int checkConnected(struct ClientServerConnection * sock) {
-  int left;
-  int ret;
-
-  ret = 0;
-  left = 30; /* how many iterations should we wait? */
-  while (OK == STATS_getStatistics(NULL,
-                                  sock,
-                                  &waitForConnect,
-                                  NULL)) {
-    printf(_("Waiting for peers to connect (%u iterations left)...\n"),
-          left);
-    sleep(5);
-    left--;
-    if (left == 0) {
-      ret = 1;
-      break;
-    }
-  }
-  return ret;
-}
-
-#define START_PEERS 1
-
 /**
  * Testcase to test p2p communications.
  *
@@ -137,16 +105,15 @@
  */
 int main(int argc, char ** argv) {
 #if START_PEERS
-  pid_t daemon1;
-  pid_t daemon2;
+  struct DaemonContext * peers;
 #endif
   int i;
   int ok;
   int ret;
   struct ClientServerConnection * sock;
-  int left;
   struct GC_Configuration * cfg;
 
+  ret = 0;
   ok = 1;
   cfg = GC_create_C_impl();
   if (-1 == GC_parse_configuration(cfg,
@@ -155,85 +122,42 @@
     return -1;
   }
 #if START_PEERS
-  daemon1  = os_daemon_start(NULL,
-                            cfg,
-                            "peer1.conf",
-                            NO);
-  daemon2 = os_daemon_start(NULL,
-                           cfg,
-                           "peer2.conf",
-                           NO);
-#endif
-  /* in case existing hellos have expired */
-  PTHREAD_SLEEP(30 * cronSECONDS);
-  system("cp peer1/data/hosts/* peer2/data/hosts/");
-  system("cp peer2/data/hosts/* peer1/data/hosts/");
-  ret = 0;
-#if START_PEERS
-  if (daemon1 != -1) {
-    if (os_daemon_stop(NULL, daemon1) != YES)
-      ret = 1;
+  peers = gnunet_testing_start_daemons("tcp",
+                                      "advertising tbench topology stats",
+                                      "/tmp/gnunet-tbench-test",
+                                      2087,
+                                      10000,
+                                      2);
+  if (peers == NULL) {
+    GC_free(cfg);
+    return -1;
   }
-  if (daemon2 != -1) {
-    if (os_daemon_stop(NULL, daemon2) != YES)
-      ret = 1;
-  }
-  if (ret != 0)
-    return 1;
-  daemon1  = os_daemon_start(NULL,
-                            cfg,
-                            "peer1.conf",
-                            NO);
-  daemon2 = os_daemon_start(NULL,
-                           cfg,
-                           "peer2.conf",
-                           NO);
 #endif
-  if (OK == connection_wait_for_running(NULL,
-                                       cfg,
-                                       30 * cronSECONDS)) {
-    sock = client_connection_create(NULL,
-                                   cfg);
-    left = 30; /* how many iterations should we wait? */
-    while (OK == STATS_getStatistics(NULL,
-                                    sock,
-                                    &waitForConnect,
-                                    NULL)) {
-      printf("Waiting for peers to connect (%u iterations left)...\n",
-            left);
-      sleep(5);
-      left--;
-      if (left == 0) {
-       ret = 1;
-       break;
-      }
-    }
-    ret = checkConnected(sock);
-    printf(_("Running benchmark...\n"));
-    /* 'slow' pass: wait for bandwidth negotiation! */
+  peer1 = peers->peer;
+  peer2 = peers->next->peer;
+  if (OK != gnunet_testing_connect_daemons(2087,
+                                          12087)) {
+    gnunet_testing_stop_daemons(peers);
+    fprintf(stderr,
+           "Failed to connect the peers!\n");
+    GC_free(cfg);
+    return -1;
+  }
+  sock = client_connection_create(NULL,
+                                 cfg);
+  printf(_("Running benchmark...\n"));
+  /* 'slow' pass: wait for bandwidth negotiation! */
+  if (ret == 0)
+    ret = test(sock, 64, 100, 4, 50 * cronMILLIS, 1, 5 * cronSECONDS);
+  /* 'blast' pass: hit bandwidth limits! */
+  for (i=8;i<60000;i*=2) {
     if (ret == 0)
-      ret = test(sock, 64, 100, 4, 50 * cronMILLIS, 1, 5 * cronSECONDS);
-    checkConnected(sock);
-    /* 'blast' pass: hit bandwidth limits! */
-    for (i=8;i<60000;i*=2) {
-      if (ret == 0)
-       ret = test(sock, i, 1+1024/i, 4, 10 * cronMILLIS, 2, 2 * cronSECONDS);
-      checkConnected(sock);
-    }
-    ret = test(sock, 32768, 10, 10, 500 * cronMILLIS, 1, 10 * cronSECONDS);
-    connection_destroy(sock);
-  } else {
-    printf("Could not establish connection with peer.\n");
+      ret = test(sock, i, 1+1024/i, 4, 10 * cronMILLIS, 2, 2 * cronSECONDS);
   }
+  ret = test(sock, 32768, 10, 10, 500 * cronMILLIS, 1, 10 * cronSECONDS);
+  connection_destroy(sock);
 #if START_PEERS
-  if (daemon1 != -1) {
-    if (os_daemon_stop(NULL, daemon1) != YES)
-      ret = 1;
-  }
-  if (daemon2 != -1) {
-    if (os_daemon_stop(NULL, daemon2) != YES)
-      ret = 1;
-  }
+  gnunet_testing_stop_daemons(peers);
 #endif
   if (ok == 0)
     ret = 1;

Modified: GNUnet/src/applications/tbench/tbenchtest_udp.c
===================================================================
--- GNUnet/src/applications/tbench/tbenchtest_udp.c     2007-05-28 04:32:11 UTC 
(rev 4822)
+++ GNUnet/src/applications/tbench/tbenchtest_udp.c     2007-05-28 04:41:30 UTC 
(rev 4823)
@@ -27,11 +27,19 @@
 #include "platform.h"
 #include "gnunet_protocols.h"
 #include "gnunet_stats_lib.h"
+#include "gnunet_testing_lib.h"
 #include "gnunet_util_crypto.h"
 #include "gnunet_util_config_impl.h"
 #include "gnunet_util_network_client.h"
 #include "tbench.h"
 
+#define START_PEERS 1
+
+static PeerIdentity peer1;
+
+static PeerIdentity peer2;
+
+
 static int test(struct ClientServerConnection * sock,
                unsigned int messageSize,
                unsigned int messageCnt,
@@ -39,14 +47,11 @@
                cron_t messageSpacing,
                unsigned int messageTrainSize,
                cron_t messageTimeOut /* in milli-seconds */) {
-  PeerIdentity peer2;
   int ret;
   CS_tbench_request_MESSAGE msg;
   CS_tbench_reply_MESSAGE * buffer;
   float messagesPercentLoss;
 
-  
enc2hash("BV3AS3KMIIBVIFCGEG907N6NTDTH26B7T6FODUSLSGK5B2Q58IEU1VF5FTR838449CSHVBOAHLDVQAOA33O77FOPDA8F1VIKESLSNBO",
-          &peer2.hashPubKey);
   printf(_("Using %u messages of size %u for %u times.\n"),
         messageCnt,
         messageSize,
@@ -93,40 +98,7 @@
   return ret;
 }
 
-static int waitForConnect(const char * name,
-                         unsigned long long value,
-                         void * cls) {
-  if ( (value > 0) &&
-       (0 == strcmp(_("# of connected peers"),
-                   name)) )
-    return SYSERR;
-  return OK;
-}
 
-static int checkConnected(struct ClientServerConnection * sock) {
-  int left;
-  int ret;
-
-  ret = 0;
-  left = 30; /* how many iterations should we wait? */
-  while (OK == STATS_getStatistics(NULL,
-                                  sock,
-                                  &waitForConnect,
-                                  NULL)) {
-    printf(_("Waiting for peers to connect (%u iterations left)...\n"),
-          left);
-    sleep(5);
-    left--;
-    if (left == 0) {
-      ret = 1;
-      break;
-    }
-  }
-  return ret;
-}
-
-#define START_PEERS 1
-
 /**
  * Testcase to test p2p communications.
  *
@@ -136,16 +108,15 @@
  */
 int main(int argc, char ** argv) {
 #if START_PEERS
-  pid_t daemon1;
-  pid_t daemon2;
+  struct DaemonContext * peers;
 #endif
   int i;
   int ok;
   int ret;
   struct ClientServerConnection * sock;
-  int left;
   struct GC_Configuration * cfg;
 
+  ret = 0;
   ok = 1;
   cfg = GC_create_C_impl();
   if (-1 == GC_parse_configuration(cfg,
@@ -154,85 +125,43 @@
     return -1;
   }
 #if START_PEERS
-  daemon1  = os_daemon_start(NULL,
-                            cfg,
-                            "peer1udp.conf",
-                            NO);
-  daemon2 = os_daemon_start(NULL,
-                           cfg,
-                           "peer2udp.conf",
-                           NO);
+  peers = gnunet_testing_start_daemons("udp",
+                                      "advertising tbench topology stats",
+                                      "/tmp/gnunet-tbench-test-udp",
+                                      2087,
+                                      10000,
+                                      2);
+  if (peers == NULL) {
+    GC_free(cfg);
+    return -1;
+   }
 #endif
-  /* in case existing hellos have expired */
-  PTHREAD_SLEEP(30 * cronSECONDS);
-  system("cp peer1-udp/data/hosts/* peer2-udp/data/hosts/");
-  system("cp peer2-udp/data/hosts/* peer1-udp/data/hosts/");
-  ret = 0;
-#if START_PEERS
-  if (daemon1 != -1) {
-    if (os_daemon_stop(NULL, daemon1) != YES)
-      ret = 1;
+  peer1 = peers->peer;
+  peer2 = peers->next->peer;
+  if (OK != gnunet_testing_connect_daemons(2087,
+                                          12087)) {
+    gnunet_testing_stop_daemons(peers);
+    fprintf(stderr,
+           "Failed to connect the peers!\n");
+    GC_free(cfg);
+    return -1;
   }
-  if (daemon2 != -1) {
-    if (os_daemon_stop(NULL, daemon2) != YES)
-      ret = 1;
-  }
-  if (ret != 0)
-    return 1;
-  daemon1  = os_daemon_start(NULL,
-                            cfg,
-                            "peer1udp.conf",
-                            NO);
-  daemon2 = os_daemon_start(NULL,
-                           cfg,
-                           "peer2udp.conf",
-                           NO);
-#endif
-  if (OK == connection_wait_for_running(NULL,
-                                       cfg,
-                                       30 * cronSECONDS)) {
-    sock = client_connection_create(NULL,
-                                   cfg);
-    left = 30; /* how many iterations should we wait? */
-    while (OK == STATS_getStatistics(NULL,
-                                    sock,
-                                    &waitForConnect,
-                                    NULL)) {
-      printf("Waiting for peers to connect (%u iterations left)...\n",
-            left);
-      sleep(5);
-      left--;
-      if (left == 0) {
-       ret = 1;
-       break;
-      }
-    }
-    ret = checkConnected(sock);
-    printf(_("Running benchmark...\n"));
-    /* 'slow' pass: wait for bandwidth negotiation! */
+  sock = client_connection_create(NULL,
+                                 cfg);
+  
+  printf(_("Running benchmark...\n"));
+  /* 'slow' pass: wait for bandwidth negotiation! */
+  if (ret == 0)
+    ret = test(sock, 64, 100, 4, 50 * cronMILLIS, 1, 5 * cronSECONDS);
+  /* 'blast' pass: hit bandwidth limits! */
+  for (i=8;i<60000;i*=2) {
     if (ret == 0)
-      ret = test(sock, 64, 100, 4, 50 * cronMILLIS, 1, 5 * cronSECONDS);
-    checkConnected(sock);
-    /* 'blast' pass: hit bandwidth limits! */
-    for (i=8;i<60000;i*=2) {
-      if (ret == 0)
-       ret = test(sock, i, 1+1024/i, 4, 10 * cronMILLIS, 2, 2 * cronSECONDS);
-      checkConnected(sock);
-    }
-    ret = test(sock, 32768, 10, 10, 500 * cronMILLIS, 1, 10 * cronSECONDS);
-    connection_destroy(sock);
-  } else {
-    printf("Could not establish connection with peer.\n");
+      ret = test(sock, i, 1+1024/i, 4, 10 * cronMILLIS, 2, 2 * cronSECONDS);
   }
+  ret = test(sock, 32768, 10, 10, 500 * cronMILLIS, 1, 10 * cronSECONDS);
+  connection_destroy(sock);
 #if START_PEERS
-  if (daemon1 != -1) {
-    if (os_daemon_stop(NULL, daemon1) != YES)
-      ret = 1;
-  }
-  if (daemon2 != -1) {
-    if (os_daemon_stop(NULL, daemon2) != YES)
-      ret = 1;
-  }
+  gnunet_testing_stop_daemons(peers); 
 #endif
   if (ok == 0)
     ret = 1;

Modified: GNUnet/src/applications/testing/testing.c
===================================================================
--- GNUnet/src/applications/testing/testing.c   2007-05-28 04:32:11 UTC (rev 
4822)
+++ GNUnet/src/applications/testing/testing.c   2007-05-28 04:41:30 UTC (rev 
4823)
@@ -73,7 +73,8 @@
                                const char * transports,
                                const char * applications,
                                pid_t * pid,
-                               PeerIdentity * peer) {
+                               PeerIdentity * peer,
+                               char ** configFile) {
   int ret;
   char * ipath;
   char * dpath;
@@ -82,7 +83,14 @@
   struct ClientServerConnection * sock;
   P2P_hello_MESSAGE * hello;
 
+  fprintf(stderr,
+         "Starting peer on port %u\n",
+         app_port);
+#if 0
+  /* do not usually do this -- may easily
+     exhaust entropy pool for hostkey generation... */
   disk_directory_remove(NULL, gnunetd_home);
+#endif
   ipath = os_get_installation_path(IPK_DATADIR);
   if (ipath == NULL)
     return SYSERR;
@@ -179,7 +187,7 @@
   /* now get peer ID */
   if (OK != connection_wait_for_running(NULL,
                                        cfg,
-                                       60 * cronSECONDS)) {
+                                       120 * cronSECONDS)) {
     fprintf(stderr,
            "Failed to confirm daemon running!\n");
     GC_free(cfg);
@@ -187,8 +195,8 @@
     FREE(dpath);
     return SYSERR;
   }
-  UNLINK(dpath);
-  FREE(dpath);
+  *configFile = dpath;
+  dpath = NULL;
   sock = client_connection_create(NULL,
                                  cfg);
   ret = gnunet_identity_get_self(sock,
@@ -313,4 +321,82 @@
   return OK;
 }
 
+/**
+ * Start count gnunetd processes with the same set of
+ * transports and applications.  The port numbers will
+ * be computed by adding "delta" each time (zero
+ * times for the first peer).
+ *
+ * @return handle used to stop the daemons, NULL on error
+ */
+struct DaemonContext * 
+gnunet_testing_start_daemons(const char * transports,
+                            const char * applications,
+                            const char * gnunetd_home_prefix,
+                            unsigned short app_baseport,
+                            unsigned short delta,
+                            unsigned int count) {
+  struct DaemonContext * ret;
+  struct DaemonContext * nxt;
+  unsigned int pos;
+  char * home;
+  size_t max;
+  pid_t pid;
+  PeerIdentity peer;
+  char * cf;
+
+  ret = NULL;
+  max = strlen(gnunetd_home_prefix) + 14;
+  home = MALLOC(max);
+  for (pos=0;pos<count;pos++) {
+    SNPRINTF(home,
+            max,
+            "%s.%u",
+            gnunetd_home_prefix,
+            pos);
+    if (OK != gnunet_testing_start_daemon(app_baseport + pos * delta,
+                                         delta * pos,
+                                         home,
+                                         transports,
+                                         applications,
+                                         &pid,
+                                         &peer,
+                                         &cf)) {
+      gnunet_testing_stop_daemons(ret);
+      ret = NULL;
+      break;
+    }
+    nxt = MALLOC(sizeof(struct DaemonContext));
+    nxt->next = ret;
+    nxt->pid = pid;
+    nxt->peer = peer;
+    nxt->configFile = cf;
+    nxt->port = app_baseport + pos * delta;
+    ret = nxt;
+  }
+  FREE(home);
+  return ret;
+}
+
+int gnunet_testing_stop_daemons(struct DaemonContext * peers) {
+  struct DaemonContext * next;
+  int ret;
+
+  ret = OK;
+  while (peers != NULL) {
+    next = peers->next;
+    if (OK != gnunet_testing_stop_daemon(peers->port,
+                                        peers->pid))
+      ret = SYSERR;
+    UNLINK(peers->configFile);
+    FREE(peers->configFile);
+    FREE(peers);
+    peers = next;   
+  }
+  return ret;
+}
+                            
+
+
+
 /* end of testing.c */

Modified: GNUnet/src/applications/testing/testingtest.c
===================================================================
--- GNUnet/src/applications/testing/testingtest.c       2007-05-28 04:32:11 UTC 
(rev 4822)
+++ GNUnet/src/applications/testing/testingtest.c       2007-05-28 04:41:30 UTC 
(rev 4823)
@@ -38,6 +38,8 @@
   pid_t daemon2;
   PeerIdentity p1;
   PeerIdentity p2;
+  char * c1 = NULL;
+  char * c2 = NULL;
   int ret = 0;
 
   if (OK != gnunet_testing_start_daemon(12087,
@@ -46,7 +48,8 @@
                                        "tcp",
                                        "advertising stats",
                                        &daemon1,
-                                       &p1))
+                                       &p1,
+                                       &c1))
     ret |= 1;
   if (OK != gnunet_testing_start_daemon(22087,
                                        20000,
@@ -54,7 +57,8 @@
                                        "tcp",
                                        "advertising stats",
                                        &daemon2,
-                                       &p2))
+                                       &p2,
+                                       &c2))
     ret |= 2;
   if (OK != gnunet_testing_connect_daemons(12087,
                                           22087))
@@ -65,6 +69,14 @@
   if (OK != gnunet_testing_stop_daemon(22087,
                                       daemon2))
     ret |= 16;
+  if (c1 != NULL) {
+    UNLINK(c1);
+    FREE(c1);
+  }
+  if (c2 != NULL) {
+    UNLINK(c2);
+    FREE(c2);
+  }
   return ret;
 }
 

Modified: GNUnet/src/include/gnunet_testing_lib.h
===================================================================
--- GNUnet/src/include/gnunet_testing_lib.h     2007-05-28 04:32:11 UTC (rev 
4822)
+++ GNUnet/src/include/gnunet_testing_lib.h     2007-05-28 04:41:30 UTC (rev 
4823)
@@ -59,7 +59,8 @@
                                const char * transports,
                                const char * applications,
                                pid_t * pid,
-                               PeerIdentity * peer);
+                               PeerIdentity * peer,
+                               char ** configFile);
 
 /**
  * Establish a connection between two GNUnet daemons
@@ -83,6 +84,41 @@
                               pid_t pid);
 
 
+/**
+ * Linked list of information about daemon processes.
+ */
+struct DaemonContext {
+  struct DaemonContext * next;
+  PeerIdentity peer;
+  pid_t pid;
+  unsigned short port;
+  char * configFile;
+};
+
+
+/**
+ * Start count gnunetd processes with the same set of
+ * transports and applications.  The port numbers will
+ * be computed by adding delta each time (zero
+ * times for the first peer).
+ *
+ * @return handle used to stop the daemons, NULL on error
+ */
+struct DaemonContext * 
+gnunet_testing_start_daemons(const char * transports,
+                            const char * applications,
+                            const char * gnunetd_home_prefix,
+                            unsigned short app_baseport,
+                            unsigned short delta,
+                            unsigned int count);
+
+/**
+ * Stop all of the daemons started with the start function.
+ * @return OK on success, SYSERR on error
+ */
+int gnunet_testing_stop_daemons(struct DaemonContext * peers);
+                            
+
 #if 0 /* keep Emacsens' auto-indent happy */
 {
 #endif

Modified: GNUnet/src/util/disk/storage.c
===================================================================
--- GNUnet/src/util/disk/storage.c      2007-05-28 04:32:11 UTC (rev 4822)
+++ GNUnet/src/util/disk/storage.c      2007-05-28 04:41:30 UTC (rev 4823)
@@ -583,6 +583,10 @@
  */
 int disk_directory_remove(struct GE_Context * ectx,
                          const char * fileName) {
+  struct stat istat;
+
+  if (0 != STAT(fileName, &istat)) 
+    return NO; /* file may not exist... */
   if (UNLINK(fileName) == 0)
     return OK;
   if ( (errno != EISDIR) &&

Modified: GNUnet/todo
===================================================================
--- GNUnet/todo 2007-05-28 04:32:11 UTC (rev 4822)
+++ GNUnet/todo 2007-05-28 04:41:30 UTC (rev 4823)
@@ -16,8 +16,7 @@
   * XFS / support for location URIs -- TEST!!! [CG] 
   * HTTP transport (libcurl, libmicrohttpd)
 - testcases (fix, add):
-  * design and write general testcase API for forking / connecting of daemons
-    (the amount of shared identical code is becoming ridiculous)
+  * use new testcase API for forking / connecting of daemons
   * dht/tools -- make sure dhttest2 compiles & runs!
   * ecrs_core -- implement actual testcase, harness is there!
   * gap (incl. economy)





reply via email to

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