handling replies continuously from server
[oweals/gnunet.git] / src / util / test_common_logging_runtime_loglevels.c
index 9a42d6aea8de24362e42cf16ef9ba7744c5aff48..b914ae1c6f20f88b648d5b098531f58b83b44c4c 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;
@@ -42,18 +42,20 @@ static struct GNUNET_DISK_PipeHandle *pipe_stdout;
 
 static GNUNET_SCHEDULER_TaskIdentifier die_task;
 
-static void runone ();
+static void
+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);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending phase %d, ok is %d\n", phase,
+              ok);
   if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
   {
     GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
   }
   GNUNET_OS_process_wait (proc);
-  GNUNET_OS_process_close (proc);
+  GNUNET_OS_process_destroy (proc);
   proc = NULL;
   GNUNET_DISK_pipe_close (pipe_stdout);
   if (ok == 1)
@@ -79,26 +81,32 @@ read_output_line (int phase_from1, int phase_to1, int phase_from2,
   char *r = p;
   char t[7];
   int i, j, stop = 0;
+
   j = 0;
   int stage = 0;
+
   if (!(phase >= phase_from1 && phase <= phase_to1) &&
-     !(phase >= phase_from2 && phase <= phase_to2))
+      !(phase >= phase_from2 && phase <= phase_to2))
     return p;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to match '%c%s \\d\\r\\n' on %s\n", c, expect_level, p);
