gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r1049 - in GNUnet/src/applications: dht/tools fs/ecrs fs/fs


From: grothoff
Subject: [GNUnet-SVN] r1049 - in GNUnet/src/applications: dht/tools fs/ecrs fs/fsui fs/lib gap session tbench
Date: Sun, 26 Jun 2005 04:34:17 -0700 (PDT)

Author: grothoff
Date: 2005-06-26 04:34:04 -0700 (Sun, 26 Jun 2005)
New Revision: 1049

Modified:
   GNUnet/src/applications/dht/tools/dhttest2.c
   GNUnet/src/applications/fs/ecrs/check.conf
   GNUnet/src/applications/fs/ecrs/ecrstest.c
   GNUnet/src/applications/fs/ecrs/namespacetest.c
   GNUnet/src/applications/fs/ecrs/searchtest.c
   GNUnet/src/applications/fs/fsui/check.conf
   GNUnet/src/applications/fs/fsui/downloadtest.c
   GNUnet/src/applications/fs/fsui/fsuitest.c
   GNUnet/src/applications/fs/fsui/fsuitest2.c
   GNUnet/src/applications/fs/fsui/searchtest.c
   GNUnet/src/applications/fs/lib/check.conf
   GNUnet/src/applications/fs/lib/fslibtest.c
   GNUnet/src/applications/gap/gaptest.c
   GNUnet/src/applications/session/sessiontest.c
   GNUnet/src/applications/tbench/tbenchtest.c
Log:
converting testcases to use daemon.c where possible

Modified: GNUnet/src/applications/dht/tools/dhttest2.c
===================================================================
--- GNUnet/src/applications/dht/tools/dhttest2.c        2005-06-26 11:33:02 UTC 
(rev 1048)
+++ GNUnet/src/applications/dht/tools/dhttest2.c        2005-06-26 11:34:04 UTC 
(rev 1049)
@@ -80,96 +80,47 @@
                         "5B2Q58IEU1VF5FTR838449CSHVBOAHLDVQAOA33O77F"
                         "OPDA8F1VIKESLSNBO",
                         &peer2.hashPubKey));
-  /* set to 0 if you want to start gnunetd's by hand for debugging */
-#if 0
-  daemon1 = fork();
-  if (daemon1 == 0) {
-    if (0 != execlp("gnunetd", /* what binary to execute, must be in $PATH! */
-                   "gnunetd", /* arg0, path to gnunet binary */
-                   "-d",  /* do not daemonize so we can easily kill you */
-                   "-c",
-                   "peer1.conf", /* configuration file */
-                   NULL)) {
-      fprintf(stderr,
-             _("'%s' failed: %s\n"),
-             "execlp",
-             STRERROR(errno));
-      return -1;
-    }
-  }
-  daemon2 = fork();
-  if (daemon2 == 0) {
-    if (0 != execlp("gnunetd", /* what binary to execute, must be in $PATH! */
-                   "gnunetd", /* arg0, path to gnunet binary */
-                   "-d",  /* do not daemonize so we can easily kill you */
-                   "-c",
-                   "peer2.conf", /* configuration file */
-                   NULL)) {
-      fprintf(stderr,
-             _("'%s' failed: %s\n"),
-             "execlp",
-             STRERROR(errno));
-      return -1;
-    }
-  }
+  if (OK != initUtil(argc,
+                    argv, 
+                    &parseOptions))
+    return -1;
+  FREENONNULL(setConfigurationString("GNUNET",
+                                    "GNUNETD-CONFIG",
+                                    "peer1.conf"));
+  daemon1 = startGNUnetDaemon(NO);
+  FREENONNULL(setConfigurationString("GNUNET",
+                                    "GNUNETD-CONFIG",
+                                    "peer2.conf"));
+  daemon2 = startGNUnetDaemon(NO);
   /* in case existing HELOs have expired */
-  sleep(5);
+  gnunet_util_sleep(30 * cronSECONDS);
   system("cp peer1/data/hosts/* peer2/data/hosts/");
   system("cp peer2/data/hosts/* peer1/data/hosts/");
   if (daemon1 != -1) {
     if (0 != kill(daemon1, SIGTERM))
       DIE_STRERROR("kill");
-    if (daemon1 != waitpid(daemon1, &status, 0))
-      DIE_STRERROR("waitpid");
+    GNUNET_ASSERT(OK == waitForGNUnetDaemonTermination(daemon1));
   }
   if (daemon2 != -1) {
     if (0 != kill(daemon2, SIGTERM))
       DIE_STRERROR("kill");
-    if (daemon2 != waitpid(daemon2, &status, 0))
-      DIE_STRERROR("waitpid");
+    GNUNET_ASSERT(OK == waitForGNUnetDaemonTermination(daemon2));
   }
 
   /* re-start, this time we're sure up-to-date HELOs are available */
-  daemon1 = fork();
-  if (daemon1 == 0) {
-    if (0 != execlp("gnunetd", /* what binary to execute, must be in $PATH! */
-                   "gnunetd", /* arg0, path to gnunet binary */
-                   "-d",  /* do not daemonize so we can easily kill you */
-                   "-c",
-                   "peer1.conf", /* configuration file */
-                   NULL)) {
-      fprintf(stderr,
-             _("'%s' failed: %s\n"),
-             "execlp",
-             STRERROR(errno));
-      return -1;
-    }
-  }
-  daemon2 = fork();
-  if (daemon2 == 0) {
-    if (0 != execlp("gnunetd", /* what binary to execute, must be in $PATH! */
-                   "gnunetd", /* arg0, path to gnunet binary */
-                   "-d",  /* do not daemonize so we can easily kill you */
-                   "-c",
-                   "peer2.conf", /* configuration file */
-                   NULL)) {
-      fprintf(stderr,
-             _("'%s' failed: %s\n"),
-             "execlp",
-             STRERROR(errno));
-      return -1;
-    }
-  }
-  sleep(5);
+  FREENONNULL(setConfigurationString("GNUNET",
+                                    "GNUNETD-CONFIG",
+                                    "peer1.conf"));
+  daemon1 = startGNUnetDaemon(NO);
+  FREENONNULL(setConfigurationString("GNUNET",
+                                    "GNUNETD-CONFIG",
+                                    "peer2.conf"));
+  daemon2 = startGNUnetDaemon(NO);
+    gnunet_util_sleep(5 * cronSECONDS);
 
   ret = 0;
   left = 5;
   /* wait for connection or abort with error */
