60 #include <sys/types.h>
64 #include <event2/event.h>
80 int __wrap_event_new(
struct event_base*
base, evutil_socket_t fd,
short events, event_callback_fn callback,
void* callback_arg);
81 int __real_event_new(
struct event_base*
base, evutil_socket_t fd,
short events, event_callback_fn callback,
void* callback_arg);
86 int call = (int) mock();
95 int call = (int) mock();
103 int call = (int) mock();
106 }
else if(call > 0) {
107 amxc_llist_it_t* it = amxc_llist_get_at(&
functions, call - 1);
120 int __wrap_event_new(
struct event_base*
base, evutil_socket_t fd,
short events, event_callback_fn callback,
void* callback_arg) {
121 int call = (int) mock();
156 int* counter = (
int*) priv;
162 UNUSED
const amxc_var_t*
const data,
164 int* counter = (
int*) priv;
166 printf(
"AMXP-TEST-SIGNAL OK\n");
172 amxp_timer_t* timer = NULL;
180 amxp_sigmngr_add_signal(NULL,
"AMXP-TEST-SIGNAL");
181 amxp_slot_connect(NULL,
"AMXP-TEST-SIGNAL", NULL,
test_amxp_signal, &counter);
182 amxp_sigmngr_emit_signal(NULL,
"AMXP-TEST-SIGNAL", NULL);
185 amxp_timer_start(timer, 1000);
187 printf(
"Create eventloop\n");
190 printf(
"Start eventloop\n");
193 printf(
"eventloop stopped - because of AMXP-TEST-SIGNAL\n");
195 assert_int_equal(counter, 1);
196 printf(
"Start eventloop\n");
199 printf(
"eventloop stopped - because of timer\n");
201 assert_int_equal(counter, 2);
204 amxp_timer_delete(&timer);
210 printf(
"Read from file descriptor (%d)\n", fd);
215 printf(
"Buffer = %s\n", buf);
223 int* fd = (
int*) priv;
225 printf(
"Adding file descriptor (%d) to eventloop\n", *fd);
228 amxp_connection_add(*fd,
test_reader,
"test://127.0.0.1:5001", AMXO_CUSTOM, NULL);
232 int* fd = (
int*) priv;
234 printf(
"Write byte to file descriptor (%d)\n", *fd);
241 amxp_timer_t* timer = NULL;
242 amxp_timer_t* timer_write = NULL;
244 int retval = pipe(data_pipe);
245 assert_int_equal(retval, 0);
252 amxp_sigmngr_add_signal(NULL,
"connection-added");
253 amxp_sigmngr_add_signal(NULL,
"connection-deleted");
256 amxp_timer_start(timer, 1000);
259 amxp_timer_set_interval(timer_write, 2000);
260 amxp_timer_start(timer_write, 1000);
270 amxp_timer_delete(&timer);
271 amxp_timer_delete(&timer_write);
273 amxp_connection_remove(data_pipe[0]);
274 amxp_connection_remove(data_pipe[1]);
281 amxp_timer_t* timer_write = NULL;
283 int retval = pipe(data_pipe);
284 assert_int_equal(retval, 0);
291 amxp_sigmngr_add_signal(NULL,
"connection-added");
292 amxp_sigmngr_add_signal(NULL,
"connection-deleted");
297 amxp_timer_set_interval(timer_write, 2000);
298 amxp_timer_start(timer_write, 1000);
300 printf(
"Adding connection\n");
301 amxp_connection_add(data_pipe[0],
test_reader,
"test://127.0.0.1:5001", AMXO_CUSTOM, NULL);
310 amxp_timer_delete(&timer_write);
312 amxp_connection_remove(data_pipe[0]);
313 amxp_connection_remove(data_pipe[1]);
320 printf(
"READY_WRITE: Write byte to file descriptor (%d)\n", fd);
327 int* fd = (
int*) priv;
330 printf(
"Adding wait for write descriptor (%d) to eventloop\n", *fd);
332 assert_non_null(con->el_data);
339 int retval = pipe(data_pipe);
340 assert_int_equal(retval, 0);
341 amxp_timer_t* timer = NULL;
348 amxp_sigmngr_add_signal(NULL,
"connection-wait-write");
350 amxp_connection_add(data_pipe[0],
test_reader,
"test://127.0.0.1:5001", AMXO_CUSTOM, NULL);
351 amxp_connection_add(data_pipe[1],
test_reader,
"test://127.0.0.1:5001", AMXO_CUSTOM, NULL);
354 amxp_timer_start(timer, 1000);
364 amxp_connection_remove(data_pipe[0]);
365 amxp_connection_remove(data_pipe[1]);
372 int* fd = (
int*) priv;
374 printf(
"Adding file descriptor (%d) to eventloop\n", *fd);
377 amxp_connection_remove(*fd);
382 amxp_timer_t* timer = NULL;
384 int retval = pipe(data_pipe);
385 assert_int_equal(retval, 0);
392 amxp_sigmngr_add_signal(NULL,
"connection-added");
393 amxp_sigmngr_add_signal(NULL,
"connection-deleted");
396 amxp_timer_start(timer, 1000);
398 amxp_connection_add(data_pipe[0],
test_reader,
"test://127.0.0.1:5001", AMXO_CUSTOM, NULL);
408 amxp_timer_delete(&timer);
419 amxp_timer_t* timer = NULL;
423 amxp_timer_start(timer, 1000);
static struct event_base * base
PRIVATE amxp_connection_t * amxrt_el_get_connection(amxc_llist_t *cons, int fd)
int amxrt_el_destroy(void)
Cleans-up the event loop components.
int amxrt_el_start(void)
Starts the event loop.
int amxrt_el_stop(void)
Stops the event loop.
int amxrt_el_create(void)
Creates and initializes all needed event loop components.
int amxrt_run(void)
Starts the event loop.
amxd_dm_t * amxrt_get_dm(void)
Gets the runtime data model storage.
static void test_reader(int fd, UNUSED void *priv)
int test_amxrt_el_setup(UNUSED void **state)
static void test_add_fd(UNUSED amxp_timer_t *timer, void *priv)
void test_can_add_fds_before_el_start(UNUSED void **state)
void test_runtime_run_creates_el(UNUSED void **state)
void test_eventloop_event_base_new_fails(UNUSED void **state)
static void test_add_wait_for_write(UNUSED amxp_timer_t *timer, void *priv)
void test_eventloop_cbs(UNUSED void **state)
static void test_remove_fd(UNUSED amxp_timer_t *timer, void *priv)
static amxc_llist_t functions
int test_amxrt_el_teardown(UNUSED void **state)
static void test_stop_eventloop(UNUSED amxp_timer_t *timer, void *priv)
static void remove_cb_fns(amxc_llist_it_t *it)
static void test_write_fd(UNUSED amxp_timer_t *timer, void *priv)
void test_eventloop_is_working(UNUSED void **state)
static void test_amxp_signal(UNUSED const char *const sig_name, UNUSED const amxc_var_t *const data, void *const priv)
int __real_event_add(struct event *ev, const struct timeval *timeout)
int __wrap_event_add(struct event *ev, const struct timeval *timeout)
struct event_base * __wrap_event_base_new(void)
void test_can_wait_ready_write(UNUSED void **state)
void test_can_destroy_el_without_create(UNUSED void **state)
static void test_ready_write(int fd, UNUSED void *priv)
int __real_event_base_dispatch(struct event_base *base)
void test_can_add_fds(UNUSED void **state)
int __wrap_event_new(struct event_base *base, evutil_socket_t fd, short events, event_callback_fn callback, void *callback_arg)
struct _event_cb_fns event_cb_fns_t
struct event_base * __real_event_base_new(void)
int __real_event_new(struct event_base *base, evutil_socket_t fd, short events, event_callback_fn callback, void *callback_arg)
void test_can_remove_fds(UNUSED void **state)
int __wrap_event_base_dispatch(struct event_base *base)