diff --git a/components/utilities/utest/utest.c b/components/utilities/utest/utest.c index 325823de8a5c6f4049accd525b4a34376f217262..7e25e2555e532edce52eeaad093f6a4b542cac03 100644 --- a/components/utilities/utest/utest.c +++ b/components/utilities/utest/utest.c @@ -46,12 +46,17 @@ static rt_uint8_t utest_log_lv = UTEST_LOG_ALL; static utest_tc_export_t tc_table = RT_NULL; static rt_size_t tc_num; static rt_uint32_t tc_loop; +static rt_uint8_t *tc_fail_list; static struct utest local_utest = {UTEST_PASSED, 0, 0}; #if defined(__ICCARM__) || defined(__ICCRX__) /* for IAR compiler */ #pragma section="UtestTcTab" #endif +#define TC_FAIL_LIST_SIZE (RT_ALIGN(tc_num, 8) / 8) +#define TC_FAIL_LIST_MARK_FAILED(index) (tc_fail_list[RT_ALIGN(index, 8) / 8] |= (1UL << (index % 8))) +#define TC_FAIL_LIST_IS_FAILED(index) (tc_fail_list[RT_ALIGN(index, 8) / 8] & (1UL << (index % 8))) + void utest_log_lv_set(rt_uint8_t lv) { if (lv == UTEST_LOG_ALL || lv == UTEST_LOG_ASSERT) @@ -78,6 +83,11 @@ int utest_init(void) tc_num = (utest_tc_export_t) &__rt_utest_tc_tab_end - tc_table; #endif + tc_fail_list = rt_malloc(TC_FAIL_LIST_SIZE); + if(!tc_fail_list) + { + LOG_E("no memory, tc_fail_list init failed!"); + } LOG_I("utest is initialize success."); LOG_I("total utest testcase num: (%d)", tc_num); return tc_num; @@ -147,6 +157,8 @@ static void utest_run(const char *utest_name) rt_size_t i; rt_uint32_t index; rt_bool_t is_find; + rt_uint32_t tc_fail_num = 0; + rt_uint32_t tc_run_num = 0; rt_thread_mdelay(1000); @@ -154,6 +166,14 @@ static void utest_run(const char *utest_name) { i = 0; is_find = RT_FALSE; + + tc_fail_num = 0; + tc_run_num = 0; + if (tc_fail_list) + { + memset(tc_fail_list, 0, TC_FAIL_LIST_SIZE); + } + LOG_I("[==========] [ utest ] loop %d/%d", index + 1, tc_loop); LOG_I("[==========] [ utest ] started"); while(i < tc_num) @@ -192,6 +212,8 @@ static void utest_run(const char *utest_name) } else { + TC_FAIL_LIST_MARK_FAILED(i); + tc_fail_num ++; LOG_E("[ FAILED ] [ result ] testcase (%s)", tc_table[i].name); } } @@ -212,6 +234,7 @@ static void utest_run(const char *utest_name) __tc_continue: LOG_I("[----------] [ testcase ] (%s) finished", tc_table[i].name); + tc_run_num ++; i++; } @@ -223,6 +246,20 @@ static void utest_run(const char *utest_name) } LOG_I("[==========] [ utest ] finished"); + LOG_I("[==========] [ utest ] %d tests from %d testcase ran.", tc_run_num, tc_num); + LOG_I("[ PASSED ] [ result ] %d tests.", tc_run_num - tc_fail_num); + + if(tc_fail_list && (tc_fail_num > 0)) + { + LOG_E("[ FAILED ] [ result ] %d tests, listed below:", tc_fail_num); + for(i = 0; i < tc_num; i ++) + { + if (TC_FAIL_LIST_IS_FAILED(i)) + { + LOG_E("[ FAILED ] [ result ] %s", tc_table[i].name); + } + } + } } }