]>
Commit | Line | Data |
---|---|---|
9b0a0ba9 OZ |
1 | /* |
2 | * BIRD Library -- Event Processing Tests | |
3 | * | |
4 | * (c) 2015 CZ.NIC z.s.p.o. | |
5 | * | |
6 | * Can be freely distributed and used under the terms of the GNU GPL. | |
7 | */ | |
8 | ||
9 | ||
10 | #include "test/birdtest.h" | |
11 | ||
12 | #include "lib/net.h" | |
13 | #include "lib/event.h" | |
14 | #include "conf/conf.h" | |
15 | #include "nest/locks.h" | |
16 | #include "sysdep/unix/unix.h" | |
17 | #include "nest/iface.h" | |
18 | #include "nest/route.h" | |
19 | ||
20 | #define MAX_NUM 4 | |
21 | ||
22 | int event_check_points[MAX_NUM]; | |
23 | ||
24 | #define event_hook_body(num) \ | |
25 | do { \ | |
26 | bt_debug("Event Hook " #num "\n"); \ | |
27 | event_check_points[num] = 1; \ | |
28 | bt_assert_msg(event_check_points[num-1], "Events should be run in right order"); \ | |
29 | } while (0) | |
30 | ||
31 | static void event_hook_1(void *data UNUSED) { event_hook_body(1); } | |
32 | static void event_hook_2(void *data UNUSED) { event_hook_body(2); } | |
33 | static void event_hook_3(void *data UNUSED) { event_hook_body(3); } | |
34 | ||
35 | #define schedule_event(num) \ | |
36 | do { \ | |
37 | struct event *event_##num = ev_new(&root_pool); \ | |
38 | event_##num->hook = event_hook_##num; \ | |
39 | ev_schedule(event_##num); \ | |
40 | } while (0) | |
41 | ||
42 | static void | |
43 | init_event_check_points(void) | |
44 | { | |
45 | int i; | |
46 | event_check_points[0] = 1; | |
47 | for (i = 1; i < MAX_NUM; i++) | |
48 | event_check_points[i] = 0; | |
49 | } | |
50 | ||
51 | static int | |
52 | t_ev_run_list(void) | |
53 | { | |
54 | int i; | |
55 | ||
56 | resource_init(); | |
57 | olock_init(); | |
212eda07 | 58 | timer_init(); |
9b0a0ba9 OZ |
59 | io_init(); |
60 | rt_init(); | |
61 | if_init(); | |
62 | // roa_init(); | |
63 | config_init(); | |
64 | config = config_alloc(""); | |
65 | ||
66 | init_event_check_points(); | |
67 | ||
68 | schedule_event(1); | |
69 | schedule_event(2); | |
70 | schedule_event(3); | |
71 | ||
72 | ev_run_list(&global_event_list); | |
73 | ||
74 | for (i = 1; i < MAX_NUM; i++) | |
75 | bt_assert(event_check_points[i]); | |
76 | ||
5e3cd0e5 | 77 | return 1; |
9b0a0ba9 OZ |
78 | } |
79 | ||
80 | int | |
81 | main(int argc, char *argv[]) | |
82 | { | |
83 | bt_init(argc, argv); | |
84 | ||
85 | bt_test_suite(t_ev_run_list, "Schedule and run 3 events in right order."); | |
86 | ||
87 | return bt_exit_value(); | |
88 | } | |
89 |