gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r3293 - in GNUnet/src/util: . config_impl network os


From: grothoff
Subject: [GNUnet-SVN] r3293 - in GNUnet/src/util: . config_impl network os
Date: Wed, 23 Aug 2006 20:51:47 -0700 (PDT)

Author: grothoff
Date: 2006-08-23 20:51:42 -0700 (Wed, 23 Aug 2006)
New Revision: 3293

Added:
   GNUnet/src/util/config_impl/testconfig.conf
Removed:
   GNUnet/src/util/testconfig.conf
Modified:
   GNUnet/src/util/Makefile.am
   GNUnet/src/util/config_impl/Makefile.am
   GNUnet/src/util/config_impl/configtest.c
   GNUnet/src/util/network/Makefile.am
   GNUnet/src/util/os/Makefile.am
   GNUnet/src/util/os/daemontest.c
   GNUnet/src/util/os/semaphoretest.c
   GNUnet/src/util/os/statuscallstest.c
Log:
more test targets

Modified: GNUnet/src/util/Makefile.am
===================================================================
--- GNUnet/src/util/Makefile.am 2006-08-24 03:30:40 UTC (rev 3292)
+++ GNUnet/src/util/Makefile.am 2006-08-24 03:51:42 UTC (rev 3293)
@@ -50,7 +50,6 @@
 
 
 EXTRA_DIST = \
-  testconfig.conf \
   check.conf
 
 libgnunetutil_la_LDFLAGS = \

Modified: GNUnet/src/util/config_impl/Makefile.am
===================================================================
--- GNUnet/src/util/config_impl/Makefile.am     2006-08-24 03:30:40 UTC (rev 
3292)
+++ GNUnet/src/util/config_impl/Makefile.am     2006-08-24 03:51:42 UTC (rev 
3293)
@@ -11,3 +11,19 @@
 libgnunetutil_config_la_LIBADD = \
  $(top_builddir)/src/util/libgnunetutil.la 
 
+
+check_PROGRAMS = \
+ configtest 
+
+TESTS = $(check_PROGRAMS)
+
+configtest_SOURCES = \
+ configtest.c
+configtest_LDADD = \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/util/loggers/libgnunetutil_logging.la \
+ $(top_builddir)/src/util/config_impl/libgnunetutil_config.la 
+
+
+EXTRA_DIST = \
+  testconfig.conf 

Modified: GNUnet/src/util/config_impl/configtest.c
===================================================================
--- GNUnet/src/util/config_impl/configtest.c    2006-08-24 03:30:40 UTC (rev 
3292)
+++ GNUnet/src/util/config_impl/configtest.c    2006-08-24 03:51:42 UTC (rev 
3293)
@@ -1,126 +1,94 @@
+/*
+     This file is part of GNUnet.
+     (C) 2003, 2004, 2005, 2006 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
+     by the Free Software Foundation; either version 2, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
 /**
- * @file test/configtest.c
+ * @file util/config_impl/configtest.c
  * @brief Test that the configuration module works.
  * @author Christian Grothoff
  */
 
 #include "gnunet_util.h"
 #include "platform.h"
+#include "gnunet_util_config_impl.h"
+#include "gnunet_util_error_loggers.h"
 
+static struct GC_Configuration * cfg;
+
 static int testConfig() {
   char * c;
-  if (NO == testConfigurationString("test",
-                                   "a",
-                                   "a")) {
-    printf("[test]-a not mapped to a");
+  unsigned long long l;
+
+  if (0 != GC_get_configuration_value_string(cfg,
+                                            "test",
+                                            "b",
+                                            NULL,
+                                            &c))
     return 1;
-  }
-  c = getConfigurationString("test",
-                            "b");
   if (0 != strcmp("b",
-                 c)) {         
-    printf("[test]-b not mapped to b");
+                 c)) 
     return 1;
