1 /* SilcSchedule tests */
3 #include "silcincludes.h"
5 typedef void (*Callback)(void *context);
9 #define NUM_FTASK FD_SETSIZE
14 SilcSchedule schedule;
16 SILC_TASK_CALLBACK(foo)
21 SILC_TASK_CALLBACK(cont)
25 SILC_LOG_DEBUG(("Adding %d fd tasks", NUM_FTASK - 10));
27 for (i = 0; i < NUM_FTASK - 10; i++)
28 silc_schedule_task_add_fd(schedule, i + 5, foo, (void *)(i + 5));
31 SILC_TASK_CALLBACK(timeout)
34 SILC_LOG_DEBUG(("Timeout task %d", i));
37 SILC_TASK_CALLBACK(start)
41 SILC_LOG_DEBUG(("Adding %d timeout tasks", NUM_TTASK));
43 for (i = 0; i < NUM_TTASK; i++)
44 silc_schedule_task_add_timeout(schedule, timeout, (void *)i,
45 0, (i * 720391) & 999999);
47 silc_schedule_task_add_timeout(schedule, cont, (void *)i, 0, 100);
50 int main(int argc, char **argv)
54 if (argc > 1 && !strcmp(argv[1], "-d")) {
57 silc_log_debug_hexdump(TRUE);
58 silc_log_set_debug_string("*sched*,*hash*");
61 SILC_LOG_DEBUG(("Allocating scheduler"));
62 schedule = silc_schedule_init(NUM_FTASK, NULL);
66 silc_schedule_task_add_timeout(schedule, start, NULL, 0, 1);
68 SILC_LOG_DEBUG(("Running scheduler"));
69 silc_schedule(schedule);
71 silc_schedule_uninit(schedule);
76 SILC_LOG_DEBUG(("Testing was %s", success ? "SUCCESS" : "FAILURE"));
77 fprintf(stderr, "Testing was %s\n", success ? "SUCCESS" : "FAILURE");