X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Futil%2Ftest_scheduler.c;h=4cfd81c819bf8095c0170822ba73eb3dc5e8b8c9;hb=9edc29a3c924554eecc00aa856bf3b0eb95ead52;hp=f0c908d7d6e62473aa03c5095f08dcfcc483863a;hpb=75a33a1499cf60ea4364c9aa673816629a6c1413;p=oweals%2Fgnunet.git diff --git a/src/util/test_scheduler.c b/src/util/test_scheduler.c index f0c908d7d..4cfd81c81 100644 --- a/src/util/test_scheduler.c +++ b/src/util/test_scheduler.c @@ -22,45 +22,35 @@ * @brief tests for the scheduler */ #include "platform.h" -#include "gnunet_common.h" -#include "gnunet_scheduler_lib.h" -#include "gnunet_time_lib.h" -#include "gnunet_disk_lib.h" +#include "gnunet_util_lib.h" -#define VERBOSE GNUNET_NO -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 (GNUNET_SCHEDULER_PRIORITY_COUNT)); - GNUNET_assert (3 == *ok); - (*ok) = 4; -} +struct GNUNET_DISK_PipeHandle *p; + +static const struct GNUNET_DISK_FileHandle *fds[2]; static void 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; -} -struct GNUNET_DISK_PipeHandle *p; -static const struct GNUNET_DISK_FileHandle *fds[2]; + GNUNET_assert (3 == *ok); + (*ok) = 4; +} static void @@ -68,6 +58,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; @@ -81,44 +72,49 @@ taskNeverRun (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_assert (0); } + 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; } + static void 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 (GNUNET_SCHEDULER_PRIORITY_IDLE, - &taskLast, cls); + GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, &taskLast, + cls); GNUNET_SCHEDULER_shutdown (); } 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); - 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); + 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); } @@ -126,21 +122,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. @@ -160,6 +151,7 @@ static void taskShutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { int *ok = cls; + GNUNET_assert (1 == *ok); *ok = 8; GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &taskLast, cls); @@ -182,14 +174,16 @@ checkShutdown () } +#ifndef MINGW static void taskSig (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { int *ok = cls; + GNUNET_assert (1 == *ok); *ok = 8; GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &taskLast, cls); - GNUNET_break (0 == PLIBC_KILL (getpid (), SIGTERM)); + GNUNET_break (0 == PLIBC_KILL (getpid (), GNUNET_TERM_SIG)); } @@ -206,6 +200,7 @@ checkSignal () GNUNET_SCHEDULER_run (&taskSig, &ok); return ok; } +#endif static void @@ -215,8 +210,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)); } @@ -235,7 +230,6 @@ checkCancel () } - int main (int argc, char *argv[]) {