MCPcopy Index your code
hub / github.com/RT-Thread/rt-thread / test_dynamic_timer

Function test_dynamic_timer

src/utest/timer_tc.c:407–471  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

405#ifdef RT_USING_HEAP
406
407static void test_dynamic_timer(void)
408{
409 rt_err_t result;
410
411 timer.callbacks = 0;
412 timer.is_static = RT_FALSE;
413
414 /* one shot timer test */
415 for (int time_out = 1; time_out < 10; time_out++)
416 {
417 for (int i = 0; i < sizeof(timer_flag_oneshot); i++)
418 {
419 timer.dynamic_timer = rt_timer_create("dynamic_timer",
420 timer_oneshot,
421 &timer,
422 time_out,
423 timer_flag_oneshot[i]);
424
425 /* calc expect tick */
426 timer.expect_tick = rt_tick_get() + time_out;
427
428 /* start timer */
429 result = rt_timer_start(timer.dynamic_timer);
430 uassert_true(result == RT_EOK);
431
432 /* wait for timerout */
433 rt_thread_delay(3 * time_out + 1);
434 uassert_true(timer.callbacks == 1);
435
436 /* detach timer */
437 result = rt_timer_delete(timer.dynamic_timer);
438 uassert_true(result == RT_EOK);
439 timer.callbacks = 0;
440 }
441 }
442
443 /* periodic timer test */
444 for (int time_out = 1; time_out < 10; time_out++)
445 {
446 for (int i = 0; i < sizeof(timer_flag_periodic); i++)
447 {
448 timer.dynamic_timer = rt_timer_create("dynamic_timer",
449 timer_periodic,
450 &timer,
451 time_out,
452 timer_flag_periodic[i]);
453
454 /* calc expect tick */
455 timer.expect_tick = rt_tick_get() + time_out;
456
457 /* start timer */
458 result = rt_timer_start(timer.dynamic_timer);
459 uassert_true(result == RT_EOK);
460
461 /* wait for timerout */
462 rt_thread_delay(5 * time_out + 1);
463 uassert_true(timer.callbacks >= 5);
464

Callers

nothing calls this directly

Calls 5

rt_timer_createFunction · 0.85
rt_tick_getFunction · 0.85
rt_timer_startFunction · 0.85
rt_thread_delayFunction · 0.85
rt_timer_deleteFunction · 0.85

Tested by

no test coverage detected