-#else
-  daemon1 = -1;
-  daemon2 = -1;
-#endif
-  CHECK(OK == initUtil(argc, argv, &parseOptions));
   startCron();
   do {
     sock = getClientSocket();
@@ -279,22 +230,18 @@
 
  FAILURE:
   stopCron();
-  doneUtil();
-
-  /* also shutdown daemons again */
   if (daemon1 != -1) {
     if (0 != kill(daemon1, SIGTERM))
       DIE_STRERROR("kill");
-    if (daemon1 != waitpid(daemon1, &status, 0))
-      DIE_STRERROR("waitpid");
+    GNUNET_ASSERT(OK == waitForGNUnetDaemonTermination(daemon1));
   }
   if (daemon2 != -1) {
     if (0 != kill(daemon2, SIGTERM))
       DIE_STRERROR("kill");
-    if (daemon2 != waitpid(daemon2, &status, 0))
-      DIE_STRERROR("waitpid");
-  }
+    GNUNET_ASSERT(OK == waitForGNUnetDaemonTermination(daemon2));
+  } 
+  doneUtil();
   return ret;
 }
 
-/* end of dhytest.c */
+/* end of dhttest2.c */

Modified: GNUnet/src/applications/fs/ecrs/check.conf
===================================================================
--- GNUnet/src/applications/fs/ecrs/check.conf  2005-06-26 11:33:02 UTC (rev 
1048)
+++ GNUnet/src/applications/fs/ecrs/check.conf  2005-06-26 11:34:04 UTC (rev 
1049)
@@ -10,7 +10,7 @@
 KEEPLOG         = 0
 PIDFILE         = $GNUNETD_HOME/gnunetd.pid
 HOSTS          = $GNUNETD_HOME/data/hosts/
-APPLICATIONS = "fs getoption"
+APPLICATIONS = "fs getoption traffic"
 # TRANSPORTS = -- no transports!
 
 [MODULES]

Modified: GNUnet/src/applications/fs/ecrs/ecrstest.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/ecrstest.c  2005-06-26 11:33:02 UTC (rev 
1048)
+++ GNUnet/src/applications/fs/ecrs/ecrstest.c  2005-06-26 11:34:04 UTC (rev 
1049)
@@ -43,6 +43,9 @@
   FREENONNULL(setConfigurationString("GNUNET",
                                     "LOGLEVEL",
                                     "NOTHING"));
+  FREENONNULL(setConfigurationString("GNUNET",
+                                    "GNUNETD-CONFIG",
+                                    "check.conf"));
   return OK;
 }
 
@@ -258,26 +261,16 @@
   struct ECRS_URI * uri;
   int i;
 
-  daemon = fork();
-  if (daemon == 0) {
-    if (0 != execlp("gnunetd", /* what binary to execute, must be in $PATH! */
-                   "gnunetd", /* arg0, path to gnunet binary */
-                   "-d",  /* do not daemonize so we can easily kill you */
-                   /* "-L", "NOTHING", */
-                   "-c",
-                   "check.conf", /* configuration file */
-                   NULL)) {
-      fprintf(stderr,
-             _("'%s' failed: %s\n"),
-             "execlp",
-             STRERROR(errno));
-      return -1;
-    }
-  }
+  if (OK != initUtil(argc,
+                    argv, 
+                    &parseCommandLine))
+    return -1;
+  daemon = startGNUnetDaemon(NO);
+  GNUNET_ASSERT(daemon > 0);
   ok = YES;
-  initUtil(argc, argv, &parseCommandLine);
   startCron();
-  gnunet_util_sleep(5 * cronSECONDS); /* give gnunetd time to start */
+  GNUNET_ASSERT(OK == waitForGNUnetDaemonRunning(30 * cronSECONDS));
+  gnunet_util_sleep(5 * cronSECONDS); /* give apps time to start */
   sock = getClientSocket();
   CHECK(sock != NULL);
 
@@ -303,21 +296,10 @@
   if (sock != NULL)
     releaseClientSocket(sock);
   stopCron();
+  GNUNET_ASSERT(OK == stopGNUnetDaemon());
+  GNUNET_ASSERT(OK == waitForGNUnetDaemonTermination(daemon));
   doneUtil();
-  if (daemon != -1) {
-    if (0 != kill(daemon, SIGTERM))
-      DIE_STRERROR("kill");
-    if (daemon != waitpid(daemon, &status, 0))
-      DIE_STRERROR("waitpid");
-
-    if ( (WEXITSTATUS(status) == 0) &&
-        (ok == YES) )
-      return 0;
-    else
-      return 1;
-  } else {
-    return 0;
-  }
+  return (ok == YES) ? 0 : 1;
 }
 
 /* end of ecrstest.c */

Modified: GNUnet/src/applications/fs/ecrs/namespacetest.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/namespacetest.c     2005-06-26 11:33:02 UTC 
(rev 1048)
+++ GNUnet/src/applications/fs/ecrs/namespacetest.c     2005-06-26 11:34:04 UTC 
(rev 1049)
@@ -96,6 +96,9 @@
   FREENONNULL(setConfigurationString("GNUNET",
                                     "LOGLEVEL",
                                     "WARNING"));
+  FREENONNULL(setConfigurationString("GNUNET",
+                                    "GNUNETD-CONFIG",
+                                    "check.conf"));
   return OK;
 }
 
@@ -104,42 +107,20 @@
   int status;
   int failureCount = 0; 
 
-  daemon = fork();
-  if (daemon == 0) {
-    if (0 != execlp("gnunetd", /* what binary to execute, must be in $PATH! */
-                   "gnunetd", /* arg0, path to gnunet binary */
-                   "-d",  /* do not daemonize so we can easily kill you */
-                   /* "-L", "NOTHING", */
-                   "-c",
-                   "check.conf", /* configuration file */
-                   NULL)) {
-      fprintf(stderr,
-             _("'%s' failed: %s\n"),
-             "execlp",
-             STRERROR(errno));
-      return -1;
-    }
-  }
-  initUtil(argc, argv, &parseCommandLine);
+  if (OK != initUtil(argc,
+                    argv, 
+                    &parseOptions))
+    return -1;
+  daemon = startGNUnetDaemon(NO);
+  GNUNET_ASSERT(daemon > 0);
   gnunet_util_sleep(5 * cronSECONDS);
   
   failureCount += testNamespace();
 
