gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r11284 - gnunet/src/testing


From: gnunet
Subject: [GNUnet-SVN] r11284 - gnunet/src/testing
Date: Mon, 10 May 2010 15:38:57 +0200

Author: nevans
Date: 2010-05-10 15:38:57 +0200 (Mon, 10 May 2010)
New Revision: 11284

Modified:
   gnunet/src/testing/test_testing.c
   gnunet/src/testing/test_testing_connect.c
   gnunet/src/testing/test_testing_group.c
   gnunet/src/testing/test_testing_group_remote.c
   gnunet/src/testing/test_testing_topology.c
   gnunet/src/testing/testing.c
   gnunet/src/testing/testing_group.c
Log:
change testing library to use timeout for peer and peergroup startup so 
testcase/user can decide how long to wait as opposed to arbitrary wait counts

Modified: gnunet/src/testing/test_testing.c
===================================================================
--- gnunet/src/testing/test_testing.c   2010-05-10 12:48:47 UTC (rev 11283)
+++ gnunet/src/testing/test_testing.c   2010-05-10 13:38:57 UTC (rev 11284)
@@ -26,6 +26,8 @@
 
 #define VERBOSE GNUNET_NO
 
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
+
 static int ok;
 
 static void
@@ -56,7 +58,7 @@
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Daemon `%s' started, will now stop it.\n", GNUNET_i2s (id));
 #endif
-  GNUNET_TESTING_daemon_stop (d, &end_cb, NULL, GNUNET_YES);
+  GNUNET_TESTING_daemon_stop (d, TIMEOUT, &end_cb, NULL, GNUNET_YES);
 }
 
 
@@ -72,7 +74,7 @@
 #if VERBOSE
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemon.\n");
 #endif
-  d = GNUNET_TESTING_daemon_start (sched, cfg, NULL, NULL, NULL, &my_cb, NULL);
+  d = GNUNET_TESTING_daemon_start (sched, cfg, TIMEOUT, NULL, NULL, NULL, 
&my_cb, NULL);
   GNUNET_assert (d != NULL);
 }
 

Modified: gnunet/src/testing/test_testing_connect.c
===================================================================
--- gnunet/src/testing/test_testing_connect.c   2010-05-10 12:48:47 UTC (rev 
11283)
+++ gnunet/src/testing/test_testing_connect.c   2010-05-10 13:38:57 UTC (rev 
11284)
@@ -69,14 +69,14 @@
 end1_cb (void *cls, const char *emsg)
 {
   GNUNET_assert (emsg == NULL);
-  GNUNET_TESTING_daemon_stop (d2, &end2_cb, NULL, GNUNET_YES);
+  GNUNET_TESTING_daemon_stop (d2, TIMEOUT, &end2_cb, NULL, GNUNET_YES);
   d2 = NULL;
 }
 
 static void
 finish_testing(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
 {
-  GNUNET_TESTING_daemon_stop (d1, &end1_cb, NULL, GNUNET_YES);
+  GNUNET_TESTING_daemon_stop (d1, TIMEOUT, &end1_cb, NULL, GNUNET_YES);
   d1 = NULL;
 }
 
@@ -121,7 +121,7 @@
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Daemon `%s' started.\n", GNUNET_i2s (id));
 #endif
-  d2 = GNUNET_TESTING_daemon_start (sched, c2, NULL, NULL, NULL, &my_cb2, 
NULL);
+  d2 = GNUNET_TESTING_daemon_start (sched, c2, TIMEOUT, NULL, NULL, NULL, 
&my_cb2, NULL);
   GNUNET_assert (d2 != NULL);
 
 }
@@ -142,7 +142,7 @@
   GNUNET_CONFIGURATION_parse (c1, "test_testing_connect_peer1.conf");
   c2 = GNUNET_CONFIGURATION_create ();
   GNUNET_CONFIGURATION_parse (c2, "test_testing_connect_peer2.conf");