-  }
-  FREENONNULL(c);
-  if (5 != getConfigurationInt("test",
-                              "five")) {
-    printf("[test]-five not mapped to 5");
+  FREE(c);
+  if (0 != GC_get_configuration_value_number(cfg,
+                                            "test",
+                                            "five",
+                                            0,
+                                            10,
+                                            9,
+                                            &l)) 
     return 1;
-  }
-  FREENONNULL(setConfigurationString("more",
-                                    "c",
-                                    "d"));
-  if (NO == testConfigurationString("more",
+  if (5 != l)
+    return 1;
+  GC_set_configuration_value_string(cfg,
+                                   NULL,
+                                   "more",
                                    "c",
-                                   "d")) {
-    printf("[more]-c not re-mapped to d");
+                                   "YES");
+  if (NO == GC_get_configuration_value_yesno(cfg,
+                                            "more",
+                                            "c",
+                                            NO)) 
     return 1;
-  }
-  if (42 != getConfigurationInt("more",
-                               "five")) {
-    printf("[more]-five not mapped to 42");
-    return 1;
-  }
-  if (NO == testConfigurationString("last",
-                                   "test",
-                                   "hello/world")) {
-    printf("string substitution did not work: >>%s<<\n",
-          getConfigurationString("last",
-                                 "test"));
-    return 1;
-  }
-  if (NO == testConfigurationString("last",
-                                   "boom",
-                                   "1 2 3 testing")) {
-    printf("string enclosing with \"'s did not work: >>%s<<\n",
-          getConfigurationString("last",
-                                 "boom"));
-    return 1;
-  }
-  if (NO == testConfigurationString("last",
-                                   "trailing",
-                                   "YES")) {
-    printf("confused with trailing spaces: >>%s<<\n",
-          getConfigurationString("last",
-                                 "trailing"));
-  }
   return 0;
 }
 
