|
|
|
@ -37,16 +37,19 @@ int timers2_test()
|
|
|
|
|
timers2 timers;
|
|
|
|
|
uint32_t dur = 5;
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
timers2::unique_timer t = timers.get_unique_timer();
|
|
|
|
|
TESTASSERT(not t.is_running() and not t.is_expired())
|
|
|
|
|
TESTASSERT(t.id() == 0)
|
|
|
|
|
timers2::unique_timer t2 = timers.get_unique_timer();
|
|
|
|
|
TESTASSERT(not t2.is_running() and not t2.is_expired())
|
|
|
|
|
TESTASSERT(t2.id() == 1)
|
|
|
|
|
TESTASSERT(timers.nof_timers() == 2)
|
|
|
|
|
|
|
|
|
|
// TEST: Run multiple times with the same duration
|
|
|
|
|
bool callback_called = false;
|
|
|
|
|
t.set(dur, [&callback_called](int) { callback_called = true; });
|
|
|
|
|
TESTASSERT(timers.get_cur_time() == 0)
|
|
|
|
|
for (uint32_t runs = 0; runs < 3; ++runs) {
|
|
|
|
|
callback_called = false;
|
|
|
|
|
TESTASSERT(not t.is_running())
|
|
|
|
@ -60,6 +63,7 @@ int timers2_test()
|
|
|
|
|
TESTASSERT(not t.is_running() and t.is_expired())
|
|
|
|
|
TESTASSERT(callback_called)
|
|
|
|
|
}
|
|
|
|
|
TESTASSERT(timers.get_cur_time() == 3 * (1 + dur))
|
|
|
|
|
|
|
|
|
|
// TEST: interrupt a timer. check if callback was called
|
|
|
|
|
callback_called = false;
|
|
|
|
@ -116,6 +120,9 @@ int timers2_test()
|
|
|
|
|
TESTASSERT(first_id == 1)
|
|
|
|
|
printf("Last timer id=%d\n", last_id);
|
|
|
|
|
TESTASSERT(last_id == 2)
|
|
|
|
|
}
|
|
|
|
|
// TEST: timer dtor is called and removes "timer" from "timers"
|
|
|
|
|
TESTASSERT(timers.nof_timers() == 0)
|
|
|
|
|
|
|
|
|
|
printf("Success\n");
|
|
|
|
|
|
|
|
|
|