-
+  GNUNET_ASSERT(OK == stopGNUnetDaemon());
+  GNUNET_ASSERT(OK == waitForGNUnetDaemonTermination(daemon));
   doneUtil();
-  if (daemon != -1) {
-    if (0 != kill(daemon, SIGTERM))
-      DIE_STRERROR("kill");
-    if (daemon != waitpid(daemon, &status, 0))
-      DIE_STRERROR("waitpid");
-
-    if (WEXITSTATUS(status) != 0)
-      failureCount++;
-  }
-  if (failureCount == 0)
-    return 0;
-  else
-    return 1;
+  return (failureCount == 0) ? 0 : 1;
 }
 
 /* end of namespacetest.c */

Modified: GNUnet/src/applications/fs/ecrs/searchtest.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/searchtest.c        2005-06-26 11:33:02 UTC 
(rev 1048)
+++ GNUnet/src/applications/fs/ecrs/searchtest.c        2005-06-26 11:34:04 UTC 
(rev 1049)
@@ -43,6 +43,9 @@
   FREENONNULL(setConfigurationString("GNUNET",
                                     "LOGLEVEL",
                                     "NOTHING"));
+  FREENONNULL(setConfigurationString("GNUNET",
+                                    "GNUNETD-CONFIG",
+                                    "check.conf"));
   return OK;
 }
 
@@ -98,25 +101,16 @@
   struct ECRS_URI * key;
   const char * keywords[6];
 
-  daemon = fork();
-  if (daemon == 0) {
-    if (0 != execlp("gnunetd", /* what binary to execute, must be in $PATH! */
-                   "gnunetd", /* arg0, path to gnunet binary */
-                   "-d",  /* do not daemonize so we can easily kill you */
-                   "-c",
-                   "check.conf", /* configuration file */
-                   NULL)) {
-      fprintf(stderr,
-             _("'%s' failed: %s\n"),
-             "execlp",
-             STRERROR(errno));
-      return -1;
-    }
-  }
+  if (OK != initUtil(argc,
+                    argv, 
+                    &parseOptions))
+    return -1;
+  daemon = startGNUnetDaemon(NO);
+  GNUNET_ASSERT(daemon > 0);
   ok = YES;
-  initUtil(argc, argv, &parseCommandLine);
   startCron();
-  gnunet_util_sleep(5 * cronSECONDS); /* give gnunetd time to start */
+  GNUNET_ASSERT(OK == waitForGNUnetDaemonRunning(30 * cronSECONDS));
+  gnunet_util_sleep(5 * cronSECONDS); /* give apps time to start */
   sock = getClientSocket();
   CHECK(sock != NULL);
 
@@ -178,24 +172,10 @@
   if (sock != NULL)
     releaseClientSocket(sock);
   stopCron();
+  GNUNET_ASSERT(OK == stopGNUnetDaemon());
+  GNUNET_ASSERT(OK == waitForGNUnetDaemonTermination(daemon));
   doneUtil();
-  if (daemon != -1) {
-    if (0 != kill(daemon, SIGTERM))
-      DIE_STRERROR("kill");
-    if (daemon != waitpid(daemon, &status, 0))
-      DIE_STRERROR("waitpid");
-
-    if ( (WEXITSTATUS(status) == 0) &&
-        (ok == YES) )
-      return 0;
-    else
-      return 1;
-  } else {
-    if (ok == YES)
-      return 0;
-    else
-      return 1;
-  }
+  return (ok == YES) ? 0 : 1;
 }
 
 /* end of searchtest.c */

Modified: GNUnet/src/applications/fs/fsui/check.conf
===================================================================
--- GNUnet/src/applications/fs/fsui/check.conf  2005-06-26 11:33:02 UTC (rev 
1048)
+++ GNUnet/src/applications/fs/fsui/check.conf  2005-06-26 11:34:04 UTC (rev 
1049)
@@ -10,7 +10,7 @@
 KEEPLOG         = 0
 PIDFILE         = $GNUNETD_HOME/gnunetd.pid
 HOSTS          = $GNUNETD_HOME/data/hosts/
-APPLICATIONS = "fs getoption"
+APPLICATIONS = "fs getoption traffic"
 # TRANSPORTS = -- no transports!
 
 [MODULES]

Modified: GNUnet/src/applications/fs/fsui/downloadtest.c
===================================================================
--- GNUnet/src/applications/fs/fsui/downloadtest.c      2005-06-26 11:33:02 UTC 
(rev 1048)
+++ GNUnet/src/applications/fs/fsui/downloadtest.c      2005-06-26 11:34:04 UTC 
(rev 1049)
@@ -46,6 +46,9 @@
   FREENONNULL(setConfigurationString("GNUNET",
                                     "LOGLEVEL",
                                     "WARNING"));
+  FREENONNULL(setConfigurationString("GNUNET",
+                                    "GNUNETD-CONFIG",
+                                    "check.conf"));
   return OK;
 }
 
@@ -127,26 +130,16 @@
   struct ECRS_MetaData * meta;
   struct ECRS_URI * kuri;
 
-  daemon = fork();
-  if (daemon == 0) {
-    if (0 != execlp("gnunetd", /* what binary to execute, must be in $PATH! */
-                   "gnunetd", /* arg0, path to gnunet binary */
-                   "-d",  /* do not daemonize so we can easily kill you */
-                   "-c",
-                   "check.conf", /* configuration file */
-                   NULL)) {
-      fprintf(stderr,
-             _("'%s' failed: %s\n"),
-             "execlp",
-             STRERROR(errno));
-      return -1;
-    }
-  }
-  ok = YES;
-  if (OK != initUtil(argc, argv, &parseCommandLine))
+  if (OK != initUtil(argc,
+                    argv, 
+                    &parseCommandLine))
     return -1;
+  daemon = startGNUnetDaemon(NO);
+  GNUNET_ASSERT(daemon > 0);
+  ok = YES;
   startCron();
