fix #4545: create directory for log file if it does not exist
[oweals/gnunet.git] / src / util / test_scheduler_delay.c
index f5477fd4c4922a5317f8fb7419ef6f54df522649..93568cd81b3b6e79f833ca0b5f1cfca0e7d15f39 100644 (file)
@@ -1,10 +1,10 @@
 /*
      This file is part of GNUnet.
 /*
      This file is part of GNUnet.
-     (C) 2001, 2002, 2003, 2004, 2006 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2001-2013 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
 
      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
+     by the Free Software Foundation; either version 3, or (at your
      option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
      option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
 
      You should have received a copy of the GNU General Public License
      along with GNUnet; see the file COPYING.  If not, write to the
 
      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.
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
 */
 /**
  * @file util/test_scheduler_delay.c
  * @brief testcase for delay of scheduler, measures how
 */
 /**
  * @file util/test_scheduler_delay.c
  * @brief testcase for delay of scheduler, measures how
- *  precise the timers are.  Expect values between 10 and 20 ms on
+ *  precise the timers are.  Expect values between 0.2 and 2 ms on
  *  modern machines.
  */
 #include "platform.h"
  *  modern machines.
  */
 #include "platform.h"
-#include "gnunet_common.h"
-#include "gnunet_scheduler_lib.h"
-#include "gnunet_time_lib.h"
-
-#define VERBOSE GNUNET_NO
+#include "gnunet_util_lib.h"
 
 static struct GNUNET_TIME_Absolute target;
 
 
 static struct GNUNET_TIME_Absolute target;
 
@@ -38,70 +34,61 @@ static unsigned long long cumDelta;
 
 #define INCR 47
 
 
 #define INCR 47
 
-#define MAXV 1500
+#define MAXV 5000
+
 
 /**
  * Signature of the main function of a task.
  *
  * @param cls closure
 
 /**
  * Signature of the main function of a task.
  *
  * @param cls closure
- * @param tc context
  */
 static void
  */
 static void
-test_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+test_task (void *cls)
 {
   struct GNUNET_TIME_Absolute now;
 
   now = GNUNET_TIME_absolute_get ();
 {
   struct GNUNET_TIME_Absolute now;
 
   now = GNUNET_TIME_absolute_get ();
-  if (now.value > target.value)
-    cumDelta += (now.value - target.value);
+  if (now.abs_value_us > target.abs_value_us)
+    cumDelta += (now.abs_value_us - target.abs_value_us);
   else
   else
-    cumDelta += (target.value - now.value);
+    cumDelta += (target.abs_value_us - now.abs_value_us);
   target =
   target =
-    GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply
-                                      (GNUNET_TIME_UNIT_MILLISECONDS, i));
-  fprintf (stderr, ".");
+      GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply
+                                        (GNUNET_TIME_UNIT_MICROSECONDS, i));
+  FPRINTF (stderr, "%s",  ".");
   if (i > MAXV)
   if (i > MAXV)
-    {
-      fprintf (stderr, "\n");
-      return;
-    }
-  GNUNET_SCHEDULER_add_delayed (tc->sched,
-                                GNUNET_NO,
-                                GNUNET_SCHEDULER_PRIORITY_DEFAULT,
-                                GNUNET_SCHEDULER_NO_TASK,
-                                GNUNET_TIME_relative_multiply
-                                (GNUNET_TIME_UNIT_MILLISECONDS, i),
-                                &test_task, NULL);
+  {
+    FPRINTF (stderr, "%s",  "\n");
+    return;
+  }
+  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+                                (GNUNET_TIME_UNIT_MICROSECONDS, i),
+                               &test_task,
+                                NULL);
   i += INCR;
 }
 
   i += INCR;
 }
 
-static int
-check ()
+
+int
+main (int argc, char *argv[])
 {
 {
+  GNUNET_log_setup ("test-scheduler-delay",
+                   "WARNING",
+                   NULL);
   target = GNUNET_TIME_absolute_get ();
   GNUNET_SCHEDULER_run (&test_task, NULL);
   FPRINTF (stdout,
   target = GNUNET_TIME_absolute_get ();
   GNUNET_SCHEDULER_run (&test_task, NULL);
   FPRINTF (stdout,
-           "Sleep precision: %llu ms. ", cumDelta / 1000 / (MAXV / INCR));
-  if (cumDelta <= 10 * MAXV / INCR)
-    fprintf (stdout, "Timer precision is excellent.\n");
-  else if (cumDelta <= 50 * MAXV / INCR)        /* 50 ms average deviation */
-    fprintf (stdout, "Timer precision is good.\n");
-  else if (cumDelta > 250 * MAXV / INCR)
-    fprintf (stdout, "Timer precision is awful.\n");
+          "Sleep precision: %llu microseconds (average delta). ",
+           cumDelta / (MAXV / INCR));
+  if (cumDelta <= 500 * MAXV / INCR)
+    FPRINTF (stdout, "%s",  "Timer precision is excellent.\n");
+  else if (cumDelta <= 5000 * MAXV / INCR)        /* 5 ms average deviation */
+    FPRINTF (stdout, "%s",  "Timer precision is good.\n");
+  else if (cumDelta > 25000 * MAXV / INCR)
+    FPRINTF (stdout, "%s",  "Timer precision is awful.\n");
   else
   else
-    fprintf (stdout, "Timer precision is acceptable.\n");
+    FPRINTF (stdout, "%s",  "Timer precision is acceptable.\n");
   return 0;
 }
 
   return 0;
 }
 
-int
-main (int argc, char *argv[])
-{
-  int ret;
-
-  GNUNET_log_setup ("test-scheduler-delay", "WARNING", NULL);
-  ret = check ();
-
-  return ret;
-}
-
 /* end of test_scheduler_delay.c */
 /* end of test_scheduler_delay.c */