- dist fix
[oweals/gnunet.git] / src / testing_old / testing_group.c
index 46c513970e52d8abcbf6ebcb73fe3df8cb187e04..66c498256ca5583a8f3a6d841e48636b27107c0f 100644 (file)
@@ -19,7 +19,7 @@
  */
 
 /**
- * @file testing/testing_group.c
+ * @file testing_old/testing_group.c
  * @brief convenience API for writing testcases for GNUnet
  * @author Nathan Evans
  * @author Christian Grothoff
 #define TOPOLOGY_HACK GNUNET_YES
 
 
+/**
+ * How long do we wait after a FORK+EXEC before testing for the
+ * resulting process to be up (port open, waitpid, etc.)?
+ */
+#define GNUNET_CONSTANTS_EXEC_WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 200)
+
 /**
  * Lowest port used for GNUnet testing.  Should be high enough to not
  * conflict with other applications running on the hosts but be low
@@ -1037,9 +1043,9 @@ struct ProgressMeter
  * @param hash set to uid (extended with zeros)
  */
 static void
-hash_from_uid (uint32_t uid, GNUNET_HashCode * hash)
+hash_from_uid (uint32_t uid, struct GNUNET_HashCode * hash)
 {
-  memset (hash, 0, sizeof (GNUNET_HashCode));
+  memset (hash, 0, sizeof (struct GNUNET_HashCode));
   *((uint32_t *) hash) = uid;
 }
 
@@ -1050,7 +1056,7 @@ hash_from_uid (uint32_t uid, GNUNET_HashCode * hash)
  * @param hash set to uid (extended with zeros)
  */
 static void
-uid_from_hash (const GNUNET_HashCode * hash, uint32_t * uid)
+uid_from_hash (const struct GNUNET_HashCode * hash, uint32_t * uid)
 {
   memcpy (uid, hash, sizeof (uint32_t));
 }
@@ -1579,8 +1585,8 @@ remove_connections (struct GNUNET_TESTING_PeerGroup *pg, unsigned int first,
   struct PeerConnection **second_tail;
 
 #else
-  GNUNET_HashCode hash_first;
-  GNUNET_HashCode hash_second;
+  struct GNUNET_HashCode hash_first;
+  struct GNUNET_HashCode hash_second;
 
   hash_from_uid (first, &hash_first);
   hash_from_uid (second, &hash_second);
@@ -2470,7 +2476,7 @@ create_clique (struct GNUNET_TESTING_PeerGroup *pg,
  *         GNUNET_NO if not.
  */
 static int
-unblacklist_iterator (void *cls, const GNUNET_HashCode * key, void *value)
+unblacklist_iterator (void *cls, const struct GNUNET_HashCode * key, void *value)
 {
   struct UnblacklistContext *un_ctx = cls;
   uint32_t second_pos;
@@ -2760,7 +2766,7 @@ create_ring (struct GNUNET_TESTING_PeerGroup *pg,
  *       "fixing" now.
  */
 static int
-friend_file_iterator (void *cls, const GNUNET_HashCode * key, void *value)
+friend_file_iterator (void *cls, const struct GNUNET_HashCode * key, void *value)
 {
   FILE *temp_friend_handle = cls;
   struct GNUNET_TESTING_Daemon *peer = value;
@@ -2797,7 +2803,7 @@ struct BlacklistContext
  * @return GNUNET_YES to continue iteration
  */
 static int
-blacklist_file_iterator (void *cls, const GNUNET_HashCode * key, void *value)
+blacklist_file_iterator (void *cls, const struct GNUNET_HashCode * key, void *value)
 {
   struct BlacklistContext *blacklist_ctx = cls;
   struct GNUNET_TESTING_Daemon *peer = value;
@@ -2904,7 +2910,7 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg)
                          pg->peers[pg_iter].daemon->hostname,
                          temp_service_path);
       procarr[pg_iter] =
-       GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "scp", "scp", mytemp, arg, NULL);
+       GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "scp", "scp", mytemp, arg, NULL);
       GNUNET_assert (procarr[pg_iter] != NULL);
       ret = GNUNET_OS_process_wait (procarr[pg_iter]);  /* FIXME: schedule this, throttle! */
       GNUNET_OS_process_destroy (procarr[pg_iter]);
@@ -3090,7 +3096,7 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg,
                          pg->peers[pg_iter].daemon->hostname,
                          temp_service_path);
       procarr[pg_iter] =
-       GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "scp", "scp", mytemp, arg, NULL);
+       GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "scp", "scp", mytemp, arg, NULL);
       GNUNET_assert (procarr[pg_iter] != NULL);
       GNUNET_OS_process_wait (procarr[pg_iter]);        /* FIXME: add scheduled blacklist file copy that parallelizes file copying! */
 
