]>
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(); | |
58 | io_init(); | |
59 | rt_init(); | |
60 | if_init(); | |
61 | // roa_init(); | |
62 | config_init(); | |
63 | config = config_alloc(""); | |
64 | ||
65 | init_event_check_points(); | |
66 | ||
67 | schedule_event(1); | |
68 | schedule_event(2); | |
69 | schedule_event(3); | |
70 | ||
71 | ev_run_list(&global_event_list); | |
72 | ||
73 | for (i = 1; i < MAX_NUM; i++) | |
74 | bt_assert(event_check_points[i]); | |
75 | ||
76 | return BT_SUCCESS; | |
77 | } | |
78 | ||
79 | int | |
80 | main(int argc, char *argv[]) | |
81 | { | |
82 | bt_init(argc, argv); | |
83 | ||
84 | bt_test_suite(t_ev_run_list, "Schedule and run 3 events in right order."); | |
85 | ||
86 | return bt_exit_value(); | |
87 | } | |
88 |