add units to time, use configuration time api where appropriate, fixing Mantis #1875
[oweals/gnunet.git] / src / util / test_scheduler.c
index 52e4b36849b4a7da446ae674c4b8adcdb7249c2b..788ba13fa6a79dbffcd8137bb2feccc7493fe427 100644 (file)
 #include "gnunet_time_lib.h"
 #include "gnunet_disk_lib.h"
 
-#define VERBOSE GNUNET_NO
+#define VERBOSE GNUNET_EXTRA_LOGGING
 
 static void
 task3 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   int *ok = cls;
+
   /* t4 should be ready (albeit with lower priority) */
-  GNUNET_assert (1 == GNUNET_SCHEDULER_get_load (tc->sched,
-                                                 GNUNET_SCHEDULER_PRIORITY_COUNT));
+  GNUNET_assert (1 ==
+                 GNUNET_SCHEDULER_get_load (GNUNET_SCHEDULER_PRIORITY_COUNT));
   GNUNET_assert (3 == *ok);
   (*ok) = 4;
 }
@@ -45,18 +46,19 @@ static void
 task2 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   int *ok = cls;
+
   GNUNET_assert (2 == *ok);
   (*ok) = 3;
   /* t3 will go before t4: higher priority */
-  GNUNET_SCHEDULER_add_with_priority (tc->sched,
-                                      GNUNET_SCHEDULER_PRIORITY_UI,
-                                      &task3, cls);
+  GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI, &task3,
+                                      cls);
 }
 
 static void
 task4 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   int *ok = cls;
+
   GNUNET_assert (4 == *ok);
   (*ok) = 5;
 }
@@ -70,6 +72,7 @@ taskWrt (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   static char c;
   int *ok = cls;
+
   GNUNET_assert (6 == *ok);
   GNUNET_assert (GNUNET_NETWORK_fdset_handle_isset (tc->write_ready, fds[1]));
   (*ok) = 7;
@@ -87,6 +90,7 @@ static void
 taskLast (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   int *ok = cls;
+
   /* t4 should be ready (albeit with lower priority) */
   GNUNET_assert (8 == *ok);
   (*ok) = 0;
@@ -97,14 +101,14 @@ taskRd (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   static char c;
   int *ok = cls;
+
   GNUNET_assert (7 == *ok);
   GNUNET_assert (GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, fds[0]));
   GNUNET_assert (1 == GNUNET_DISK_file_read (fds[0], &c, 1));
   (*ok) = 8;
-  GNUNET_SCHEDULER_add_with_priority (tc->sched,
-                                      GNUNET_SCHEDULER_PRIORITY_IDLE,
-                                      &taskLast, cls);
-  GNUNET_SCHEDULER_shutdown (tc->sched);
+  GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, &taskLast,
+                                      cls);
+  GNUNET_SCHEDULER_shutdown ();
 }
 
 
@@ -112,18 +116,17 @@ static void
 task5 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   int *ok = cls;
+
   GNUNET_assert (5 == *ok);
   (*ok) = 6;
-  p = GNUNET_DISK_pipe (GNUNET_NO);
+  p = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO);
   GNUNET_assert (NULL != p);
   fds[0] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_READ);
   fds[1] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_WRITE);
-  GNUNET_SCHEDULER_add_read_file (tc->sched,
-                                  GNUNET_TIME_UNIT_FOREVER_REL,
-                                  fds[0], &taskRd, cls);
-  GNUNET_SCHEDULER_add_write_file (tc->sched,
-                                   GNUNET_TIME_UNIT_FOREVER_REL,
-                                   fds[1], &taskWrt, cls);
+  GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, fds[0], &taskRd,
+                                  cls);
+  GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, fds[1],
+                                   &taskWrt, cls);
 }
 
 
@@ -137,12 +140,11 @@ task1 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   GNUNET_assert (1 == *ok);
   (*ok) = 2;
   /* t2 will go first -- prereq for all */
-  t2 = GNUNET_SCHEDULER_add_after (tc->sched,
-                                   GNUNET_SCHEDULER_NO_TASK, &task2, cls);
+  t2 = GNUNET_SCHEDULER_add_after (GNUNET_SCHEDULER_NO_TASK, &task2, cls);
   /* t4 will go after t2 ('add after') and after t3 (priority) */
-  t4 = GNUNET_SCHEDULER_add_after (tc->sched, t2, &task4, cls);
+  t4 = GNUNET_SCHEDULER_add_after (t2, &task4, cls);
   /* t5 will go last (after p4) */
-  GNUNET_SCHEDULER_add_after (tc->sched, t4, &task5, cls);
+  GNUNET_SCHEDULER_add_after (t4, &task5, cls);
 }
 
 
@@ -166,11 +168,11 @@ static void
 taskShutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   int *ok = cls;
+
   GNUNET_assert (1 == *ok);
   *ok = 8;
-  GNUNET_SCHEDULER_add_delayed (tc->sched,
-                                GNUNET_TIME_UNIT_FOREVER_REL, &taskLast, cls);
-  GNUNET_SCHEDULER_shutdown (tc->sched);
+  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &taskLast, cls);
+  GNUNET_SCHEDULER_shutdown ();
 }
 
 
@@ -193,10 +195,10 @@ static void
 taskSig (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   int *ok = cls;
+
   GNUNET_assert (1 == *ok);
   *ok = 8;
-  GNUNET_SCHEDULER_add_delayed (tc->sched,
-                                GNUNET_TIME_UNIT_FOREVER_REL, &taskLast, cls);
+  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &taskLast, cls);
   GNUNET_break (0 == PLIBC_KILL (getpid (), SIGTERM));
 }
 
@@ -223,10 +225,8 @@ taskCancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 
   GNUNET_assert (1 == *ok);
   *ok = 0;
-  GNUNET_SCHEDULER_cancel (tc->sched,
-                           GNUNET_SCHEDULER_add_after (tc->sched,
-                                                       GNUNET_SCHEDULER_NO_TASK,
-                                                       &taskNeverRun, NULL));
+  GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_add_after
+                           (GNUNET_SCHEDULER_NO_TASK, &taskNeverRun, NULL));
 }