2 This file is part of GNUnet.
3 Copyright (C) 2009 GNUnet e.V.
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 * @file util/test_scheduler.c
22 * @brief tests for the scheduler
25 #include "gnunet_util_lib.h"
28 static struct GNUNET_DISK_PipeHandle *p;
30 static const struct GNUNET_DISK_FileHandle *fds[2];
38 /* t3 should be ready (albeit with lower priority) */
40 GNUNET_SCHEDULER_get_load (GNUNET_SCHEDULER_PRIORITY_COUNT));
41 GNUNET_assert (2 == *ok);
51 GNUNET_assert (3 == *ok);
61 const struct GNUNET_SCHEDULER_TaskContext *tc;
63 tc = GNUNET_SCHEDULER_get_task_context ();
64 GNUNET_assert (6 == *ok);
65 GNUNET_assert (GNUNET_NETWORK_fdset_handle_isset (tc->write_ready, fds[1]));
67 GNUNET_assert (1 == GNUNET_DISK_file_write (fds[1], &c, 1));
72 taskNeverRun (void *cls)
83 GNUNET_assert (8 == *ok);
93 const struct GNUNET_SCHEDULER_TaskContext *tc;
95 tc = GNUNET_SCHEDULER_get_task_context ();
96 GNUNET_assert (7 == *ok);
97 GNUNET_assert (GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, fds[0]));
98 GNUNET_assert (1 == GNUNET_DISK_file_read (fds[0], &c, 1));
100 GNUNET_SCHEDULER_add_shutdown (&taskLast,
102 GNUNET_SCHEDULER_shutdown ();
111 GNUNET_assert (4 == *ok);
113 p = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_NO);
114 GNUNET_assert (NULL != p);
115 fds[0] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_READ);
116 fds[1] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_WRITE);
117 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
121 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
133 GNUNET_assert (1 == *ok);
135 GNUNET_SCHEDULER_add_now (&task3, cls);
136 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI,
139 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
146 * Main method, starts scheduler with task1,
147 * checks that "ok" is correct at the end.
155 GNUNET_SCHEDULER_run (&task1, &ok);
161 taskShutdown (void *cls)
165 GNUNET_assert (1 == *ok);
167 GNUNET_SCHEDULER_add_shutdown (&taskLast, cls);
168 GNUNET_SCHEDULER_shutdown ();
173 * Main method, starts scheduler with task1,
174 * checks that "ok" is correct at the end.
182 GNUNET_SCHEDULER_run (&taskShutdown, &ok);
193 GNUNET_assert (1 == *ok);
195 GNUNET_SCHEDULER_add_shutdown (&taskLast, cls);
196 GNUNET_break (0 == PLIBC_KILL (getpid (),
202 * Main method, starts scheduler with task1,
203 * checks that "ok" is correct at the end.
211 GNUNET_SCHEDULER_run (&taskSig, &ok);
218 taskCancel (void *cls)
222 GNUNET_assert (1 == *ok);
224 GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_add_now (&taskNeverRun, NULL));
229 * Main method, starts scheduler with task1,
230 * checks that "ok" is correct at the end.
238 GNUNET_SCHEDULER_run (&taskCancel, &ok);
244 main (int argc, char *argv[])
248 GNUNET_log_setup ("test_scheduler", "WARNING", NULL);
251 ret += checkSignal ();
253 ret += checkShutdown ();
254 ret += checkCancel ();
255 GNUNET_DISK_pipe_close (p);
260 /* end of test_scheduler.c */