gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r12978 - gnunet/src/testing
Date: Tue, 14 Sep 2010 10:45:05 +0200

Author: nevans
Date: 2010-09-14 10:45:05 +0200 (Tue, 14 Sep 2010)
New Revision: 12978

Modified:
   gnunet/src/testing/test_testing.c
   gnunet/src/testing/test_testing_group_remote.c
   gnunet/src/testing/testing.c
   gnunet/src/testing/testing_group.c
Log:
some testing changes, features added

Modified: gnunet/src/testing/test_testing.c
===================================================================
--- gnunet/src/testing/test_testing.c   2010-09-14 08:34:05 UTC (rev 12977)
+++ gnunet/src/testing/test_testing.c   2010-09-14 08:45:05 UTC (rev 12978)
@@ -74,7 +74,7 @@
 #if VERBOSE
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemon.\n");
 #endif
-  d = GNUNET_TESTING_daemon_start (sched, cfg, TIMEOUT, NULL, NULL, NULL, 
&my_cb, NULL);
+  d = GNUNET_TESTING_daemon_start (sched, cfg, TIMEOUT, NULL, NULL, 0, NULL, 
NULL, &my_cb, NULL);
   GNUNET_assert (d != NULL);
 }
 

Modified: gnunet/src/testing/test_testing_group_remote.c
===================================================================
--- gnunet/src/testing/test_testing_group_remote.c      2010-09-14 08:34:05 UTC 
(rev 12977)
+++ gnunet/src/testing/test_testing_group_remote.c      2010-09-14 08:45:05 UTC 
(rev 12978)
@@ -88,13 +88,13 @@
   peers_left--;
   if (peers_left == 0)
     {
-      GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
+      //GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
       ok = 0;
     }
   else if (peers_failed == peers_left)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Too many peers failed, ending 
test!\n");
-      GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
+      //GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
     }
 }
 
@@ -113,6 +113,7 @@
   char *buf;
   char *data;
   int count;
+  int ret;
   sched = s;
   ok = 1;
 #if VERBOSE