-  gnunet_util_sleep(30 * cronSECONDS); /* give gnunetd time to start */
+  GNUNET_ASSERT(OK == waitForGNUnetDaemonRunning(30 * cronSECONDS));
+  gnunet_util_sleep(5 * cronSECONDS); /* give apps time to start */
 
   /* ACTUAL TEST CODE */
   ctx = FSUI_start("fsuidownloadtest",
@@ -213,21 +206,10 @@
   FREE(fn);
 
   stopCron();
+  GNUNET_ASSERT(OK == stopGNUnetDaemon());
+  GNUNET_ASSERT(OK == waitForGNUnetDaemonTermination(daemon));
   doneUtil();
-  if (daemon != -1) {
-    if (0 != kill(daemon, SIGTERM))
-      DIE_STRERROR("kill");
-    if (daemon != waitpid(daemon, &status, 0))
-      DIE_STRERROR("waitpid");
-
-    if ( (WEXITSTATUS(status) == 0) &&
-        (ok == YES) )
-      return 0;
-    else
-      return 1;
-  } else {
-    return 0;
-  }
+  return (ok == YES) ? 0 : 1;
 }
 
 /* end of downloadtest.c */

Modified: GNUnet/src/applications/fs/fsui/fsuitest.c
===================================================================
--- GNUnet/src/applications/fs/fsui/fsuitest.c  2005-06-26 11:33:02 UTC (rev 
1048)
+++ GNUnet/src/applications/fs/fsui/fsuitest.c  2005-06-26 11:34:04 UTC (rev 
1049)
@@ -42,6 +42,9 @@
   FREENONNULL(setConfigurationString("GNUNET",
                                     "LOGLEVEL",
                                     "WARNING"));
+  FREENONNULL(setConfigurationString("GNUNET",
+                                    "GNUNETD-CONFIG",
+                                    "check.conf"));
   return OK;
 }
 
@@ -117,26 +120,16 @@
   struct ECRS_MetaData * meta;
   struct ECRS_URI * kuri;
 
-  daemon = fork();
-  if (daemon == 0) {
-    if (0 != execlp("gnunetd", /* what binary to execute, must be in $PATH! */
-                   "gnunetd", /* arg0, path to gnunet binary */
-                   "-d",  /* do not daemonize so we can easily kill you */
-                   "-c",
-                   "check.conf", /* configuration file */
-                   NULL)) {
-      fprintf(stderr,
-             _("'%s' failed: %s\n"),
-             "execlp",
-             STRERROR(errno));
-      return -1;
-    }
-  }
+  if (OK != initUtil(argc, 
+                    argv, 
+                    &parseCommandLine))
+    return -1;  
+  daemon = startGNUnetDaemon(NO);
+  GNUNET_ASSERT(daemon > 0);
   ok = YES;
-  if (OK != initUtil(argc, argv, &parseCommandLine))
-    return -1;
   startCron();
-  gnunet_util_sleep(30 * cronSECONDS); /* give gnunetd time to start */
+  GNUNET_ASSERT(OK == waitForGNUnetDaemonRunning(30 * cronSECONDS));
+  gnunet_util_sleep(5 * cronSECONDS); /* give apps time to start */
 
   /* ACTUAL TEST CODE */
   ctx = FSUI_start("fsuitest",
@@ -203,21 +196,10 @@
   FREE(filename);
 
   stopCron();
+  GNUNET_ASSERT(OK == stopGNUnetDaemon());
+  GNUNET_ASSERT(OK == waitForGNUnetDaemonTermination(daemon));
   doneUtil();
-  if (daemon != -1) {
-    if (0 != kill(daemon, SIGTERM))
-      DIE_STRERROR("kill");
-    if (daemon != waitpid(daemon, &status, 0))
-      DIE_STRERROR("waitpid");
-
-    if ( (WEXITSTATUS(status) == 0) &&
-        (ok == YES) )
-      return 0;
-    else
-      return 1;
-  } else {
-    return 0;
-  }
+  return (ok == YES) ? 0 : 1;
 }
 
 /* end of fsuitest.c */

Modified: GNUnet/src/applications/fs/fsui/fsuitest2.c
===================================================================
--- GNUnet/src/applications/fs/fsui/fsuitest2.c 2005-06-26 11:33:02 UTC (rev 
1048)
+++ GNUnet/src/applications/fs/fsui/fsuitest2.c 2005-06-26 11:34:04 UTC (rev 
1049)
@@ -42,6 +42,9 @@
   FREENONNULL(setConfigurationString("GNUNET",
                                     "LOGLEVEL",
                                     "WARNING"));
+  FREENONNULL(setConfigurationString("GNUNET",
+                                    "GNUNETD-CONFIG",
+                                    "check.conf"));
   return OK;
 }
 
@@ -57,25 +60,16 @@
   int status;
   int ok;
 
-  daemon = fork();
-  if (daemon == 0) {
-    if (0 != execlp("gnunetd", /* what binary to execute, must be in $PATH! */
-                   "gnunetd", /* arg0, path to gnunet binary */
-                   "-d",  /* do not daemonize so we can easily kill you */
-                   "-c",
-                   "check.conf", /* configuration file */
-                   NULL)) {
-      fprintf(stderr,
-             _("'%s' failed: %s\n"),
-             "execlp",
-             STRERROR(errno));
-      return -1;
-    }
-  }
+  if (OK != initUtil(argc,
+                    argv, 
+                    &parseCommandLine))
+    return -1;
+  daemon = startGNUnetDaemon(NO);
+  GNUNET_ASSERT(daemon > 0);
   ok = YES;
-  initUtil(argc, argv, &parseCommandLine);
   startCron();
-  gnunet_util_sleep(30 * cronSECONDS); /* give gnunetd time to start */
+  GNUNET_ASSERT(OK == waitForGNUnetDaemonRunning(30 * cronSECONDS));
+  gnunet_util_sleep(5 * cronSECONDS); /* give apps time to start */
 
   /* ACTUAL TEST CODE */
   ctx = FSUI_start("fsuitest2",
@@ -95,21 +89,10 @@
     FSUI_stop(ctx);
 
   stopCron();
+  GNUNET_ASSERT(OK == stopGNUnetDaemon());
+  GNUNET_ASSERT(OK == waitForGNUnetDaemonTermination(daemon));
   doneUtil();
-  if (daemon != -1) {
-    if (0 != kill(daemon, SIGTERM))
-      DIE_STRERROR("kill");
-    if (daemon != waitpid(daemon, &status, 0))
-      DIE_STRERROR("waitpid");
-
-    if ( (WEXITSTATUS(status) == 0) &&
-        (ok == YES) )
-      return 0;
-    else
-      return 1;
-  } else {
-    return 0;
-  }
+  return (ok == YES) ? 0 : 1;
 }
 
 /* end of fsuitest2.c */

