mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
tests/event: add test for timeout_clear + cleanup
This commit is contained in:
parent
cef3d307c7
commit
6c55b36943
@ -31,6 +31,7 @@ static uint32_t before;
|
||||
static void callback(event_t *arg);
|
||||
static void custom_callback(event_t *event);
|
||||
static void timed_callback(void *arg);
|
||||
static void forbidden_callback(void *arg);
|
||||
|
||||
|
||||
static event_t event = { .handler = callback };
|
||||
@ -51,6 +52,7 @@ typedef struct {
|
||||
|
||||
static custom_event_t custom_event = { .super.handler = custom_callback, .text = "CUSTOM CALLBACK" };
|
||||
static event_callback_t event_callback = EVENT_CALLBACK_INIT(timed_callback, 0x12345678);
|
||||
static event_callback_t noevent_callback = EVENT_CALLBACK_INIT(forbidden_callback, 0);
|
||||
|
||||
static void custom_callback(event_t *event)
|
||||
{
|
||||
@ -72,6 +74,17 @@ static void timed_callback(void *arg)
|
||||
printf("[SUCCESS]\n");
|
||||
}
|
||||
|
||||
static void forbidden_callback(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
/* this callback should never be triggered! */
|
||||
puts("call to forbidden callback");
|
||||
puts("[FAILED]");
|
||||
while (1) {
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
puts("[START] event test application.\n");
|
||||
@ -95,6 +108,14 @@ int main(void)
|
||||
before = xtimer_now_usec();
|
||||
event_timeout_set(&event_timeout, 100000LU);
|
||||
|
||||
event_timeout_t event_timeout_canceled;
|
||||
|
||||
puts("posting timed callback with timeout 0.5sec and canceling it again");
|
||||
event_timeout_init(&event_timeout_canceled, &queue,
|
||||
(event_t *)&noevent_callback);
|
||||
event_timeout_set(&event_timeout_canceled, 500 * US_PER_MS);
|
||||
event_timeout_clear(&event_timeout_canceled);
|
||||
|
||||
printf("launching event queue\n");
|
||||
event_loop(&queue);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user