@@ -3682,7 +3688,7 @@ schedule_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  * @return GNUNET_YES to continue iteration
  */
 static int
-connect_iterator (void *cls, const GNUNET_HashCode * key, void *value)
+connect_iterator (void *cls, const struct GNUNET_HashCode * key, void *value)
 {
   struct ConnectTopologyContext *ct_ctx = cls;
   struct PeerData *first = ct_ctx->first;
@@ -3713,7 +3719,7 @@ connect_iterator (void *cls, const GNUNET_HashCode * key, void *value)
  * @return GNUNET_YES to continue iteration
  */
 static int
-copy_topology_iterator (void *cls, const GNUNET_HashCode * key, void *value)
+copy_topology_iterator (void *cls, const struct GNUNET_HashCode * key, void *value)
 {
   struct PeerData *first = cls;
 
@@ -3890,9 +3896,9 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg,
 
   for (i = 0; i < pg->total; i++)
   {
-    pg->peers[i].allowed_peers = GNUNET_CONTAINER_multihashmap_create (100);
-    pg->peers[i].connect_peers = GNUNET_CONTAINER_multihashmap_create (100);
-    pg->peers[i].blacklisted_peers = GNUNET_CONTAINER_multihashmap_create (100);
+    pg->peers[i].allowed_peers = GNUNET_CONTAINER_multihashmap_create (100, GNUNET_NO);
+    pg->peers[i].connect_peers = GNUNET_CONTAINER_multihashmap_create (100, GNUNET_NO);
+    pg->peers[i].blacklisted_peers = GNUNET_CONTAINER_multihashmap_create (100, GNUNET_NO);
     pg->peers[i].pg = pg;
   }
 #endif
@@ -4108,12 +4114,12 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg,
  * @return GNUNET_YES to continue iteration
  */
 static int
-random_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value)
+random_connect_iterator (void *cls, const struct GNUNET_HashCode * key, void *value)
 {
   struct RandomContext *random_ctx = cls;
   double random_number;
   uint32_t second_pos;
-  GNUNET_HashCode first_hash;
+  struct GNUNET_HashCode first_hash;
 
   random_number =
       ((double)
@@ -4153,11 +4159,11 @@ random_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value)
  * @return GNUNET_YES to continue iteration
  */
 static int
-minimum_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value)
+minimum_connect_iterator (void *cls, const struct GNUNET_HashCode * key, void *value)
 {
   struct MinimumContext *min_ctx = cls;
   uint32_t second_pos;
-  GNUNET_HashCode first_hash;
+  struct GNUNET_HashCode first_hash;
   unsigned int i;
 
   if (GNUNET_CONTAINER_multihashmap_size
@@ -4211,10 +4217,10 @@ minimum_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value)
  * @return GNUNET_YES to continue iteration
  */
 static int
-dfs_connect_iterator (void *cls, const GNUNET_HashCode * key, void *value)
+dfs_connect_iterator (void *cls, const struct GNUNET_HashCode * key, void *value)
 {
   struct DFSContext *dfs_ctx = cls;
-  GNUNET_HashCode first_hash;
+  struct GNUNET_HashCode first_hash;
 
   if (dfs_ctx->current == dfs_ctx->chosen)
   {
@@ -4291,7 +4297,7 @@ choose_random_connections (struct GNUNET_TESTING_PeerGroup *pg,
     random_ctx.percentage = percentage;
     random_ctx.pg = pg;
     pg->peers[pg_iter].connect_peers_working_set =
-        GNUNET_CONTAINER_multihashmap_create (pg->total);
+      GNUNET_CONTAINER_multihashmap_create (pg->total, GNUNET_NO);
     GNUNET_CONTAINER_multihashmap_iterate (pg->peers[pg_iter].connect_peers,
                                            &random_connect_iterator,
                                            &random_ctx);
@@ -4450,7 +4456,7 @@ choose_minimum (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num)
   for (pg_iter = 0; pg_iter < pg->total; pg_iter++)
   {
     pg->peers[pg_iter].connect_peers_working_set =
-        GNUNET_CONTAINER_multihashmap_create (num);
+      GNUNET_CONTAINER_multihashmap_create (num, GNUNET_NO);
   }
 
   for (pg_iter = 0; pg_iter < pg->total; pg_iter++)
@@ -4538,7 +4544,7 @@ struct FindClosestContext
  *         GNUNET_NO if not.
  */
 static int
-find_closest_peers (void *cls, const GNUNET_HashCode * key, void *value)
+find_closest_peers (void *cls, const struct GNUNET_HashCode * key, void *value)
 {
   struct FindClosestContext *closest_ctx = cls;
   struct GNUNET_TESTING_Daemon *daemon = value;
@@ -4627,7 +4633,7 @@ perform_dfs (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num)
   struct PeerConnection *peer_iter;
 #else
   struct DFSContext dfs_ctx;
-  GNUNET_HashCode second_hash;
+  struct GNUNET_HashCode second_hash;
 #endif
 
 #if OLD
@@ -4679,7 +4685,7 @@ perform_dfs (struct GNUNET_TESTING_PeerGroup *pg, unsigned int num)
   for (pg_iter = 0; pg_iter < pg->total; pg_iter++)
   {
     pg->peers[pg_iter].connect_peers_working_set =
-        GNUNET_CONTAINER_multihashmap_create (num);
+      GNUNET_CONTAINER_multihashmap_create (num, GNUNET_NO);
   }
 
   starting_peer = 0;
@@ -5693,7 +5699,7 @@ start_peer_helper (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 
   /* FIXME: Doesn't support ssh_port option! */
   helper->proc =
-    GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "ssh", "ssh", arg,
+    GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "ssh", "ssh", arg,
                                "peerStartHelper.pl", tempdir, NULL);
   GNUNET_assert (helper->proc != NULL);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "starting peers with cmd ssh %s %s %s\n",
@@ -5916,13 +5922,13 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
     {
       GNUNET_asprintf (&ssh_port_str, "%d", pg->hosts[i].sshport);
       proc =
-       GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "ssh", "ssh", "-P", ssh_port_str,
+       GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "ssh", "ssh", "-P", ssh_port_str,
                                    "-q",
                                    arg, "mkdir -p", tmpdir, NULL);
     }
     else
       proc =
-       GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "ssh", "ssh", arg, "mkdir -p",
+       GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "ssh", "ssh", arg, "mkdir -p",
                                    tmpdir, NULL);
     GNUNET_assert (proc != NULL);
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -5940,9 +5946,26 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
       GNUNET_CONFIGURATION_get_value_string (cfg, "TESTING_OLD", "HOSTKEYSFILE",
                                              &hostkeys_file))
   {
+    /* This is a hack to make old testing able to load keys from datadir,
+     * just as new testing does.
+     * No need to document it, just convert everything to the new testing
+     * framework...
+     */
+    char *DATADIR = "${DATADIR}";
+    size_t ddl = strlen (DATADIR);
+    if (strncmp (hostkeys_file, DATADIR, ddl) == 0)
+    {
+      char *data_dir;
+      char *filename;
+      data_dir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
+      GNUNET_asprintf (&filename, "%s%s", data_dir, &hostkeys_file[ddl]);
+      GNUNET_free (data_dir);
+      GNUNET_free (hostkeys_file);
+      hostkeys_file = filename;
+    }
     if (GNUNET_YES != GNUNET_DISK_file_test (hostkeys_file))
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                  _("Could not read hostkeys file!\n"));
+                  _("Could not read hostkeys file `%s'!\n"), hostkeys_file);
     else
     {
       /* Check hostkey file size, read entire thing into memory */
@@ -6141,7 +6164,7 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
 
       /* FIXME: Doesn't support ssh_port option! */
       proc =
-       GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "rsync", "rsync", "-r",
+       GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "rsync", "rsync", "-r",
                                    newservicehome, arg, NULL);
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   "copying directory with command rsync -r %s %s\n",