#include <sys/signalfd.h>
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <fcntl.h>
#include <cmocka.h>
#include <amxc/amxc.h>
#include <amxc/amxc_timestamp.h>
#include <amxp/amxp_timer.h>
#include "test_timer.h"
#include <amxc/amxc_macros.h>
Go to the source code of this file.
◆ read_sigalrm()
static void read_sigalrm |
( |
void |
| ) |
|
|
static |
Definition at line 96 of file test_timer.c.
99 struct signalfd_siginfo fdsi;
103 sigaddset(&
mask, SIGALRM);
105 sigprocmask(SIG_BLOCK, &
mask, NULL);
107 sfd = signalfd(-1, &
mask, 0);
108 s = read(sfd, &fdsi,
sizeof(
struct signalfd_siginfo));
109 assert_int_equal(s,
sizeof(
struct signalfd_siginfo));
110 if(fdsi.ssi_signo == SIGALRM) {
111 printf(
"Got SIGALRM\n");
113 printf(
"Read unexpected signal\n");
◆ test_can_create_timer()
void test_can_create_timer |
( |
UNUSED void ** |
state | ) |
|
Definition at line 117 of file test_timer.c.
124 assert_ptr_not_equal(timer, NULL);
126 assert_ptr_equal(timer->
cb, NULL);
127 assert_ptr_equal(timer->
priv, NULL);
132 assert_ptr_equal(timer, NULL);
void amxp_timer_delete(amxp_timer_t **timer)
Deletes a timer.
int amxp_timer_new(amxp_timer_t **timer, amxp_timer_cb_t cb, void *priv)
Allocate and initializes a new timer.
◆ test_can_restart_timer()
void test_can_restart_timer |
( |
UNUSED void ** |
state | ) |
|
Definition at line 248 of file test_timer.c.
249 amxc_ts_t start_time;
256 amxc_ts_now(&start_time);
259 amxc_ts_now(&end_time);
260 assert_int_equal(end_time.sec - start_time.sec, 3);
int amxp_timer_start(amxp_timer_t *timer, unsigned int timeout_msec)
Starts or resets a timer.
static void read_sigalrm(void)
◆ test_can_start_interval_timer()
void test_can_start_interval_timer |
( |
UNUSED void ** |
state | ) |
|
Definition at line 201 of file test_timer.c.
208 assert_ptr_not_equal(timer1, NULL);
210 assert_ptr_not_equal(timer2, NULL);
230 assert_true((remaining / 1000) <= (
count - 1));
234 assert_int_equal(
count, 0);
unsigned int amxp_timer_remaining_time(amxp_timer_t *timer)
Get the remaining time of the timer.
amxp_timer_state_t amxp_timer_get_state(amxp_timer_t *timer)
Get the timer's state.
void amxp_timers_check(void)
Check all timers and call the callback function when the timer is in Timer expired state.
int amxp_timer_stop(amxp_timer_t *timer)
Stops the timer.
void amxp_timers_calculate(void)
Caclulates the remaining time of all timers.
int amxp_timer_set_interval(amxp_timer_t *timer, unsigned int msec)
Sets the interval of a timer in milli seconds.
◆ test_can_start_timers()
void test_can_start_timers |
( |
UNUSED void ** |
state | ) |
|
Definition at line 136 of file test_timer.c.
143 assert_ptr_not_equal(timer1, NULL);
145 assert_ptr_not_equal(timer2, NULL);
163 assert_int_equal(ts2.sec - ts1.sec, 1);
171 assert_int_equal(ts2.sec - ts1.sec, 3);
◆ test_timer_callback_is_called()
void test_timer_callback_is_called |
( |
UNUSED void ** |
state | ) |
|
Definition at line 181 of file test_timer.c.
185 assert_ptr_not_equal(timer1, NULL);
static void timer_callback(amxp_timer_t *timer, void *priv)
◆ test_timer_can_delete_add_timers_in_callback()
void test_timer_can_delete_add_timers_in_callback |
( |
UNUSED void ** |
state | ) |
|
Definition at line 338 of file test_timer.c.
static void timer_delete_add_timers_cb(UNUSED amxp_timer_t *timer, UNUSED void *priv)
◆ test_timer_can_delete_timers_in_callback()
void test_timer_can_delete_timers_in_callback |
( |
UNUSED void ** |
state | ) |
|
Definition at line 323 of file test_timer.c.
static void timer_delete_timers_cb(UNUSED amxp_timer_t *timer, UNUSED void *priv)
◆ test_timer_with_0_timeout_test1()
void test_timer_with_0_timeout_test1 |
( |
UNUSED void ** |
state | ) |
|
Definition at line 265 of file test_timer.c.
266 amxc_ts_t start_time;
281 amxc_ts_now(&start_time);
283 amxc_ts_now(&end_time);
288 assert_int_equal(end_time.sec - start_time.sec, 0);
◆ test_timer_with_0_timeout_test2()
void test_timer_with_0_timeout_test2 |
( |
UNUSED void ** |
state | ) |
|
Definition at line 294 of file test_timer.c.
295 amxc_ts_t start_time;
310 amxc_ts_now(&start_time);
312 amxc_ts_now(&end_time);
317 assert_int_equal(end_time.sec - start_time.sec, 0);
◆ timer_callback()
static void timer_callback |
( |
amxp_timer_t * |
timer, |
|
|
void * |
priv |
|
) |
| |
|
static |
Definition at line 89 of file test_timer.c.
90 check_expected(timer);
93 assert_ptr_not_equal(timer, NULL);
◆ timer_delete_add_timers_cb()
◆ timer_delete_timers_cb()
◆ t1
◆ t2