-code deduplication in rsa sign/verify code
[oweals/gnunet.git] / src / util / test_scheduler.c
index 788ba13fa6a79dbffcd8137bb2feccc7493fe427..2a9ed2db16588f577572045cd69636009b10a23a 100644 (file)
 #include "gnunet_time_lib.h"
 #include "gnunet_disk_lib.h"
 
-#define VERBOSE GNUNET_EXTRA_LOGGING
 
-static void
-task3 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  int *ok = cls;
+struct GNUNET_DISK_PipeHandle *p;
 
-  /* t4 should be ready (albeit with lower priority) */
-  GNUNET_assert (1 ==
-                 GNUNET_SCHEDULER_get_load (GNUNET_SCHEDULER_PRIORITY_COUNT));
-  GNUNET_assert (3 == *ok);
-  (*ok) = 4;
-}
+static const struct GNUNET_DISK_FileHandle *fds[2];
 
 
 static void
@@ -47,25 +38,23 @@ task2 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   int *ok = cls;
 
+  /* t3 should be ready (albeit with lower priority) */
+  GNUNET_assert (1 ==
+                 GNUNET_SCHEDULER_get_load (GNUNET_SCHEDULER_PRIORITY_COUNT));
   GNUNET_assert (2 == *ok);
   (*ok) = 3;
-  /* t3 will go before t4: higher priority */
-  GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI, &task3,
-                                      cls);
 }
 
+
 static void
-task4 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+task3 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   int *ok = cls;
 
-  GNUNET_assert (4 == *ok);
-  (*ok) = 5;
+  GNUNET_assert (3 == *ok);
+  (*ok) = 4;
 }
 
-struct GNUNET_DISK_PipeHandle *p;
-static const struct GNUNET_DISK_FileHandle *fds[2];
-
 
 static void
 taskWrt (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
@@ -86,6 +75,7 @@ taskNeverRun (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   GNUNET_assert (0);
 }
 
+
 static void
 taskLast (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
@@ -96,6 +86,7 @@ taskLast (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   (*ok) = 0;
 }
 
+
 static void
 taskRd (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
@@ -113,13 +104,13 @@ taskRd (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 
 
 static void
-task5 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+task4 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   int *ok = cls;
 
-  GNUNET_assert (5 == *ok);
+  GNUNET_assert (4 == *ok);
   (*ok) = 6;
-  p = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO);
+  p = GNUNET_DISK_pipe (GNUNET_NO, 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);
@@ -134,21 +125,16 @@ static void
 task1 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   int *ok = cls;
-  GNUNET_SCHEDULER_TaskIdentifier t2;
-  GNUNET_SCHEDULER_TaskIdentifier t4;
 
   GNUNET_assert (1 == *ok);
   (*ok) = 2;
-  /* t2 will go first -- prereq for all */
-  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 (t2, &task4, cls);
-  /* t5 will go last (after p4) */
-  GNUNET_SCHEDULER_add_after (t4, &task5, cls);
+  GNUNET_SCHEDULER_add_now (&task3, cls);
+  GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI, &task2,
+                                      cls);
+  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &task4, cls);
 }
 
 
-
 /**
  * Main method, starts scheduler with task1,
  * checks that "ok" is correct at the end.
@@ -225,8 +211,8 @@ taskCancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 
   GNUNET_assert (1 == *ok);
   *ok = 0;
-  GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_add_after
-                           (GNUNET_SCHEDULER_NO_TASK, &taskNeverRun, NULL));
+  GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_add_now
+                           (&taskNeverRun, NULL));
 }
 
 
@@ -245,7 +231,6 @@ checkCancel ()
 }
 
 
-
 int
 main (int argc, char *argv[])
 {