mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-12-24 10:41:54 +00:00
94eb0858c2
There is a simple universal IO loop, taking care of events, timers and sockets. Primarily, one instance of a protocol should use exactly one IO loop to do all its work, as is now done in BFD. Contrary to previous versions, the loop is now launched and cleaned by the nest/proto.c code, allowing for a protocol to just request its own loop by setting the loop's lock order in config higher than the_bird. It is not supported nor checked if any protocol changed the requested lock order in reconfigure. No protocol should do it at all.
95 lines
1.8 KiB
C
95 lines
1.8 KiB
C
/*
|
|
* BIRD Library -- Event Processing Tests
|
|
*
|
|
* (c) 2015 CZ.NIC z.s.p.o.
|
|
*
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
*/
|
|
|
|
|
|
#include "test/birdtest.h"
|
|
|
|
#include "lib/net.h"
|
|
#include "lib/event.h"
|
|
#include "conf/conf.h"
|
|
#include "nest/locks.h"
|
|
#include "sysdep/unix/unix.h"
|
|
#include "nest/iface.h"
|
|
#include "nest/route.h"
|
|
|
|
#define MAX_NUM 4
|
|
|
|
int event_check_points[MAX_NUM];
|
|
|
|
#define event_hook_body(num) \
|
|
do { \
|
|
bt_debug("Event Hook " #num "\n"); \
|
|
event_check_points[num] = 1; \
|
|
bt_assert_msg(event_check_points[num-1], "Events should be run in right order"); \
|
|
} while (0)
|
|
|
|
static void event_hook_1(void *data UNUSED) { event_hook_body(1); }
|
|
static void event_hook_2(void *data UNUSED) { event_hook_body(2); }
|
|
static void event_hook_3(void *data UNUSED) { event_hook_body(3); }
|
|
|
|
#define schedule_event(num) \
|
|
do { \
|
|
struct event *event_##num = ev_new(&root_pool); \
|
|
event_##num->hook = event_hook_##num; \
|
|
ev_schedule(event_##num); \
|
|
} while (0)
|
|
|
|
static void
|
|
init_event_check_points(void)
|
|
{
|
|
int i;
|
|
event_check_points[0] = 1;
|
|
for (i = 1; i < MAX_NUM; i++)
|
|
event_check_points[i] = 0;
|
|
}
|
|
|
|
void resource_sys_init(void);
|
|
|
|
static int
|
|
t_ev_run_list(void)
|
|
{
|
|
int i;
|
|
|
|
resource_sys_init();
|
|
resource_init();
|
|
olock_init();
|
|
birdloop_init();
|
|
io_init();
|
|
rt_init();
|
|
if_init();
|
|
// roa_init();
|
|
config_init();
|
|
config = config_alloc("");
|
|
|
|
init_event_check_points();
|
|
|
|
schedule_event(1);
|
|
schedule_event(2);
|
|
schedule_event(3);
|
|
|
|
ev_run_list(&global_event_list);
|
|
|
|
for (i = 1; i < MAX_NUM; i++)
|
|
bt_assert(event_check_points[i]);
|
|
|
|
return 1;
|
|
}
|
|
|
|
int
|
|
main(int argc, char *argv[])
|
|
{
|
|
bt_init(argc, argv);
|
|
|
|
the_bird_lock();
|
|
bt_test_suite(t_ev_run_list, "Schedule and run 3 events in right order.");
|
|
the_bird_unlock();
|
|
|
|
return bt_exit_value();
|
|
}
|
|
|