-  d1 = GNUNET_TESTING_daemon_start (sched, c1, NULL, NULL, NULL, &my_cb1, 
NULL);
+  d1 = GNUNET_TESTING_daemon_start (sched, c1, TIMEOUT, NULL, NULL, NULL, 
&my_cb1, NULL);
   GNUNET_assert (d1 != NULL);
 }
 

Modified: gnunet/src/testing/test_testing_group.c
===================================================================
--- gnunet/src/testing/test_testing_group.c     2010-05-10 12:48:47 UTC (rev 
11283)
+++ gnunet/src/testing/test_testing_group.c     2010-05-10 13:38:57 UTC (rev 
11284)
@@ -33,7 +33,6 @@
  */
 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)
 
-
 static int ok;
 
 static int peers_left;
@@ -64,12 +63,13 @@
     {
       sleep(2); /* Give other services a chance to initialize before killing */
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers started successfully, 
ending test!\n");
-      GNUNET_TESTING_daemons_stop (pg);
+      GNUNET_TESTING_daemons_stop (pg, TIMEOUT);
       ok = 0;
     }
   else if (failed_peers == peers_left)
     {
-      GNUNET_TESTING_daemons_stop (pg);
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Too many peers failed, ending 
test!\n");
+      GNUNET_TESTING_daemons_stop (pg, TIMEOUT);
     }
 }
 
@@ -88,6 +88,7 @@
   peers_left = NUM_PEERS;
   pg = GNUNET_TESTING_daemons_start (sched, cfg,
                                      peers_left,
+                                     TIMEOUT,
                                      NULL, NULL,
                                      &my_cb, NULL, NULL, NULL, NULL);
   GNUNET_assert (pg != NULL);

Modified: gnunet/src/testing/test_testing_group_remote.c
===================================================================
--- gnunet/src/testing/test_testing_group_remote.c      2010-05-10 12:48:47 UTC 
(rev 11283)
+++ gnunet/src/testing/test_testing_group_remote.c      2010-05-10 13:38:57 UTC 
(rev 11284)
@@ -59,7 +59,7 @@
   peers_left--;
   if (peers_left == 0)
     {
-      GNUNET_TESTING_daemons_stop (pg);
+      GNUNET_TESTING_daemons_stop (pg, TIMEOUT);
       ok = 0;
     }
 }
@@ -88,6 +88,7 @@
   peers_left = num_peers;
   pg = GNUNET_TESTING_daemons_start (sched, cfg,
                                      peers_left,
+                                     TIMEOUT,
                                      &my_cb, NULL, NULL, NULL, hostnames);
   GNUNET_assert (pg != NULL);
 }

Modified: gnunet/src/testing/test_testing_topology.c
===================================================================
--- gnunet/src/testing/test_testing_topology.c  2010-05-10 12:48:47 UTC (rev 
11283)
+++ gnunet/src/testing/test_testing_topology.c  2010-05-10 13:38:57 UTC (rev 
11284)
@@ -33,7 +33,7 @@
 #define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 
600)
 
 /**
- * How long until we give up on connecting the peers?
+ * How long until we give up on starting the peers?
  */
 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
 
@@ -177,7 +177,7 @@
           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                       "Calling daemons_stop\n");
 #endif
-  GNUNET_TESTING_daemons_stop (pg);
+  GNUNET_TESTING_daemons_stop (pg, TIMEOUT);
 #if VERBOSE
           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                       "daemons_stop finished\n");
@@ -280,7 +280,7 @@
 
   if (pg != NULL)
     {
-      GNUNET_TESTING_daemons_stop (pg);
+      GNUNET_TESTING_daemons_stop (pg, TIMEOUT);
       ok = 7331;                /* Opposite of leet */
     }
   else
@@ -729,7 +729,7 @@
                                            &end_badly, "didn't start all 