Modified: GNUnet/src/applications/fs/fsui/searchtest.c
===================================================================
--- GNUnet/src/applications/fs/fsui/searchtest.c        2005-06-26 11:33:02 UTC 
(rev 1048)
+++ GNUnet/src/applications/fs/fsui/searchtest.c        2005-06-26 11:34:04 UTC 
(rev 1049)
@@ -42,6 +42,9 @@
   FREENONNULL(setConfigurationString("GNUNET",
                                     "LOGLEVEL",
                                     "WARNING"));
+  FREENONNULL(setConfigurationString("GNUNET",
+                                    "GNUNETD-CONFIG",
+                                    "check.conf"));
   return OK;
 }
 
@@ -117,25 +120,16 @@
   struct ECRS_MetaData * meta;
   struct ECRS_URI * kuri;
 
-  daemon = fork();
-  if (daemon == 0) {
-    if (0 != execlp("gnunetd", /* what binary to execute, must be in $PATH! */
-                   "gnunetd", /* arg0, path to gnunet binary */
-                   "-d",  /* do not daemonize so we can easily kill you */
-                   "-c",
-                   "check.conf", /* configuration file */
-                   NULL)) {
-      fprintf(stderr,
-             _("'%s' failed: %s\n"),
-             "execlp",
-             STRERROR(errno));
-      return -1;
-    }
-  }
+  if (OK != initUtil(argc,
+                    argv, 
+                    &parseCommandLine))
+    return -1;
+  daemon = startGNUnetDaemon(NO);
+  GNUNET_ASSERT(daemon > 0);
   ok = YES;
-  initUtil(argc, argv, &parseCommandLine);
   startCron();
-  gnunet_util_sleep(30 * cronSECONDS); /* give gnunetd plenty of time to start 
*/
+  GNUNET_ASSERT(OK == waitForGNUnetDaemonRunning(30 * cronSECONDS));
+  gnunet_util_sleep(5 * cronSECONDS); /* give apps time to start */
 
   /* ACTUAL TEST CODE */
 
@@ -212,21 +206,10 @@
   FREE(fn);
 
   stopCron();
+  GNUNET_ASSERT(OK == stopGNUnetDaemon());
+  GNUNET_ASSERT(OK == waitForGNUnetDaemonTermination(daemon));
   doneUtil();
-  if (daemon != -1) {
-    if (0 != kill(daemon, SIGTERM))
-      DIE_STRERROR("kill");
-    if (daemon != waitpid(daemon, &status, 0))
-      DIE_STRERROR("waitpid");
-
-    if ( (WEXITSTATUS(status) == 0) &&
-        (ok == YES) )
-      return 0;
-    else
-      return 1;
-  } else {
-    return 0;
-  }
+  return (ok == YES) ? 0 : 1;
 }
 
 /* end of searchtest.c */

Modified: GNUnet/src/applications/fs/lib/check.conf
===================================================================
--- GNUnet/src/applications/fs/lib/check.conf   2005-06-26 11:33:02 UTC (rev 
1048)
+++ GNUnet/src/applications/fs/lib/check.conf   2005-06-26 11:34:04 UTC (rev 
1049)
@@ -10,7 +10,7 @@
 KEEPLOG         = 0
 PIDFILE         = $GNUNETD_HOME/gnunetd.pid
 HOSTS          = $GNUNETD_HOME/data/hosts/
-APPLICATIONS = "fs"
+APPLICATIONS = "fs traffic"
 # TRANSPORTS = -- no transports!
 
 [MODULES]

Modified: GNUnet/src/applications/fs/lib/fslibtest.c
===================================================================
--- GNUnet/src/applications/fs/lib/fslibtest.c  2005-06-26 11:33:02 UTC (rev 
1048)
+++ GNUnet/src/applications/fs/lib/fslibtest.c  2005-06-26 11:34:04 UTC (rev 
1049)
@@ -43,6 +43,9 @@
   FREENONNULL(setConfigurationString("GNUNET",
                                     "LOGLEVEL",
                                     "WARNING"));
+  FREENONNULL(setConfigurationString("GNUNET",
+                                    "GNUNETD-CONFIG",
+                                    "check.conf"));
   return OK;
 }
 
@@ -224,29 +227,17 @@
   int fd;
 
   cronTime(&now);
-  daemon = fork();
-  if (daemon == 0) {
-    /* FIXME: would be nice to be able to tell
-       gnunetd to use the check/debug DB and not
-       any real DB! */
-    if (0 != execlp("gnunetd", /* what binary to execute, must be in $PATH! */
-                   "gnunetd", /* arg0, path to gnunet binary */
-                   "-d",  /* do not daemonize so we can easily kill you */
-                   "-c",
-                   "check.conf", /* configuration file */
-                   NULL)) {
-      fprintf(stderr,
-             _("'%s' failed: %s\n"),
-             "execlp",
-             STRERROR(errno));
-      return -1;
-    }
-  }
+  if (OK != initUtil(argc,
+                    argv, 
+                    &parseCommandLine))
+    return -1;
+  daemon = startGNUnetDaemon(NO);
+  GNUNET_ASSERT(daemon > 0);
   ok = YES;
-  initUtil(argc, argv, &parseCommandLine);
   startCron();
   MUTEX_CREATE(&lock);
-  gnunet_util_sleep(5 * cronSECONDS); /* give gnunetd time to start */
+  GNUNET_ASSERT(OK == waitForGNUnetDaemonRunning(30 * cronSECONDS));
+  gnunet_util_sleep(5 * cronSECONDS); /* give apps time to start */
   sock = getClientSocket();
   CHECK(sock != NULL);
   ctx = FS_SEARCH_makeContext(&lock);
@@ -367,20 +358,10 @@
     releaseClientSocket(sock);
   MUTEX_DESTROY(&lock);
   stopCron();
+  GNUNET_ASSERT(OK == stopGNUnetDaemon());
+  GNUNET_ASSERT(OK == waitForGNUnetDaemonTermination(daemon));
   doneUtil();
