From 4af99b0dca501cae50a11b233b8a2a507084a442 Mon Sep 17 00:00:00 2001 From: guozhanxin Date: Tue, 17 Aug 2021 21:26:11 +0800 Subject: [PATCH 1/2] [add] utest add fail_list. --- components/utilities/utest/utest.c | 37 ++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/components/utilities/utest/utest.c b/components/utilities/utest/utest.c index 325823de8a..7e25e2555e 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); + } + } + } } } From 38f5fec63ed420db514f415489b0516dd97a9ea9 Mon Sep 17 00:00:00 2001 From: guozhanxin Date: Thu, 19 Aug 2021 11:20:10 +0800 Subject: [PATCH 2/2] =?UTF-8?q?[utest]=20=E5=AE=8C=E5=96=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=EF=BC=8C=E6=B7=BB=E5=8A=A0=E5=AF=B9tc=5Fnum=E7=9A=84?= =?UTF-8?q?=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/utilities/utest/utest.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/components/utilities/utest/utest.c b/components/utilities/utest/utest.c index 7e25e2555e..937f156b85 100644 --- a/components/utilities/utest/utest.c +++ b/components/utilities/utest/utest.c @@ -83,13 +83,16 @@ 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); + if (tc_num > 0) + { + tc_fail_list = rt_malloc(TC_FAIL_LIST_SIZE); + if(!tc_fail_list) + { + LOG_E("no memory, tc_fail_list init failed!"); + } + } return tc_num; } INIT_COMPONENT_EXPORT(utest_init);