gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r29642 - gnunet/src/util


From: gnunet
Subject: [GNUnet-SVN] r29642 - gnunet/src/util
Date: Thu, 26 Sep 2013 21:14:36 +0200

Author: LRN
Date: 2013-09-26 21:14:36 +0200 (Thu, 26 Sep 2013)
New Revision: 29642

Modified:
   gnunet/src/util/test_common_logging_dummy.c
   gnunet/src/util/test_common_logging_runtime_loglevels.c
Log:
More comments to make the testcase easier to understand later.
Increase code verbosity to make it obvious what is being tested.

Modified: gnunet/src/util/test_common_logging_dummy.c
===================================================================
--- gnunet/src/util/test_common_logging_dummy.c 2013-09-26 18:51:49 UTC (rev 
29641)
+++ gnunet/src/util/test_common_logging_dummy.c 2013-09-26 19:14:36 UTC (rev 
29642)
@@ -33,7 +33,9 @@
 #include "gnunet_network_lib.h"
 
 /**
- * Delay introduced between operations, useful for debugging.
+ * Artificial delay attached to each log call that is not skipped out.
+ * This must be long enough for us to not to mistake skipped log call
+ * on a slow machine for a non-skipped one.
  */
 #define OUTPUT_DELAY GNUNET_TIME_relative_multiply 
(GNUNET_TIME_UNIT_MICROSECONDS, 200)
 

Modified: gnunet/src/util/test_common_logging_runtime_loglevels.c
===================================================================
--- gnunet/src/util/test_common_logging_runtime_loglevels.c     2013-09-26 
18:51:49 UTC (rev 29641)
+++ gnunet/src/util/test_common_logging_runtime_loglevels.c     2013-09-26 
19:14:36 UTC (rev 29642)
@@ -32,6 +32,18 @@
 
 #define VERBOSE GNUNET_NO
 
+/**
+ * How much time the child is allowed to waste on skipped log calls, at most.
+ * Raspberry Pi takes 33 microseconds tops, this is 3x that value.
+ */
+#define MAX_SKIP_DELAY GNUNET_TIME_relative_multiply 
(GNUNET_TIME_UNIT_MICROSECONDS, 100).rel_value_us
+
+/**
+ * How much time non-skipped log call should take, at least.
+ * Keep in sync with the value in the dummy!
+ */
+#define OUTPUT_DELAY GNUNET_TIME_relative_multiply 
(GNUNET_TIME_UNIT_MICROSECONDS, 200).rel_value_us
+
 static int ok;
 
 static int phase = 0;
@@ -95,6 +107,10 @@
   char *r = p;
   char t[7];
   int i, j, stop = 0;
+  int level_matches;
+  int delay_is_sane;
+  int delay_is_a_dummy;
+  int delay_outside_of_range;
 
   j = 0;
   int stage = 0;
@@ -157,16 +173,46 @@
       break;
     }
   }
-  if (!stop || strcmp (expect_level, level) != 0 || *delay < 0 || *delay > 
1000000
-      || (!((*delay < delay_lessthan) || (*delay > delay_morethan)) && c != '1'
-          && c != '2'))
+  level_matches = (strcmp (expect_level, level) == 0);
+  delay_is_sane = (*delay >= 0) && (*delay <= 1000000);
+  delay_is_a_dummy = (c == 'L');
+  /* Delay must be either less than 'lessthan' (log call is skipped)
+   * or more than 'morethan' (log call is not skipped)
+   */
+  delay_outside_of_range = ((*delay < delay_lessthan) || (*delay > 
delay_morethan));
+  if (delay_is_a_dummy)
+    delay_outside_of_range = 1;
+
+  if (!stop)
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Wrong log format?\n");
+  if (!level_matches)
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Wrong log level\n");
+  if (!delay_is_sane)
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Delay %ld is insane\n", *delay);
+  if (!delay_outside_of_range)
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Delay %ld is not outside of range (%ld ; %ld)\n",
+                *delay, delay_lessthan, delay_morethan, c);
+  if (!stop || !level_matches || !delay_is_sane || !delay_outside_of_range)
     return NULL;
   *len = *len - i;
   return &r[i];
 }
 