-  if (daemon != -1) {
-    if (0 != kill(daemon, SIGTERM))
-      DIE_STRERROR("kill");
-    if (daemon != waitpid(daemon, &status, 0))
-      DIE_STRERROR("waitpid");
-
-    if ( (WEXITSTATUS(status) == 0) &&
-        (ok == YES) )
-      return 0;
-    else
-      return 1;
-  } else
-    return 0;
+  return (ok == YES) ? 0 : 1;
 }
 
 /* end of fslibtest.c */

Modified: GNUnet/src/applications/gap/gaptest.c
===================================================================
--- GNUnet/src/applications/gap/gaptest.c       2005-06-26 11:33:02 UTC (rev 
1048)
+++ GNUnet/src/applications/gap/gaptest.c       2005-06-26 11:34:04 UTC (rev 
1049)
@@ -263,37 +263,20 @@
                         "OPDA8F1VIKESLSNBO",
                         &peer2.hashPubKey));
   /* set to 0 if you want to start gnunetd's by hand for debugging */
+
+  if (OK != initUtil(argc,
+                    argv, 
+                    &parseOptions))
+    return -1;
 #if 1
-  daemon1 = fork();
-  if (daemon1 == 0) {
-    if (0 != execlp("gnunetd", /* what binary to execute, must be in $PATH! */
-                   "gnunetd", /* arg0, path to gnunet binary */
-                   "-d",  /* do not daemonize so we can easily kill you */
-                   "-c",
-                   "peer1.conf", /* configuration file */
-                   NULL)) {
-      fprintf(stderr,
-             _("'%s' failed: %s\n"),
-             "execlp",
-             STRERROR(errno));
-      return -1;
-    }
-  }
-  daemon2 = fork();
-  if (daemon2 == 0) {
-    if (0 != execlp("gnunetd", /* what binary to execute, must be in $PATH! */
-                   "gnunetd", /* arg0, path to gnunet binary */
-                   "-d",  /* do not daemonize so we can easily kill you */
-                   "-c",
-                   "peer2.conf", /* configuration file */
-                   NULL)) {
-      fprintf(stderr,
-             _("'%s' failed: %s\n"),
-             "execlp",
-             STRERROR(errno));
-      return -1;
-    }
-  }
+  FREENONNULL(setConfigurationString("GNUNET",
+                                    "GNUNETD-CONFIG",
+                                    "peer1.conf"));
+  daemon1 = startGNUnetDaemon(NO);
+  FREENONNULL(setConfigurationString("GNUNET",
+                                    "GNUNETD-CONFIG",
+                                    "peer2.conf"));
+  daemon2 = startGNUnetDaemon(NO);
   /* in case existing HELOs have expired */
   sleep(5);
   system("cp peer1/data/hosts/* peer2/data/hosts/");
@@ -301,47 +284,23 @@
   if (daemon1 != -1) {
     if (0 != kill(daemon1, SIGTERM))
       DIE_STRERROR("kill");
-    if (daemon1 != waitpid(daemon1, &status, 0))
-      DIE_STRERROR("waitpid");
+    GNUNET_ASSERT(OK == waitForGNUnetDaemonTermination(daemon1));
   }
   if (daemon2 != -1) {
     if (0 != kill(daemon2, SIGTERM))
       DIE_STRERROR("kill");
-    if (daemon2 != waitpid(daemon2, &status, 0))
-      DIE_STRERROR("waitpid");
+    GNUNET_ASSERT(OK == waitForGNUnetDaemonTermination(daemon2));
   }
 
   /* re-start, this time we're sure up-to-date HELOs are available */
-  daemon1 = fork();
-  if (daemon1 == 0) {
-    if (0 != execlp("gnunetd", /* what binary to execute, must be in $PATH! */
-                   "gnunetd", /* arg0, path to gnunet binary */
-                   "-d",  /* do not daemonize so we can easily kill you */
-                   "-c",
-                   "peer1.conf", /* configuration file */
-                   NULL)) {
-      fprintf(stderr,
-             _("'%s' failed: %s\n"),
-             "execlp",
-             STRERROR(errno));
-      return -1;
-    }
-  }
-  daemon2 = fork();
-  if (daemon2 == 0) {
-    if (0 != execlp("gnunetd", /* what binary to execute, must be in $PATH! */
-                   "gnunetd", /* arg0, path to gnunet binary */
-                   "-d",  /* do not daemonize so we can easily kill you */
-                   "-c",
-                   "peer2.conf", /* configuration file */
-                   NULL)) {
-      fprintf(stderr,
-             _("'%s' failed: %s\n"),
-             "execlp",
-             STRERROR(errno));
-      return -1;
-    }
-  }
+  FREENONNULL(setConfigurationString("GNUNET",
+                                    "GNUNETD-CONFIG",
+                                    "peer1.conf"));
+  daemon1 = startGNUnetDaemon(NO);
+  FREENONNULL(setConfigurationString("GNUNET",
+                                    "GNUNETD-CONFIG",
+                                    "peer2.conf"));
+  daemon2 = startGNUnetDaemon(NO);
   sleep(5);
 
   ret = 0;
@@ -351,7 +310,6 @@
   daemon1 = -1;
   daemon2 = -1;
 #endif
-  initUtil(argc, argv, &parseOptions);
   do {
     sock = getClientSocket();
     if (sock == NULL) {
@@ -390,21 +348,18 @@
   CHECK(OK == unindexFile(12345));
 
  FAILURE:
-  doneUtil();
 
-  /* also shutdown daemons again */
   if (daemon1 != -1) {
     if (0 != kill(daemon1, SIGTERM))
       DIE_STRERROR("kill");
-    if (daemon1 != waitpid(daemon1, &status, 0))
-      DIE_STRERROR("waitpid");
+    GNUNET_ASSERT(OK == waitForGNUnetDaemonTermination(daemon1));
   }
   if (daemon2 != -1) {
     if (0 != kill(daemon2, SIGTERM))
       DIE_STRERROR("kill");
-    if (daemon2 != waitpid(daemon2, &status, 0))
-      DIE_STRERROR("waitpid");
-  }
+    GNUNET_ASSERT(OK == waitForGNUnetDaemonTermination(daemon2));
+  } 
+  doneUtil();
   return ret;
 }
 

