From a305c6cca93cb7c33cd522098163ae52d6964e90 Mon Sep 17 00:00:00 2001 From: MurphyZhao Date: Thu, 14 Feb 2019 15:23:07 +0800 Subject: [PATCH] =?UTF-8?q?[components][utest]=20utest=5Frun=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=20loop=20=E5=8A=9F=E8=83=BD=EF=BC=8C=E6=96=B9?= =?UTF-8?q?=E4=BE=BF=E6=8C=81=E7=BB=AD=E8=BF=90=E8=A1=8C=E5=8D=95=E4=B8=80?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B=EF=BC=9B?= =?UTF-8?q?=20[components][utest]=20utest=5Frun=20=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B=E5=90=8D=E5=AD=97=E7=9A=84?= =?UTF-8?q?=E6=97=B6=E5=80=99=EF=BC=8C=E5=A2=9E=E5=8A=A0=E9=80=9A=E9=85=8D?= =?UTF-8?q?=E7=AC=A6=20`*`=20=E7=9A=84=E6=94=AF=E6=8C=81=EF=BC=8C=E5=8F=8A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=85=E6=8C=87=E5=AE=9A=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=E5=90=8D=E5=AD=97=E7=9A=84=E5=89=8D=E9=83=A8?= =?UTF-8?q?=E5=88=86=E5=AD=97=E8=8A=82=E6=9D=A5=E8=BF=90=E8=A1=8C=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=94=A8=E4=BE=8B=E3=80=82=E8=AF=A5=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E4=BC=9A=E6=89=A7=E8=A1=8C=E5=8C=B9=E9=85=8D=E6=88=90=E5=8A=9F?= =?UTF-8?q?=E7=9A=84=E6=89=80=E6=9C=89=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MurphyZhao --- components/utilities/utest/utest.c | 97 ++++++++++++++++++------------ 1 file changed, 59 insertions(+), 38 deletions(-) diff --git a/components/utilities/utest/utest.c b/components/utilities/utest/utest.c index 8d89e3a2a0..13cb405550 100644 --- a/components/utilities/utest/utest.c +++ b/components/utilities/utest/utest.c @@ -10,6 +10,8 @@ #include #include +#include + #include "utest.h" #include @@ -47,6 +49,7 @@ 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 struct utest local_utest = {UTEST_PASSED, 0, 0}; #if defined(__ICCARM__) || defined(__ICCRX__) /* for IAR compiler */ @@ -118,61 +121,74 @@ static const char *file_basename(const char *file) static void utest_run(const char *utest_name) { - rt_size_t i = 0; + rt_size_t i; + rt_uint32_t index; rt_thread_mdelay(1000); - LOG_I("[==========] [ utest ] started"); - while(i < tc_num) + for (index = 0; index < tc_loop; index ++) { - if (utest_name && rt_strcmp(utest_name, tc_table[i].name)) + i = 0; + LOG_I("[==========] [ utest ] started"); + while(i < tc_num) { - i++; - continue; - } - - LOG_I("[----------] [ testcase ] (%s) started", tc_table[i].name); - if (tc_table[i].init != RT_NULL) - { - if (tc_table[i].init() != RT_EOK) + if (utest_name) { - LOG_E("[ FAILED ] [ result ] testcase (%s)", tc_table[i].name); - goto __tc_continue; + int len = strlen(utest_name); + if (utest_name[len - 1] == '*') + { + len -= 1; + } + if (rt_memcmp(tc_table[i].name, utest_name, len) != 0) + { + i++; + continue; + } } - } - if (tc_table[i].tc != RT_NULL) - { - tc_table[i].tc(); - if (local_utest.failed_num == 0) + LOG_I("[----------] [ testcase ] (%s) started", tc_table[i].name); + if (tc_table[i].init != RT_NULL) { - LOG_I("[ PASSED ] [ result ] testcase (%s)", tc_table[i].name); + if (tc_table[i].init() != RT_EOK) + { + LOG_E("[ FAILED ] [ result ] testcase (%s)", tc_table[i].name); + goto __tc_continue; + } + } + + if (tc_table[i].tc != RT_NULL) + { + tc_table[i].tc(); + if (local_utest.failed_num == 0) + { + LOG_I("[ PASSED ] [ result ] testcase (%s)", tc_table[i].name); + } + else + { + LOG_E("[ FAILED ] [ result ] testcase (%s)", tc_table[i].name); + } } else { LOG_E("[ FAILED ] [ result ] testcase (%s)", tc_table[i].name); } - } - else - { - LOG_E("[ FAILED ] [ result ] testcase (%s)", tc_table[i].name); - } - if (tc_table[i].cleanup != RT_NULL) - { - if (tc_table[i].cleanup() != RT_EOK) + if (tc_table[i].cleanup != RT_NULL) { - LOG_E("[ FAILED ] [ result ] testcase (%s)", tc_table[i].name); - goto __tc_continue; + if (tc_table[i].cleanup() != RT_EOK) + { + LOG_E("[ FAILED ] [ result ] testcase (%s)", tc_table[i].name); + goto __tc_continue; + } } + + __tc_continue: + LOG_I("[----------] [ testcase ] (%s) finished", tc_table[i].name); + + i++; } - -__tc_continue: - LOG_I("[----------] [ testcase ] (%s) finished", tc_table[i].name); - - i++; + LOG_I("[==========] [ utest ] finished"); } - LOG_I("[==========] [ utest ] finished"); } static void utest_testcase_run(int argc, char** argv) @@ -182,20 +198,24 @@ static void utest_testcase_run(int argc, char** argv) static char utest_name[UTEST_NAME_MAX_LEN]; rt_memset(utest_name, 0x0, sizeof(utest_name)); + tc_loop = 1; + if (argc == 1) { utest_run(RT_NULL); return; } - else if (argc == 2 || argc == 3) + else if (argc == 2 || argc == 3 || argc == 4) { if (rt_strcmp(argv[1], "-thread") == 0) { rt_thread_t tid = RT_NULL; - if (argc == 3) + if (argc == 3 || argc == 4) { rt_strncpy(utest_name, argv[2], sizeof(utest_name) -1); thr_param = (void*)utest_name; + + if (argc == 4) tc_loop = atoi(argv[3]); } tid = rt_thread_create("utest", (void (*)(void *))utest_run, thr_param, @@ -208,6 +228,7 @@ static void utest_testcase_run(int argc, char** argv) else { rt_strncpy(utest_name, argv[1], sizeof(utest_name) -1); + if (argc == 3) tc_loop = atoi(argv[2]); utest_run(utest_name); } }