[utest] feat: print progress on testing

This is required so the user will not be confused on waiting for test to complete.

Changes:

- notify user that the test is not corrupted
- expand waiting tick on timed mtx test, for compatibility on different hw.

Signed-off-by: Shell <smokewood@qq.com>
This commit is contained in:
Shell 2024-07-18 09:57:46 +00:00 committed by Rbb666
parent 79d14461bd
commit e726b93016
2 changed files with 24 additions and 3 deletions

View File

@ -197,7 +197,7 @@ static void timed_mtx_tc(void)
for (size_t i = 0; i < 2; i++) for (size_t i = 0; i < 2; i++)
{ {
uassert_int_equal( uassert_int_equal(
rt_sem_take(&_thr_exit_sem, 2 * TEST_LOOP_TICKS), rt_sem_take(&_thr_exit_sem, 4 * TEST_LOOP_TICKS),
RT_EOK); RT_EOK);
} }

View File

@ -22,6 +22,9 @@
} \ } \
} while (0) } while (0)
/* notify user that the test is not corrupted */
#define PRINT_PROGRESS(id) LOG_I("Testing on %d", id)
static rt_uint8_t timer_flag_oneshot[] = { static rt_uint8_t timer_flag_oneshot[] = {
RT_TIMER_FLAG_ONE_SHOT, RT_TIMER_FLAG_ONE_SHOT,
RT_TIMER_FLAG_ONE_SHOT | RT_TIMER_FLAG_HARD_TIMER, RT_TIMER_FLAG_ONE_SHOT | RT_TIMER_FLAG_HARD_TIMER,
@ -649,6 +652,8 @@ static void test_timer_stress(void)
{ {
rt_tick_t start; rt_tick_t start;
rt_ubase_t iters = 0; rt_ubase_t iters = 0;
rt_ubase_t cur_tick;
rt_ubase_t next_print_time;
LOG_I("timer stress test begin, it will take %d seconds", 3*TEST_TIME_S); LOG_I("timer stress test begin, it will take %d seconds", 3*TEST_TIME_S);
@ -665,8 +670,9 @@ static void test_timer_stress(void)
} }
start = rt_tick_get(); start = rt_tick_get();
cur_tick = rt_tick_get();
while (rt_tick_get() - start <= TEST_TIME_S * RT_TICK_PER_SECOND) next_print_time = cur_tick + RT_TICK_PER_SECOND;
while (cur_tick - start <= TEST_TIME_S * RT_TICK_PER_SECOND)
{ {
for (int j = 0; j < STRESS_TIMERS; j++) for (int j = 0; j < STRESS_TIMERS; j++)
{ {
@ -680,6 +686,12 @@ static void test_timer_stress(void)
} }
} }
iters ++; iters ++;
cur_tick = rt_tick_get();
if (cur_tick > next_print_time)
{
PRINT_PROGRESS(next_print_time);
next_print_time = cur_tick + RT_TICK_PER_SECOND;
}
} }
for (int j = 0; j < STRESS_TIMERS; j++) for (int j = 0; j < STRESS_TIMERS; j++)
@ -710,16 +722,25 @@ static rt_err_t utest_tc_cleanup(void)
static void testcase(void) static void testcase(void)
{ {
UTEST_UNIT_RUN(test_static_timer); UTEST_UNIT_RUN(test_static_timer);
PRINT_PROGRESS(__LINE__);
UTEST_UNIT_RUN(test_static_timer_control); UTEST_UNIT_RUN(test_static_timer_control);
PRINT_PROGRESS(__LINE__);
UTEST_UNIT_RUN(test_static_timer_start_twice); UTEST_UNIT_RUN(test_static_timer_start_twice);
PRINT_PROGRESS(__LINE__);
UTEST_UNIT_RUN(test_static_timer_op_in_callback); UTEST_UNIT_RUN(test_static_timer_op_in_callback);
PRINT_PROGRESS(__LINE__);
#ifdef RT_USING_HEAP #ifdef RT_USING_HEAP
UTEST_UNIT_RUN(test_dynamic_timer); UTEST_UNIT_RUN(test_dynamic_timer);
PRINT_PROGRESS(__LINE__);
UTEST_UNIT_RUN(test_dynamic_timer_control); UTEST_UNIT_RUN(test_dynamic_timer_control);
PRINT_PROGRESS(__LINE__);
UTEST_UNIT_RUN(test_dynamic_timer_start_twice); UTEST_UNIT_RUN(test_dynamic_timer_start_twice);
PRINT_PROGRESS(__LINE__);
UTEST_UNIT_RUN(test_dynamic_timer_op_in_callback); UTEST_UNIT_RUN(test_dynamic_timer_op_in_callback);
PRINT_PROGRESS(__LINE__);
#endif /* RT_USING_HEAP */ #endif /* RT_USING_HEAP */
UTEST_UNIT_RUN(test_timer_stress); UTEST_UNIT_RUN(test_timer_stress);
PRINT_PROGRESS(__LINE__);
} }
UTEST_TC_EXPORT(testcase, "testcases.kernel.timer_tc", utest_tc_init, utest_tc_cleanup, 1000); UTEST_TC_EXPORT(testcase, "testcases.kernel.timer_tc", utest_tc_init, utest_tc_cleanup, 1000);