@@ -165,11 +166,27 @@
     while (count < frstat.st_size)
       {
         count++;
-        if (((data[count] == '\n') || (data[count] == '\0')) && (buf != 
&data[count]))
+        if (count >= frstat.st_size)
+          break;
+
+        /* if (((data[count] == '\n') || (data[count] == '\0')) && (buf != 
&data[count]))*/
+        if (((data[count] == '\n')) && (buf != &data[count]))
           {
             data[count] = '\0';
             temphost = GNUNET_malloc(sizeof(struct GNUNET_TESTING_Host));
-            temphost->hostname = buf;
+            ret = sscanf(buf, "address@hidden:%hd", &temphost->username, 
&temphost->hostname, &temphost->port);
+            if (3 == ret)
+              {
+                GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Successfully read host 
%s, port %d and user %s from file\n", temphost->hostname, temphost->port, 
temphost->username);
+              }
+            else
+              {
+                GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Error reading line `%s' 
in hostfile\n", buf);
+                GNUNET_free(temphost);
+                buf = &data[count + 1];
+                continue;
+              }
+            /* temphost->hostname = buf; */
             temphost->next = hosts;
             hosts = temphost;
             buf = &data[count + 1];
@@ -195,11 +212,14 @@
   while (hostpos != NULL)
     {
       temphost = hostpos->next;
+      GNUNET_free(hostpos->hostname);
+      GNUNET_free(hostpos->username);
       GNUNET_free(hostpos);
       hostpos = temphost;
     }
   GNUNET_free_non_null(data);
   GNUNET_assert (pg != NULL);
+
 }
 
 static int

Modified: gnunet/src/testing/testing.c
===================================================================
--- gnunet/src/testing/testing.c        2010-09-14 08:34:05 UTC (rev 12977)
+++ gnunet/src/testing/testing.c        2010-09-14 08:45:05 UTC (rev 12978)
@@ -283,14 +283,28 @@
                       "gnunet-peerinfo", "ssh", dst, "gnunet-peerinfo", "-c", 
d->cfgfile,
                       "-sq");
 #endif
-          d->pid = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh",
-                                            "ssh",
+          if (d->ssh_port_str == NULL)
+            {
+              d->pid = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh",
+                                                "ssh",
 #if !DEBUG_TESTING
-                                            "-q",
+                                                "-q",
 #endif
-                                            dst,
-                                            "gnunet-peerinfo",
-                                            "-c", d->cfgfile, "-sq", NULL);
+                                                dst,
+                                                "gnunet-peerinfo",
+                                                "-c", d->cfgfile, "-sq", NULL);
+            }
+          else
+            {
+              d->pid = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh",
+                                                "ssh", "-p", d->ssh_port_str,
+#if !DEBUG_TESTING
+                                                "-q",
+#endif
+                                                dst,
+                                                "gnunet-peerinfo",
+                                                "-c", d->cfgfile, "-sq", NULL);
+            }
           GNUNET_DISK_pipe_close_end(d->pipe_stdout, 
GNUNET_DISK_PIPE_END_WRITE);
           GNUNET_free (dst);
         }
@@ -446,17 +460,35 @@
                       "gnunet-arm", "ssh", dst, "gnunet-arm", "-c", d->cfgfile,
                       "-L", "DEBUG", "-s", "-q");
 #endif
-          d->pid = GNUNET_OS_start_process (NULL, NULL, "ssh",
-                                            "ssh",
+          if (d->ssh_port_str == NULL)
+            {
+              d->pid = GNUNET_OS_start_process (NULL, NULL, "ssh",
+                                                "ssh",
 #if !DEBUG_TESTING
-                                            "-q",
+                                                "-q",
 #endif
-                                            dst,
-                                            "gnunet-arm",
+                                                dst,
+                                                "gnunet-arm",
 #if DEBUG_TESTING
-                                            "-L", "DEBUG",
+                                                "-L", "DEBUG",
 #endif
-                                            "-c", d->cfgfile, "-s", "-q", 
NULL);
+                                                "-c", d->cfgfile, "-s", "-q", 
NULL);
+            }
+          else
+            {
+
+              d->pid = GNUNET_OS_start_process (NULL, NULL, "ssh",
+                                                "ssh", "-p", d->ssh_port_str,
+#if !DEBUG_TESTING
+                                                "-q",
+#endif
+                                                dst,
+                                                "gnunet-arm",
+#if DEBUG_TESTING
+                                                "-L", "DEBUG",
+#endif
+                                                "-c", d->cfgfile, "-s", "-q", 
NULL);
+            }
           GNUNET_free (dst);
         }
       if (-1 == d->pid)
@@ -708,6 +740,8 @@
  * @param timeout how long to wait starting up peers
  * @param hostname name of the machine where to run GNUnet
  *        (use NULL for localhost).
+ * @param ssh_username ssh username to use when connecting to hostname
+ * @param sshport port to pass to ssh process when connecting to hostname
  * @param hostkey_callback function to call once the hostkey has been
  *        generated for this peer, but it hasn't yet been started
  *        (NULL to start immediately, otherwise waits on 
GNUNET_TESTING_daemon_continue_start)
@@ -721,6 +755,8 @@
                              const struct GNUNET_CONFIGURATION_Handle *cfg,
                              struct GNUNET_TIME_Relative timeout,
                              const char *hostname,
+                             const char *ssh_username,
+                             uint16_t sshport,
                              GNUNET_TESTING_NotifyHostkeyCreated 
hostkey_callback,
                              void *hostkey_cls,
                              GNUNET_TESTING_NotifyDaemonRunning cb,
@@ -733,6 +769,12 @@
   ret = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Daemon));
   ret->sched = sched;
   ret->hostname = (hostname == NULL) ? NULL : GNUNET_strdup (hostname);
+  if (sshport != 0)
+    {
+      GNUNET_asprintf(&ret->ssh_port_str, "%d", sshport);
+    }
+  else
+    ret->ssh_port_str = NULL;
   ret->cfgfile = GNUNET_DISK_mktemp ("gnunet-testing-config");
 #if DEBUG_TESTING
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -766,10 +808,12 @@
       GNUNET_free (ret);
       return NULL;
     }
-  if (GNUNET_OK !=
+  if (ssh_username != NULL)
+    username = GNUNET_strdup(ssh_username);
+  if ((ssh_username == NULL) && (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_string (cfg,
                                              "TESTING",
-                                             "USERNAME", &username))
+                                             "USERNAME", &username)))
     {
       if (NULL != getenv ("USER"))
         username = GNUNET_strdup (getenv ("USER"));
@@ -790,12 +834,25 @@
         GNUNET_asprintf (&arg, "address@hidden:%s", username, hostname, 
ret->cfgfile);
       else
         GNUNET_asprintf (&arg, "%s:%s", hostname, ret->cfgfile);
-      ret->pid = GNUNET_OS_start_process (NULL, NULL, "scp",
-                                          "scp",
+
+      if (ret->ssh_port_str == NULL)
+        {
+          ret->pid = GNUNET_OS_start_process (NULL, NULL, "scp",
+                                              "scp",
 #if !DEBUG_TESTING
-                                          "-q",
+                                              "-q",
 #endif
-                                          ret->cfgfile, arg, NULL);
+                                              ret->cfgfile, arg, NULL);
+        }
+      else
+        {
+          ret->pid = GNUNET_OS_start_process (NULL, NULL, "scp",
+                                              "scp", "-P", ret->ssh_port_str,
+#if !DEBUG_TESTING
+                                              "-q",
+#endif
+                                              ret->cfgfile, arg, NULL);
+        }
       GNUNET_free (arg);
       if (-1 == ret->pid)
         {
@@ -983,6 +1040,7 @@
       GNUNET_free_non_null (d->username);
       if (NULL != d->dead_cb)
         d->dead_cb (d->dead_cb_cls, NULL);
+      GNUNET_free(d);
       return;
     }
 

Modified: gnunet/src/testing/testing_group.c
===================================================================
--- gnunet/src/testing/testing_group.c  2010-09-14 08:34:05 UTC (rev 12977)
+++ gnunet/src/testing/testing_group.c  2010-09-14 08:45:05 UTC (rev 12978)
@@ -242,6 +242,18 @@
    * Hostname, where to start the peer
    */
   const char *hostname;
+
+  /**
+   * Username to use when connecting to the
+   * host via ssh.
+   */
+  const char *username;
+
+  /**
+   * Port to use for ssh.
+   */
+  uint16_t sshport;
+
 };
 
 /**
@@ -312,6 +324,16 @@
   char *hostname;
 
   /**
+   * SSH username to use when connecting to this host.
+   */
+  char *username;
+
+  /**
+   * SSH port to use when connecting to this host.
+   */
+  uint16_t sshport;
+
+  /**
    * Lowest port that we have not yet used
    * for GNUnet.
    */
@@ -729,6 +751,7 @@
           value = uval;
         }
       GNUNET_free(single_variable);
+      GNUNET_free(per_host_variable);
 
     }
 
@@ -816,6 +839,7 @@
       GNUNET_CONFIGURATION_set_value_string(uc.ret, "transport-udp", "BINDTO", 
"127.0.0.1");
     }
 
+
   *port = (uint16_t) uc.nport;
   *upnum = uc.upnum;
   uc.fdnum++;
@@ -3312,6 +3336,8 @@
                                                                     
internal_context->peer->cfg,
                                                                     
internal_context->timeout,
                                                                     
internal_context->hostname,
+                                                                    
internal_context->username,
+                                                                    
internal_context->sshport,
                                                                     
&internal_hostkey_callback,
                                                                     
internal_context,
                                                                     
&internal_startup_callback,
@@ -3387,6 +3413,7 @@
   char *start;
 #endif
   const char *hostname;
+  const char *username;
   char *baseservicehome;
   char *newservicehome;
   char *tmpdir;
@@ -3394,6 +3421,7 @@
   unsigned int off;
   unsigned int hostcnt;
   uint16_t minport;
+  uint16_t sshport;
   uint32_t upnum;
   uint32_t fdnum;
 
@@ -3428,7 +3456,11 @@
       while (hostpos != NULL)
         {
           pg->hosts[off].minport = LOW_PORT;
-          pg->hosts[off++].hostname = GNUNET_strdup(hostpos->hostname);
+          off++;
+          pg->hosts[off].hostname = GNUNET_strdup(hostpos->hostname);
+          if (hostpos->username != NULL)
+            pg->hosts[off].username = GNUNET_strdup(hostpos->username);
+          pg->hosts[off].sshport = hostpos->port;
           hostpos = hostpos->next;
         }
 
@@ -3495,6 +3527,8 @@
       if (hostcnt > 0)
         {
           hostname = pg->hosts[off % hostcnt].hostname;
+          username = pg->hosts[off % hostcnt].username;
+          sshport = pg->hosts[off % hostcnt].sshport;
           pcfg = make_config (cfg, 
                              &pg->hosts[off % hostcnt].minport,
                              &upnum,
@@ -3503,6 +3537,8 @@
       else
         {
           hostname = NULL;
+          username = NULL;
+          sshport = 0;
           pcfg = make_config (cfg,
                              &minport,
                              &upnum,
@@ -3548,6 +3584,8 @@
       pg->peers[off].internal_context.peer = &pg->peers[off];
       pg->peers[off].internal_context.timeout = timeout;
       pg->peers[off].internal_context.hostname = hostname;
+      pg->peers[off].internal_context.username = username;
+      pg->peers[off].internal_context.sshport = sshport;
       pg->peers[off].internal_context.hostkey_callback = hostkey_callback;
       pg->peers[off].internal_context.hostkey_cls = hostkey_cls;
       pg->peers[off].internal_context.start_cb = cb;
@@ -3740,6 +3778,28 @@
   }
 }
 
+/**
+ * Count the number of running peers.
+ *
+ * @param pg handle for the peer group
+ *
+ * @return the number of currently running peers in the peer group
+ */
+unsigned int
+GNUNET_TESTING_daemons_running (struct GNUNET_TESTING_PeerGroup *pg)
+{
+  unsigned int i;
+  unsigned int running = 0;
+  for (i = 0; i < pg->total; i++)
+  {
+    if (pg->peers[i].daemon->running == GNUNET_YES)
+    {
+      GNUNET_assert(running != -1);
+      running++;
+    }
+  }
+  return running;
+}
 
 /**
  * Simulate churn by stopping some peers (and possibly




reply via email to

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