Modified: GNUnet/src/applications/session/sessiontest.c
===================================================================
--- GNUnet/src/applications/session/sessiontest.c       2005-06-26 11:33:02 UTC 
(rev 1048)
+++ GNUnet/src/applications/session/sessiontest.c       2005-06-26 11:34:04 UTC 
(rev 1049)
@@ -72,91 +72,48 @@
                         "5B2Q58IEU1VF5FTR838449CSHVBOAHLDVQAOA33O77F"
                         "OPDA8F1VIKESLSNBO",
                         &peer2.hashPubKey));
-  daemon1 = fork();
-  if (daemon1 == 0) {
-    if (0 != execlp("gnunetd", /* what binary to execute, must be in $PATH! */
-                   "gnunetd", /* arg0, path to gnunet binary */
-                   "-d",  /* do not daemonize so we can easily kill you */
-                   "-c",
-                   "peer1.conf", /* configuration file */
-                   NULL)) {
-      fprintf(stderr,
-             _("'%s' failed: %s\n"),
-             "execlp",
-             STRERROR(errno));
-      return -1;
-    }
-  }
-  daemon2 = fork();
-  if (daemon2 == 0) {
-    if (0 != execlp("gnunetd", /* what binary to execute, must be in $PATH! */
-                   "gnunetd", /* arg0, path to gnunet binary */
-                   "-d",  /* do not daemonize so we can easily kill you */
-                   "-c",
-                   "peer2.conf", /* configuration file */
-                   NULL)) {
-      fprintf(stderr,
-             _("'%s' failed: %s\n"),
-             "execlp",
-             STRERROR(errno));
-      return -1;
-    }
-  }
+  if (OK != initUtil(argc,
+                    argv, 
+                    &parseOptions))
+    return -1;
+  FREENONNULL(setConfigurationString("GNUNET",
+                                    "GNUNETD-CONFIG",
+                                    "peer1.conf"));
+  daemon1 = startGNUnetDaemon(NO);
+  FREENONNULL(setConfigurationString("GNUNET",
+                                    "GNUNETD-CONFIG",
+                                    "peer2.conf"));
+  daemon2 = startGNUnetDaemon(NO);
   /* in case existing HELOs have expired */
-  sleep(5);
+  gnunet_util_sleep(30 * cronSECONDS);
   system("cp peer1/data/hosts/* peer2/data/hosts/");
-  system("cp peer2/data/hosts/* peer1/data/hosts/");
+  system("cp peer2/data/hosts/* peer1/data/hosts/");  
   if (daemon1 != -1) {
     if (0 != kill(daemon1, SIGTERM))
       DIE_STRERROR("kill");
-    if (daemon1 != waitpid(daemon1, &status, 0))
-      DIE_STRERROR("waitpid");
+    GNUNET_ASSERT(OK == waitForGNUnetDaemonTermination(daemon1));
   }
   if (daemon2 != -1) {
     if (0 != kill(daemon2, SIGTERM))
       DIE_STRERROR("kill");
-    if (daemon2 != waitpid(daemon2, &status, 0))
-      DIE_STRERROR("waitpid");
+    GNUNET_ASSERT(OK == waitForGNUnetDaemonTermination(daemon2));
   }
 
   /* re-start, this time we're sure up-to-date HELOs are available */
-  daemon1 = fork();
-  if (daemon1 == 0) {
-    if (0 != execlp("gnunetd", /* what binary to execute, must be in $PATH! */
-                   "gnunetd", /* arg0, path to gnunet binary */
-                   "-d",  /* do not daemonize so we can easily kill you */
-                   "-c",
-                   "peer1.conf", /* configuration file */
-                   NULL)) {
-      fprintf(stderr,
-             _("'%s' failed: %s\n"),
-             "execlp",
-             STRERROR(errno));
-      return -1;
-    }
-  }
-  daemon2 = fork();
-  if (daemon2 == 0) {
-    if (0 != execlp("gnunetd", /* what binary to execute, must be in $PATH! */
-                   "gnunetd", /* arg0, path to gnunet binary */
-                   "-d",  /* do not daemonize so we can easily kill you */
-                   "-c",
-                   "peer2.conf", /* configuration file */
-                   NULL)) {
-      fprintf(stderr,
-             _("'%s' failed: %s\n"),
-             "execlp",
-             STRERROR(errno));
-      return -1;
-    }
-  }
-  sleep(5);
+  FREENONNULL(setConfigurationString("GNUNET",
+                                    "GNUNETD-CONFIG",
+                                    "peer1.conf"));
+  daemon1 = startGNUnetDaemon(NO);
+  FREENONNULL(setConfigurationString("GNUNET",
+                                    "GNUNETD-CONFIG",
+                                    "peer2.conf"));
+  daemon2 = startGNUnetDaemon(NO);
+  gnunet_util_sleep(5 * cronSECONDS);
 
 
   ret = 0;
   left = 5;
   /* wait for connection or abort with error */
-  initUtil(argc, argv, &parseOptions);
   do {
     sock = getClientSocket();
     if (sock == NULL) {
@@ -185,21 +142,17 @@
     }
   }
   releaseClientSocket(sock);
-  doneUtil();
-
-  /* also shutdown daemons again */
   if (daemon1 != -1) {
     if (0 != kill(daemon1, SIGTERM))
       DIE_STRERROR("kill");
-    if (daemon1 != waitpid(daemon1, &status, 0))
-      DIE_STRERROR("waitpid");
+    GNUNET_ASSERT(OK == waitForGNUnetDaemonTermination(daemon1));
   }
   if (daemon2 != -1) {
     if (0 != kill(daemon2, SIGTERM))
       DIE_STRERROR("kill");
-    if (daemon2 != waitpid(daemon2, &status, 0))
-      DIE_STRERROR("waitpid");
-  }
+    GNUNET_ASSERT(OK == waitForGNUnetDaemonTermination(daemon2));
+  } 
+  doneUtil();
   return ret;
 }
 

Modified: GNUnet/src/applications/tbench/tbenchtest.c
===================================================================
--- GNUnet/src/applications/tbench/tbenchtest.c 2005-06-26 11:33:02 UTC (rev 
1048)
+++ GNUnet/src/applications/tbench/tbenchtest.c 2005-06-26 11:34:04 UTC (rev 
1049)
@@ -30,11 +30,6 @@
 #include "tbench.h"
 #include <sys/wait.h>
 