daemons in reasonable amount of time!!!");
 
   pg = GNUNET_TESTING_daemons_start (sched, cfg,
-                                     peers_left, &hostkey_callback, NULL, 
&peers_started_callback, NULL,
+                                     peers_left, TIMEOUT, &hostkey_callback, 
NULL, &peers_started_callback, NULL,
                                      &topology_callback, NULL, NULL);
 
 }

Modified: gnunet/src/testing/testing.c
===================================================================
--- gnunet/src/testing/testing.c        2010-05-10 12:48:47 UTC (rev 11283)
+++ gnunet/src/testing/testing.c        2010-05-10 13:38:57 UTC (rev 11284)
@@ -126,7 +126,7 @@
     {
       d->server = NULL;
       if (GNUNET_YES == d->dead)
-        GNUNET_TESTING_daemon_stop (d, d->dead_cb, d->dead_cb_cls, GNUNET_YES);
+        GNUNET_TESTING_daemon_stop (d, 
GNUNET_TIME_absolute_get_remaining(d->max_timeout), d->dead_cb, d->dead_cb_cls, 
GNUNET_YES);
       else if (NULL != cb)
         cb (d->cb_cls, NULL, d->cfg, d,
             _("Failed to connect to core service\n"));
@@ -141,7 +141,7 @@
   d->server = server;
   d->running = GNUNET_YES;
   if (GNUNET_YES == d->dead)
-    GNUNET_TESTING_daemon_stop (d, d->dead_cb, d->dead_cb_cls, GNUNET_YES);
+    GNUNET_TESTING_daemon_stop (d, 
GNUNET_TIME_absolute_get_remaining(d->max_timeout), d->dead_cb, d->dead_cb_cls, 
GNUNET_YES);
   else if (NULL != cb)
     cb (d->cb_cls, my_identity, d->cfg, d, NULL);
 #if DEBUG_TESTING
@@ -155,7 +155,7 @@
   if (d->th == NULL)
     {
       if (GNUNET_YES == d->dead)
-        GNUNET_TESTING_daemon_stop (d, d->dead_cb, d->dead_cb_cls, GNUNET_YES);
+        GNUNET_TESTING_daemon_stop (d, 
GNUNET_TIME_absolute_get_remaining(d->max_timeout), d->dead_cb, d->dead_cb_cls, 
GNUNET_YES);
       else if (NULL != d->cb)
         d->cb (d->cb_cls, &d->id, d->cfg, d,
             _("Failed to connect to transport service!\n"));
@@ -196,15 +196,14 @@
       /* confirm copying complete */
       if (GNUNET_OK != GNUNET_OS_process_status (d->pid, &type, &code))
         {
-          d->wait_runs++;
-          if (d->wait_runs > MAX_EXEC_WAIT_RUNS)
+          if (GNUNET_TIME_absolute_get_remaining(d->max_timeout).value == 0)
             {
               cb = d->cb;
               d->cb = NULL;
               if (NULL != cb)
                 cb (d->cb_cls,
                     NULL,
-                    d->cfg, d, _("`scp' does not seem to terminate.\n"));
+                    d->cfg, d, _("`scp' does not seem to terminate (timeout 
copying config).\n"));
               return;
             }
           /* wait some more */
@@ -305,7 +304,6 @@
                   "gnunet-peerinfo");
 #endif
       d->phase = SP_HOSTKEY_CREATE;
-      d->wait_runs = 0;
       d->task
         = GNUNET_SCHEDULER_add_delayed (d->sched,
                                         GNUNET_CONSTANTS_EXEC_WAIT,
@@ -336,8 +334,7 @@
 
       if (GNUNET_OK != GNUNET_OS_process_status (d->pid, &type, &code))
         {
-          d->wait_runs++;
-          if (d->wait_runs > MAX_EXEC_WAIT_RUNS)
+          if (GNUNET_TIME_absolute_get_remaining(d->max_timeout).value == 0)
             {
               cb = d->cb;
               d->cb = NULL;
@@ -391,8 +388,7 @@
       /* Fall through */
     case SP_HOSTKEY_CREATED:
       /* wait for topology finished */
-      d->wait_runs++;
-      if ((GNUNET_YES == d->dead) || (d->wait_runs > MAX_EXEC_WAIT_RUNS))
+      if ((GNUNET_YES == d->dead) || 
(GNUNET_TIME_absolute_get_remaining(d->max_timeout).value == 0))
         {
           cb = d->cb;
           d->cb = NULL;
@@ -475,7 +471,6 @@
                   "gnunet-arm", "gnunet-service-core");
 #endif
       d->phase = SP_START_ARMING;
-      d->wait_runs = 0;
       d->task
         = GNUNET_SCHEDULER_add_delayed (d->sched,
                                         GNUNET_CONSTANTS_EXEC_WAIT,
@@ -484,8 +479,7 @@
     case SP_START_ARMING:
       if (GNUNET_OK != GNUNET_OS_process_status (d->pid, &type, &code))
         {
-          d->wait_runs++;
-          if (d->wait_runs > MAX_EXEC_WAIT_RUNS)
+          if (GNUNET_TIME_absolute_get_remaining(d->max_timeout).value == 0)
             {
               cb = d->cb;
               d->cb = NULL;
@@ -530,8 +524,7 @@
       /* confirm copying complete */
       if (GNUNET_OK != GNUNET_OS_process_status (d->pid, &type, &code))
         {
-          d->wait_runs++;
-          if (d->wait_runs > MAX_EXEC_WAIT_RUNS)
+          if (GNUNET_TIME_absolute_get_remaining(d->max_timeout).value == 0)
             {
               d->dead_cb (d->dead_cb_cls,
                           _("either `gnunet-arm' or `ssh' does not seem to 
terminate.\n"));
@@ -601,8 +594,7 @@
       /* confirm copying complete */
       if (GNUNET_OK != GNUNET_OS_process_status (d->pid, &type, &code))
         {
-          d->wait_runs++;
-          if (d->wait_runs > MAX_EXEC_WAIT_RUNS)
+          if (GNUNET_TIME_absolute_get_remaining(d->max_timeout).value == 0) 
/* FIXME: config update should take timeout parameter! */
             {
               cb = d->cb;
               d->cb = NULL;
@@ -659,6 +651,7 @@
  *
  * @param sched scheduler to use
  * @param cfg configuration to use
+ * @param timeout how long to wait starting up peers
  * @param hostname name of the machine where to run GNUnet
  *        (use NULL for localhost).
  * @param hostkey_callback function to call once the hostkey has been
@@ -672,6 +665,7 @@
 struct GNUNET_TESTING_Daemon *
 GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched,
                              const struct GNUNET_CONFIGURATION_Handle *cfg,
+                             struct GNUNET_TIME_Relative timeout,
                              const char *hostname,
                              GNUNET_TESTING_NotifyHostkeyCreated 
hostkey_callback,
                              void *hostkey_cls,
@@ -701,6 +695,7 @@
   ret->hostkey_cls = hostkey_cls;
   ret->cb = cb;
   ret->cb_cls = cb_cls;
+  ret->max_timeout = GNUNET_TIME_relative_to_absolute(timeout);
   ret->cfg = GNUNET_CONFIGURATION_dup (cfg);
   GNUNET_CONFIGURATION_set_value_string (ret->cfg,
                                          "PATHS",
@@ -868,7 +863,6 @@
     }
 
     GNUNET_free_non_null(del_arg);
-    d->wait_runs = 0;
     d->task
       = GNUNET_SCHEDULER_add_delayed (d->sched,
                                       GNUNET_CONSTANTS_EXEC_WAIT,
@@ -881,6 +875,7 @@
  * Stops a GNUnet daemon.
  *
  * @param d the daemon that should be stopped
+ * @param timeout how long to wait for process for shutdown to complete
  * @param cb function called once the daemon was stopped
  * @param cb_cls closure for cb
  * @param delete_files GNUNET_YES to remove files, GNUNET_NO
@@ -889,6 +884,7 @@
  */
 void
 GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
+                            struct GNUNET_TIME_Relative timeout,
                             GNUNET_TESTING_NotifyCompletion cb, void *cb_cls,
                             int delete_files)
 {
@@ -929,8 +925,7 @@
               _("Terminating peer `%4s'\n"), GNUNET_i2s (&d->id));
 #endif
 
-   d->phase = SP_SHUTDOWN_START;
-
+  d->phase = SP_SHUTDOWN_START;
   /* Check if this is a local or remote process */
   if (NULL != d->hostname)
     {
@@ -969,7 +964,7 @@
     }
 
   GNUNET_free_non_null(del_arg);
-  d->wait_runs = 0;
+  d->max_timeout = GNUNET_TIME_relative_to_absolute(timeout);
   d->task
     = GNUNET_SCHEDULER_add_delayed (d->sched,
                                     GNUNET_CONSTANTS_EXEC_WAIT,

Modified: gnunet/src/testing/testing_group.c
===================================================================
--- gnunet/src/testing/testing_group.c  2010-05-10 12:48:47 UTC (rev 11283)
+++ gnunet/src/testing/testing_group.c  2010-05-10 13:38:57 UTC (rev 11284)
@@ -240,6 +240,10 @@
    */
   unsigned int total;
 
+  /**
+   * At what time should we fail the peer startup process?
+   */
+  struct GNUNET_TIME_Absolute max_timeout;
 };
 
 /**
@@ -2380,6 +2384,7 @@
  * @param sched scheduler to use
  * @param cfg configuration template to use
  * @param total number of daemons to start
+ * @param timeout total time allowed for peers to start
  * @param hostkey_callback function to call on each peers hostkey generation
  *        if NULL, peers will be started by this call, if non-null,
  *        GNUNET_TESTING_daemons_continue_startup must be called after
@@ -2397,6 +2402,7 @@
 GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
                               const struct GNUNET_CONFIGURATION_Handle *cfg,
                               unsigned int total,
+                              struct GNUNET_TIME_Relative timeout,
                               GNUNET_TESTING_NotifyHostkeyCreated 
hostkey_callback,
                               void *hostkey_cls,
                               GNUNET_TESTING_NotifyDaemonRunning cb,
@@ -2432,6 +2438,7 @@
   pg->notify_connection = connect_callback;
   pg->notify_connection_cls = connect_callback_cls;
   pg->total = total;
+  pg->max_timeout = GNUNET_TIME_relative_to_absolute(timeout);
   pg->peers = GNUNET_malloc (total * sizeof (struct PeerData));
   if (NULL != hostnames)
     {
@@ -2533,6 +2540,7 @@
       pg->peers[off].pg = pg;
       pg->peers[off].daemon = GNUNET_TESTING_daemon_start (sched,
                                                            pcfg,
+                                                           timeout,
                                                            hostname,
                                                            hostkey_callback,
                                                            hostkey_cls,
@@ -2628,9 +2636,11 @@
  * Shutdown all peers started in the given group.
  *
  * @param pg handle to the peer group
+ * @param timeout how long to wait for shutdown
+ *
  */
 void
-GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg)
+GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg, struct 
GNUNET_TIME_Relative timeout)
 {
   unsigned int off;
 
@@ -2642,7 +2652,7 @@
          as well... */
 
       if (NULL != pg->peers[off].daemon)
-        GNUNET_TESTING_daemon_stop (pg->peers[off].daemon, NULL, NULL, 
GNUNET_YES);
+        GNUNET_TESTING_daemon_stop (pg->peers[off].daemon, timeout, NULL, 
NULL, GNUNET_YES);
       if (NULL != pg->peers[off].cfg)
         GNUNET_CONFIGURATION_destroy (pg->peers[off].cfg);
 





reply via email to

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