+#if 0
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Trying to match '%c%s \\d\\r\\n' on %s\n", c, expect_level, p);
+#endif
   for (i = 0; i < *len && !stop; i++)
   {
     switch (stage)
     {
-    case 0: /* read first char */
+    case 0:                    /* read first char */
       if (r[i] != c)
       {
-        GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Expected '%c', but got '%c'\n", c, r[i]);
+        GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Expected '%c', but got '%c'\n", c,
+                    r[i]);
         GNUNET_break (0);
         return NULL;
       }
       stage += 1;
       break;
-    case 1:  /* read at most 7 char-long error level string, finished by ' ' */
+    case 1:                    /* read at most 7 char-long error level string, finished by ' ' */
       if (r[i] == ' ')
       {
         level[j] = '\0';
@@ -114,7 +122,7 @@ read_output_line (int phase_from1, int phase_to1, int phase_from2,
       else
         level[j++] = r[i];
       break;
-    case 2: /* read the delay, finished by '\n' */
+    case 2:                    /* read the delay, finished by '\n' */
       t[j++] = r[i];
 #if WINDOWS
       if (r[i] == '\r' && r[i + 1] == '\n')
@@ -135,14 +143,15 @@ read_output_line (int phase_from1, int phase_to1, int phase_from2,
       break;
     }
   }
-  if (!stop || strcmp (expect_level, level) != 0 || *delay < 0 || *delay > 1000 ||
-      (!((*delay < delay_lessthan) || !(*delay > delay_morethan)) && c != '1' && c != '2'))
+  if (!stop || strcmp (expect_level, level) != 0 || *delay < 0 || *delay > 1000
+      || (!((*delay < delay_lessthan) || !(*delay > delay_morethan)) && c != '1'
+          && c != '2'))
     return NULL;
   *len = *len - i;
   return &r[i];
 }
 
-char buf[20*16];
+char buf[20 * 16];
 char *buf_ptr;
 int bytes;
 
@@ -155,13 +164,14 @@ read_call (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   long delays[8];
   int rd;
 
-  rd = GNUNET_DISK_file_read (stdout_read_handle, buf_ptr, sizeof (buf) - bytes);
+  rd = GNUNET_DISK_file_read (stdout_read_handle, buf_ptr,
+                              sizeof (buf) - bytes);
   if (rd > 0)
   {
     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,
@@ -170,7 +180,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--
@@ -189,26 +199,59 @@ read_call (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
    * | 9  * *      * *
    */
   char *p = buf;
-  if (bytes == 20*16 ||
-      !(p = read_output_line (0, 3, 4, 9, 'L', "ERROR", -1, 1, phase, p, &bytes, &delay, level)) ||
-      !(p = read_output_line (0, 3, 4, 9, '1', "ERROR", 200, 400, phase, p, &bytes, &delays[0], level)) ||
-      !(p = read_output_line (1, 3, 5, 9, 'L', "WARNING", -1, 1, phase, p, &bytes, &delay, level)) ||
-      !(p = read_output_line (0, 3, 4, 9, '1', "WARNING", 200, 400, phase, p, &bytes, &delays[1], level)) ||
-      !(p = read_output_line (2, 3, 6, 7, 'L', "INFO", -1, 1, phase, p, &bytes, &delay, level)) ||
-      !(p = read_output_line (0, 3, 4, 9, '1', "INFO", 200, 400, phase, p, &bytes, &delays[2], level)) ||
-      !(p = read_output_line (3, 3, 7, 7, 'L', "DEBUG", -1, 1, phase, p, &bytes, &delay, level)) ||
-      !(p = read_output_line (0, 3, 4, 9, '1', "DEBUG", 200, 400, phase, p, &bytes, &delays[3], level)) ||
-      !(p = read_output_line (0, 3, 4, 9, 'L', "ERROR", -1, 1, phase, p, &bytes, &delay, level)) ||
-      !(p = read_output_line (0, 3, 4, 9, '2', "ERROR", 200, 400, phase, p, &bytes, &delays[4], level)) ||
-      !(p = read_output_line (0, 3, 5, 9, 'L', "WARNING", -1, 1, phase, p, &bytes, &delay, level)) ||
-      !(p = read_output_line (0, 3, 4, 9, '2', "WARNING", 200, 400, phase, p, &bytes, &delays[5], level)) ||
-      !(p = read_output_line (-1, -1, 6, 7, 'L', "INFO", -1, 1, phase, p, &bytes, &delay, level)) ||
-      !(p = read_output_line (0, 3, 4, 9, '2', "INFO", 200, 400, phase, p, &bytes, &delays[6], level)) ||
-      !(p = read_output_line (-1, -1, 7, 7, 'L', "DEBUG", -1, 1, phase, p, &bytes, &delay, level)) ||
-      !(p = read_output_line (0, 3, 4, 9, '2', "DEBUG", 200, 400, phase, p, &bytes, &delays[7], level)))
+
+  if (bytes == 20 * 16 ||
+      !(p =
+        read_output_line (0, 3, 4, 9, 'L', "ERROR", -1, 1, phase, p, &bytes,
+                          &delay, level)) ||
+      !(p =
+        read_output_line (0, 3, 4, 9, '1', "ERROR", 200, 400, phase, p, &bytes,
+                          &delays[0], level)) ||
+      !(p =
+        read_output_line (1, 3, 5, 9, 'L', "WARNING", -1, 1, phase, p, &bytes,
+                          &delay, level)) ||
+      !(p =
+        read_output_line (0, 3, 4, 9, '1', "WARNING", 200, 400, phase, p,
+                          &bytes, &delays[1], level)) ||
+      !(p =
+        read_output_line (2, 3, 6, 7, 'L', "INFO", -1, 1, phase, p, &bytes,
+                          &delay, level)) ||
+      !(p =
+        read_output_line (0, 3, 4, 9, '1', "INFO", 200, 400, phase, p, &bytes,
+                          &delays[2], level)) ||
+      !(p =
+        read_output_line (3, 3, 7, 7, 'L', "DEBUG", -1, 1, phase, p, &bytes,
+                          &delay, level)) ||
+      !(p =
+        read_output_line (0, 3, 4, 9, '1', "DEBUG", 200, 400, phase, p, &bytes,
+                          &delays[3], level)) ||
+      !(p =
+        read_output_line (0, 3, 4, 9, 'L', "ERROR", -1, 1, phase, p, &bytes,
+                          &delay, level)) ||
+      !(p =
+        read_output_line (0, 3, 4, 9, '2', "ERROR", 200, 400, phase, p, &bytes,
+                          &delays[4], level)) ||
+      !(p =
+        read_output_line (0, 3, 5, 9, 'L', "WARNING", -1, 1, phase, p, &bytes,
+                          &delay, level)) ||
+      !(p =
+        read_output_line (0, 3, 4, 9, '2', "WARNING", 200, 400, phase, p,
+                          &bytes, &delays[5], level)) ||
+      !(p =
+        read_output_line (-1, -1, 6, 7, 'L', "INFO", -1, 1, phase, p, &bytes,
+                          &delay, level)) ||
+      !(p =
+        read_output_line (0, 3, 4, 9, '2', "INFO", 200, 400, phase, p, &bytes,
+                          &delays[6], level)) ||
+      !(p =
+        read_output_line (-1, -1, 7, 7, 'L', "DEBUG", -1, 1, phase, p, &bytes,
+                          &delay, level)) ||
+      !(p =
+        read_output_line (0, 3, 4, 9, '2', "DEBUG", 200, 400, phase, p, &bytes,
+                          &delays[7], level)))
   {
-    if (bytes == 20*16)
-      fprintf (stderr, "Ran out of buffer space!\n");
+    if (bytes == 20 * 16)
+      FPRINTF (stderr, "%s",  "Ran out of buffer space!\n");
     GNUNET_break (0);
     ok = 2;
     GNUNET_SCHEDULER_cancel (die_task);
@@ -225,18 +268,18 @@ 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)
   {
     GNUNET_break (0);
     ok = 2;
-    GNUNET_free (fn);
     return;
   }
 
   putenv ("GNUNET_LOG=");
   putenv ("GNUNET_FORCE_LOG=");
+  putenv ("GNUNET_FORCE_LOGFILE=");
   switch (phase)
   {
   case 0:
@@ -271,10 +314,13 @@ 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, NULL, pipe_stdout,
+#if MINGW
+                                  "test_common_logging_dummy",
+#else
+                                  "./test_common_logging_dummy",
+#endif
+                                  "test_common_logging_dummy", NULL);
   putenv ("GNUNET_FORCE_LOG=");
   putenv ("GNUNET_LOG=");