-static char buf[20 * 16];
+/**
+ * Up to 8 non-skipped GNUNET_log() calls
+ * + extra line with delay for each one
+ */
+#define LOG_MAX_NUM_LINES (8 * 2)
+/**
+ * Actual message is 17 chars at most
+ */
+#define LOG_MAX_LINE_LENGTH (17)
 
+#define LOG_BUFFER_SIZE LOG_MAX_NUM_LINES * LOG_MAX_LINE_LENGTH
+
+static char buf[LOG_BUFFER_SIZE];
+
 static char *buf_ptr;
 
 static int bytes;
@@ -218,57 +264,73 @@
    */
   char *p = buf;
 
-  if (bytes == 20 * 16 ||
+  if (bytes == LOG_BUFFER_SIZE ||
       !(p =
-        read_output_line (0, 3, 4, 9, 'L', "ERROR", -1, 1, phase, p, &bytes,
-                          &delay, level)) ||
+        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)) ||
+        read_output_line (0, 3, 4, 9, '1', "ERROR", OUTPUT_DELAY,
+                          MAX_SKIP_DELAY, phase, p,
+                          &bytes, &delays[0], level)) ||
       !(p =
-        read_output_line (1, 3, 5, 9, 'L', "WARNING", -1, 1, phase, p, &bytes,
-                          &delay, level)) ||
+        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,
+        read_output_line (0, 3, 4, 9, '1', "WARNING", OUTPUT_DELAY,
+                          MAX_SKIP_DELAY, phase, p,
                           &bytes, &delays[1], level)) ||
       !(p =
-        read_output_line (2, 3, 6, 7, 'L', "INFO", -1, 1, phase, p, &bytes,
-                          &delay, level)) ||
+        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)) ||
+        read_output_line (0, 3, 4, 9, '1', "INFO", OUTPUT_DELAY,
+                          MAX_SKIP_DELAY, phase, p,
+                          &bytes, &delays[2], level)) ||
       !(p =
-        read_output_line (3, 3, 7, 7, 'L', "DEBUG", -1, 1, phase, p, &bytes,
-                          &delay, level)) ||
+        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)) ||
+        read_output_line (0, 3, 4, 9, '1', "DEBUG", OUTPUT_DELAY,
+                          MAX_SKIP_DELAY, phase, p,
+                          &bytes, &delays[3], level)) ||
       !(p =
-        read_output_line (0, 3, 4, 9, 'L', "ERROR", -1, 1, phase, p, &bytes,
-                          &delay, level)) ||
+        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)) ||
+        read_output_line (0, 3, 4, 9, '2', "ERROR", OUTPUT_DELAY,
+                          MAX_SKIP_DELAY, phase, p,
+                          &bytes, &delays[4], level)) ||
       !(p =
-        read_output_line (0, 3, 5, 9, 'L', "WARNING", -1, 1, phase, p, &bytes,
-                          &delay, level)) ||
+        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,
+        read_output_line (0, 3, 4, 9, '2', "WARNING", OUTPUT_DELAY,
+                          MAX_SKIP_DELAY, phase, p,
                           &bytes, &delays[5], level)) ||
       !(p =
-        read_output_line (-1, -1, 6, 7, 'L', "INFO", -1, 1, phase, p, &bytes,
-                          &delay, level)) ||
+        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)) ||
+        read_output_line (0, 3, 4, 9, '2', "INFO", OUTPUT_DELAY,
+                          MAX_SKIP_DELAY, phase, p,
+                          &bytes, &delays[6], level)) ||
       !(p =
-        read_output_line (-1, -1, 7, 7, 'L', "DEBUG", -1, 1, phase, p, &bytes,
-                          &delay, level)) ||
+        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)))
+        read_output_line (0, 3, 4, 9, '2', "DEBUG", OUTPUT_DELAY,
+                          MAX_SKIP_DELAY, phase, p,
+                          &bytes, &delays[7], level)))
   {
-    if (bytes == 20 * 16)
+    if (bytes == LOG_BUFFER_SIZE)
       FPRINTF (stderr, "%s",  "Ran out of buffer space!\n");
     GNUNET_break (0);
     ok = 2;




reply via email to

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