-typo
[oweals/gnunet.git] / src / util / test_common_logging_runtime_loglevels.c
index 5b89b722129fc1b834efc526e3947b3b4e607014..4c6ae003936f40e8f4de40135b1f2a07e4797b3d 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2008 Christian Grothoff (and other contributing authors)
+     (C) 2011 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
@@ -30,7 +30,7 @@
 #include "gnunet_disk_lib.h"
 #include "gnunet_os_lib.h"
 
-#define VERBOSE GNUNET_EXTRA_LOGGING
+#define VERBOSE GNUNET_NO
 
 static int ok;
 static int phase = 0;
@@ -43,20 +43,23 @@ static struct GNUNET_DISK_PipeHandle *pipe_stdout;
 static GNUNET_SCHEDULER_TaskIdentifier die_task;
 
 static void
-runone ();
+runone (void);
 
 static void
 end_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending phase %d, ok is %d\n", phase,
               ok);
-  if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
+  if (NULL != proc)
   {
-    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+    if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
+    {
+      GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+    }
+    GNUNET_OS_process_wait (proc);
+    GNUNET_OS_process_destroy (proc);
+    proc = NULL;
   }
-  GNUNET_OS_process_wait (proc);
-  GNUNET_OS_process_close (proc);
-  proc = NULL;
   GNUNET_DISK_pipe_close (pipe_stdout);
   if (ok == 1)
   {
@@ -171,7 +174,7 @@ read_call (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
     buf_ptr += rd;
     bytes += rd;
 #if VERBOSE
-    fprintf (stderr, "got %d bytes, reading more\n", rd);
+    FPRINTF (stderr, "got %d bytes, reading more\n", rd);
 #endif
     GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
                                     stdout_read_handle, &read_call,
@@ -180,7 +183,7 @@ read_call (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   }
 
 #if VERBOSE
-  fprintf (stderr, "bytes is %d:%s\n", bytes, buf);
+  FPRINTF (stderr, "bytes is %d:%s\n", bytes, buf);
 #endif
 
   /* +------CHILD OUTPUT--
@@ -251,7 +254,7 @@ read_call (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
                           &delays[7], level)))
   {
     if (bytes == 20 * 16)
-      fprintf (stderr, "Ran out of buffer space!\n");
+      FPRINTF (stderr, "%s",  "Ran out of buffer space!\n");
     GNUNET_break (0);
     ok = 2;
     GNUNET_SCHEDULER_cancel (die_task);
@@ -268,7 +271,7 @@ runone ()
 {
   const struct GNUNET_DISK_FileHandle *stdout_read_handle;
 
-  pipe_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES);
+  pipe_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES);
 
   if (pipe_stdout == NULL)
   {
@@ -279,6 +282,7 @@ runone ()
 
   putenv ("GNUNET_LOG=");
   putenv ("GNUNET_FORCE_LOG=");
+  putenv ("GNUNET_FORCE_LOGFILE=");
   switch (phase)
   {
   case 0:
@@ -313,9 +317,14 @@ runone ()
     break;
   }
 
-  proc =
-      GNUNET_OS_start_process (NULL, pipe_stdout, "./test_common_logging_dummy",
-                               "test_common_logging_dummy", NULL);
+  proc = GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, pipe_stdout,
+#if MINGW
+                                  "test_common_logging_dummy",
+#else
+                                  "./test_common_logging_dummy",
+#endif
+                                  "test_common_logging_dummy", NULL);
+  GNUNET_assert (NULL != proc);
   putenv ("GNUNET_FORCE_LOG=");
   putenv ("GNUNET_LOG=");
 
@@ -346,34 +355,16 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   runone ();
 }
 
-/**
- * Main method, starts scheduler with task1,
- * checks that "ok" is correct at the end.
- */
-static int
-check ()
-{
-  ok = 1;
-  GNUNET_SCHEDULER_run (&task, &ok);
-  return ok;
-}
-
 
 int
 main (int argc, char *argv[])
 {
-  int ret;
-
   GNUNET_log_setup ("test-common-logging-runtime-loglevels",
-#if VERBOSE
-                    "DEBUG",
-#else
                     "WARNING",
-#endif
                     NULL);
-  ret = check ();
-
-  return ret;
+  ok = 1;
+  GNUNET_SCHEDULER_run (&task, &ok);
+  return ok;
 }
 
 /* end of test_common_logging_runtime_loglevels.c */