-/**
- * Set this to NO when debugging gnunetd processes separately.
- */
-#define DO_FORK YES
-
 static int parseOptions(int argc,
                        char ** argv) {
   FREENONNULL(setConfigurationString("GNUNETD",
@@ -145,11 +140,9 @@
  * @return 0: ok, -1: error
  */
 int main(int argc, char ** argv) {
-#if DO_FORK
   pid_t daemon1;
   pid_t daemon2;
   int status;
-#endif
   int ret;
   int left;
   GNUNET_TCP_SOCKET * sock;
@@ -160,37 +153,18 @@
                         "5B2Q58IEU1VF5FTR838449CSHVBOAHLDVQAOA33O77F"
                         "OPDA8F1VIKESLSNBO",
                         &peer2.hashPubKey));
-#if DO_FORK
-  daemon1 = fork();
-  if (daemon1 == 0) {
-    if (0 != execlp("gnunetd", /* what binary to execute, must be in $PATH! */
-                   "gnunetd", /* arg0, path to gnunet binary */
-                   "-d",  /* do not daemonize so we can easily kill you */
-                   "-c",
-                   "peer1.conf", /* configuration file */
-                   NULL)) {
-     fprintf(stderr,
-             _("'%s' failed: %s\n"),
-             "execlp",
-             STRERROR(errno));
-      return -1;
-    }
-  }
-  daemon2 = fork();
-  if (daemon2 == 0) {
-    if (0 != execlp("gnunetd", /* what binary to execute, must be in $PATH! */
-                   "gnunetd", /* arg0, path to gnunet binary */
-                   "-d",  /* do not daemonize so we can easily kill you */
-                   "-c",
-                   "peer2.conf", /* configuration file */
-                   NULL)) {
-      fprintf(stderr,
-             _("'%s' failed: %s\n"),
-             "execlp",
-             STRERROR(errno));
-      return -1;
-    }
-  }
+  if (OK != initUtil(argc,
+                    argv, 
+                    &parseOptions))
+    return -1;
+  FREENONNULL(setConfigurationString("GNUNET",
+                                    "GNUNETD-CONFIG",
+                                    "peer1.conf"));
+  daemon1 = startGNUnetDaemon(NO);
+  FREENONNULL(setConfigurationString("GNUNET",
+                                    "GNUNETD-CONFIG",
+                                    "peer2.conf"));
+  daemon2 = startGNUnetDaemon(NO);
   /* in case existing HELOs have expired */
   sleep(5);
   system("cp peer1/data/hosts/* peer2/data/hosts/");
@@ -198,54 +172,29 @@
   if (daemon1 != -1) {
     if (0 != kill(daemon1, SIGTERM))
       DIE_STRERROR("kill");
-    if (daemon1 != waitpid(daemon1, &status, 0))
-      DIE_STRERROR("waitpid");
+    GNUNET_ASSERT(OK == waitForGNUnetDaemonTermination(daemon1));
   }
   if (daemon2 != -1) {
     if (0 != kill(daemon2, SIGTERM))
       DIE_STRERROR("kill");
-    if (daemon2 != waitpid(daemon2, &status, 0))
-      DIE_STRERROR("waitpid");
+    GNUNET_ASSERT(OK == waitForGNUnetDaemonTermination(daemon2));
   }
 
   /* re-start, this time we're sure up-to-date HELOs are available */
-  daemon1 = fork();
-  if (daemon1 == 0) {
-    if (0 != execlp("gnunetd", /* what binary to execute, must be in $PATH! */
-                   "gnunetd", /* arg0, path to gnunet binary */
-                   "-d",  /* do not daemonize so we can easily kill you */
-                   "-c",
-                   "peer1.conf", /* configuration file */
-                   NULL)) {
-      fprintf(stderr,
-             _("'%s' failed: %s\n"),
-             "execlp",
-             STRERROR(errno));
-      return -1;
-    }
-  }
-  daemon2 = fork();
-  if (daemon2 == 0) {
-    if (0 != execlp("gnunetd", /* what binary to execute, must be in $PATH! */
-                   "gnunetd", /* arg0, path to gnunet binary */
-                   "-d",  /* do not daemonize so we can easily kill you */
-                   "-c",
-                   "peer2.conf", /* configuration file */
-                   NULL)) {
-      fprintf(stderr,
-             _("'%s' failed: %s\n"),
-             "execlp",
-             STRERROR(errno));
-      return -1;
-    }
-  }
+  FREENONNULL(setConfigurationString("GNUNET",
+                                    "GNUNETD-CONFIG",
+                                    "peer1.conf"));
+  daemon1 = startGNUnetDaemon(NO);
+  FREENONNULL(setConfigurationString("GNUNET",
+                                    "GNUNETD-CONFIG",
+                                    "peer2.conf"));
+  daemon2 = startGNUnetDaemon(NO);
+  gnunet_util_sleep(5 * cronSECONDS);
   sleep(5);
-#endif
 
   ret = 0;
   left = 5;
   /* wait for connection or abort with error */
-  initUtil(argc, argv, &parseOptions);
   do {
     sock = getClientSocket();
     if (sock == NULL) {
@@ -274,22 +223,17 @@
   }
   ret = test(sock, 32768, 10, 10, 500 * cronMILLIS, 1, 10 * cronSECONDS);
   releaseClientSocket(sock);
-  doneUtil();
-
-#if DO_FORK
   if (daemon1 != -1) {
     if (0 != kill(daemon1, SIGTERM))
       DIE_STRERROR("kill");
-    if (daemon1 != waitpid(daemon1, &status, 0))
-      DIE_STRERROR("waitpid");
+    GNUNET_ASSERT(OK == waitForGNUnetDaemonTermination(daemon1));
   }
   if (daemon2 != -1) {
     if (0 != kill(daemon2, SIGTERM))
       DIE_STRERROR("kill");
-    if (daemon2 != waitpid(daemon2, &status, 0))
-      DIE_STRERROR("waitpid");
-  }
-#endif
+    GNUNET_ASSERT(OK == waitForGNUnetDaemonTermination(daemon2));
+  } 
+  doneUtil();
   return ret;
 }
 





reply via email to

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