-/**
- * Perform option parsing from the command line.
- */
-static int parseCommandLine(int argc,
-                           char * argv[]) {
-  char c;
-
-  while (1) {
-    int option_index = 0;
-    static struct GNoption long_options[] = {
-      { "config",  1, 0, 'c' },
-      { 0,0,0,0 }
-    };
-
-    c = GNgetopt_long(argc,
-                     argv,
-                     "c:",
-                     long_options,
-                     &option_index);
-
-    if (c == -1)
-      break;  /* No more flags to process */
-
-    switch(c) {
-    case 'c':
-      FREENONNULL(setConfigurationString("FILES",
-                                        "gnunet.conf",
-                                        GNoptarg));
-      break;
-    } /* end of parsing commandline */
-  }
-  FREENONNULL(setConfigurationString("GNUNETD",
-                                    "LOGLEVEL",
-                                    "NOTHING"));
-  return OK;
-}
-
-int main(int argc, char * argv[]) {
+int main(int argc, 
+        char * argv[]) {
+  struct GE_Context * ectx;
   int failureCount = 0;
-  char * args[] = {
-    "main",
-    "-c",
-    "testconfig.conf",
-  };
 
-  initUtil(3, args, &parseCommandLine);
+  ectx = GE_create_context_stderr(NO, 
+                                 GE_WARNING | GE_ERROR | GE_FATAL |
+                                 GE_USER | GE_ADMIN | GE_DEVELOPER |
+                                 GE_IMMEDIATE | GE_BULK);
+  GE_setDefaultContext(ectx);
+  cfg = GC_create_C_impl();
+  if (0 != GC_parse_configuration(cfg,
+                                 "testconfig.conf")) {
+    fprintf(stderr,
+           "Failed to parse configuration file\n");
+    return 1;
+  }
+  GE_ASSERT(ectx, cfg != NULL);
+  os_init(ectx);
   failureCount += testConfig();
-  doneUtil();
 
-  if (failureCount == 0)
-    return 0;
-  else {
-    printf("\n\n%d TESTS FAILED!\n\n",failureCount);
-    return -1;
-  }
+  if (failureCount != 0)
+    return 1;
+  return 0;
 }

Copied: GNUnet/src/util/config_impl/testconfig.conf (from rev 3289, 
GNUnet/src/util/testconfig.conf)

Modified: GNUnet/src/util/network/Makefile.am
===================================================================
--- GNUnet/src/util/network/Makefile.am 2006-08-24 03:30:40 UTC (rev 3292)
+++ GNUnet/src/util/network/Makefile.am 2006-08-24 03:51:42 UTC (rev 3293)
@@ -11,15 +11,6 @@
  ipcheck.c \
  select.c 
 
-check_PROGRAMS = \
- tcpiotest 
 
-TESTS = $(check_PROGRAMS)
 
-tcpiotest_SOURCES = \
- tcpiotest.c
-tcpiotest_LDADD = \
- $(top_builddir)/src/util/libgnunetutil.la  
 
-
-

Modified: GNUnet/src/util/os/Makefile.am
===================================================================
--- GNUnet/src/util/os/Makefile.am      2006-08-24 03:30:40 UTC (rev 3292)
+++ GNUnet/src/util/os/Makefile.am      2006-08-24 03:51:42 UTC (rev 3293)
@@ -38,9 +38,12 @@
 semaphoretest_SOURCES = \
  semaphoretest.c
 semaphoretest_LDADD = \
+ $(top_builddir)/src/util/loggers/libgnunetutil_logging.la \
  $(top_builddir)/src/util/libgnunetutil.la  
 
 statuscallstest_SOURCES = \
  statuscallstest.c
 statuscallstest_LDADD = \
+ $(top_builddir)/src/util/loggers/libgnunetutil_logging.la \
+ $(top_builddir)/src/util/config_impl/libgnunetutil_config.la \
  $(top_builddir)/src/util/libgnunetutil.la  

Modified: GNUnet/src/util/os/daemontest.c
===================================================================
--- GNUnet/src/util/os/daemontest.c     2006-08-24 03:30:40 UTC (rev 3292)
+++ GNUnet/src/util/os/daemontest.c     2006-08-24 03:51:42 UTC (rev 3293)
@@ -24,16 +24,16 @@
  */
 
 #include "gnunet_util.h"
-#include "platform.h"
 #include "gnunet_util_config_impl.h"
 #include "gnunet_util_network_client.h"
 #include "gnunet_util_error_loggers.h"
+#include "platform.h"
 
 int main(int argc, 
         const char *argv[]) {
   int daemon;
   struct GE_Context * ectx;
-  static struct GC_Configuration * cfg;
+  struct GC_Configuration * cfg;
 
   ectx = GE_create_context_stderr(NO, 
                                  GE_WARNING | GE_ERROR | GE_FATAL |
@@ -47,11 +47,29 @@
                           cfg,
                           "check.conf",
                           NO);
-  GE_ASSERT(ectx, daemon > 0);
-  GE_ASSERT(ectx, OK == connection_wait_for_running(ectx,
-                                                   cfg,
-                                                   30 * cronSECONDS));
-  GE_ASSERT(ectx, OK == os_daemon_stop(ectx, daemon));
+  if (daemon <= 0) {
+    fprintf(stderr,
+           "Failed to start daemon.\n");
+    GC_free(cfg);
+    GE_free_context(ectx);
+    return 1;
+  }
+  if (0 != connection_wait_for_running(ectx,
+                                      cfg,
+                                      30 * cronSECONDS)) {
+    fprintf(stderr,
+           "Failed to confirm daemon running (after 30s).\n");
+    GC_free(cfg);
+    GE_free_context(ectx);
+    return 1;
+  }
+  if (OK != os_daemon_stop(ectx, daemon)) {
+    fprintf(stderr,
+           "Failed to stop daemon.\n");
+    GC_free(cfg);
+    GE_free_context(ectx);
+    return 1;
+  }
 
   GC_free(cfg);
   GE_free_context(ectx);

Modified: GNUnet/src/util/os/semaphoretest.c
===================================================================
--- GNUnet/src/util/os/semaphoretest.c  2006-08-24 03:30:40 UTC (rev 3292)
+++ GNUnet/src/util/os/semaphoretest.c  2006-08-24 03:51:42 UTC (rev 3293)
@@ -23,13 +23,15 @@
  */
 
 #include "gnunet_util.h"
+#include "gnunet_util_error_loggers.h"
 #include "platform.h"
 
 #include <sys/types.h>
-#ifndef MINGW             /* PORT-ME MINGW */
 
 static struct IPC_SEMAPHORE * ipc;
 
+static struct GE_Context * ectx;
+
 static int testIPCSemaphore() {
   pid_t me;
   int cnt;
@@ -46,12 +48,14 @@
   me = fork();
   sw = me;
 
-  ipc = IPC_SEMAPHORE_CREATE("/tmp/gnunet_ipc_semtest",
-                         0);
+  ipc = IPC_SEMAPHORE_CREATE(ectx,
+                            "/tmp/gnunet_ipc_semtest",
+                            0);
   for (cnt=0;cnt<3;cnt++) {
     if (sw == 0) {
       for (i=0;i<6;i++) {
-       IPC_SEMAPHORE_DOWN(ipc);
+       IPC_SEMAPHORE_DOWN(ipc,
+                          YES);
        fd = FOPEN("/tmp/gnunet_ipc_xchange",
                       "a+");
        if (fd == NULL) {
@@ -129,56 +133,17 @@
   return ret;
 }
 
-
-/**
- * Perform option parsing from the command line.
- */
-static int parseCommandLine(int argc,
-                           char * argv[]) {
-  char c;
-
-  while (1) {
-    int option_index = 0;
-    static struct GNoption long_options[] = {
-      { "loglevel",1, 0, 'L' },
-      { "config",  1, 0, 'c' },
-      { 0,0,0,0 }
-    };
-
-    c = GNgetopt_long(argc,
-                     argv,
-                     "c:L:",
-                     long_options,
-                     &option_index);
-
-    if (c == -1)
-      break;  /* No more flags to process */
-
-    switch(c) {
-    case 'L':
-      FREENONNULL(setConfigurationString("GNUNET",
-                                        "LOGLEVEL",
-                                        GNoptarg));
-      break;
-    case 'c':
-      FREENONNULL(setConfigurationString("FILES",
-                                        "gnunet.conf",
-                                        GNoptarg));
-      break;
-    } /* end of parsing commandline */
-  }
-  return OK;
-}
-#endif /* PORT-ME MINGW */
-
 int main(int argc, char * argv[]){
   int ret = 0;
 
-#ifndef MINGW
-  initUtil(argc, argv, &parseCommandLine);
+  ectx = GE_create_context_stderr(NO, 
+                                 GE_WARNING | GE_ERROR | GE_FATAL |
+                                 GE_USER | GE_ADMIN | GE_DEVELOPER |
+                                 GE_IMMEDIATE | GE_BULK);
+  GE_setDefaultContext(ectx);
+  os_init(ectx);
   ret += testIPCSemaphore();
   fprintf(stderr, "\n");
-  doneUtil();
-#endif
+  GE_free_context(ectx);
   return ret;
 }

Modified: GNUnet/src/util/os/statuscallstest.c
===================================================================
--- GNUnet/src/util/os/statuscallstest.c        2006-08-24 03:30:40 UTC (rev 
3292)
+++ GNUnet/src/util/os/statuscallstest.c        2006-08-24 03:51:42 UTC (rev 
3293)
@@ -1,76 +1,67 @@
+/*
+     This file is part of GNUnet.
+     (C) 2003, 2004, 2005, 2006 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
+     by the Free Software Foundation; either version 2, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
 /**
- * @file util/statuscallstest.c
- * @brief testcase for util/statuscalls.c
+ * @file util/os/statuscallstest.c
+ * @brief testcase for util/os/statuscalls.c
  */
 
 #include "gnunet_util.h"
+#include "gnunet_util_config_impl.h"
+#include "gnunet_util_error_loggers.h"
 #include "platform.h"
 
-/**
- * Perform option parsing from the command line.
- */
-static int parseCommandLine(int argc,
-                           char * argv[]) {
-  char c;
-
-  FREENONNULL(setConfigurationString("GNUNETD",
-                                    "_MAGIC_",
-                                    "YES"));
-  FREENONNULL(setConfigurationString("GNUNETD",
-                                    "GNUNETD_HOME",
-                                    "/tmp/gnunet_test/"));
-  FREENONNULL(setConfigurationString("FILES",
-                                    "gnunet.conf",
-                                    "check.conf"));
-  while (1) {
-    int option_index = 0;
-    static struct GNoption long_options[] = {
-      { "config",  1, 0, 'c' },
-      { 0,0,0,0 }
-    };
-
-    c = GNgetopt_long(argc,
-                     argv,
-                     "c:",
-                     long_options,
-                     &option_index);
-
-    if (c == -1)
-      break;  /* No more flags to process*/
-
-    switch(c) {
-    case 'c':
-      FREENONNULL(setConfigurationString("FILES",
-                                        "gnunet.conf",
-                                        GNoptarg));
-      break;
-    } /* end of parsing commandline */
-  }
-  return OK;
-}
-
 int main(int argc, char * argv[]){
   int ret;
   cron_t start;
+  struct GE_Context * ectx;
+  struct GC_Configuration * cfg;
 
-  if (OK != initUtil(argc, argv, &parseCommandLine))
-    errexit("Error during initialization!\n");
-  startCron();
+  ectx = GE_create_context_stderr(NO, 
+                                 GE_WARNING | GE_ERROR | GE_FATAL |
+                                 GE_USER | GE_ADMIN | GE_DEVELOPER |
+                                 GE_IMMEDIATE | GE_BULK);
+  GE_setDefaultContext(ectx);
+  cfg = GC_create_C_impl();
+  GE_ASSERT(ectx, cfg != NULL);
+  os_init(ectx);
   /* need to run each phase for more than 10s since
      statuscalls only refreshes that often... */
-  cronTime(&start);
+  start = get_time();
   while (start + 12 * cronSECONDS > get_time())
-    sleep(1);
-  cronTime(&start);
-  ret = getCPULoad();
+    PTHREAD_SLEEP(1);
+  start = get_time();
+  ret = os_cpu_get_load(ectx,
+                       cfg);
   while (start + 12 * cronSECONDS > get_time())
     sqrt(245.2523); /* do some processing to drive load up */
-  if (ret > getCPULoad())
+  if (ret > os_cpu_get_load(ectx,
+                           cfg)) {
     printf("busy loop decreased CPU load: %d < %d.\n",
           ret,
-          getCPULoad());
-  stopCron();
-  doneUtil();
-
-  return 0;
+          os_cpu_get_load(ectx,
+                          cfg));
+    ret = 1;
+  } else {
+    ret = 0;
+  }
+  GC_free(cfg);
+  GE_free_context(ectx);
+  return ret;
 }

Deleted: GNUnet/src/util/testconfig.conf
===================================================================
--- GNUnet/src/util/testconfig.conf     2006-08-24 03:30:40 UTC (rev 3292)
+++ GNUnet/src/util/testconfig.conf     2006-08-24 03:51:42 UTC (rev 3293)
@@ -1,19 +0,0 @@
-[GNUNET]
-SUBST=hello
-GNUNET_HOME=/tmp
-
-[test]
-a=a
-b=b
-five=5
-
-[more]
-c=c
-five=42
-
-               
-[last]
-test = $SUBST/world
-boom = "1 2 3 testing"
-trailing = YES 
-





reply via email to

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