[components][utest] utest_run 增加 loop 功能,方便持续运行单一一个测试用例;

[components][utest] utest_run 指定测试用例名字的时候,增加通配符 `*` 的支持,及支持仅指定测试用例名字的前部分字节来运行测试用例。该功能会执行匹配成功的所有测试用例。

Signed-off-by: MurphyZhao <d2014zjt@163.com>
This commit is contained in:
MurphyZhao 2019-02-14 15:23:07 +08:00
parent 0dc7b9a5a2
commit a305c6cca9
1 changed files with 59 additions and 38 deletions

View File

@ -10,6 +10,8 @@
#include <rtthread.h> #include <rtthread.h>
#include <string.h> #include <string.h>
#include <stdlib.h>
#include "utest.h" #include "utest.h"
#include <utest_log.h> #include <utest_log.h>
@ -47,6 +49,7 @@
static rt_uint8_t utest_log_lv = UTEST_LOG_ALL; static rt_uint8_t utest_log_lv = UTEST_LOG_ALL;
static utest_tc_export_t tc_table = RT_NULL; static utest_tc_export_t tc_table = RT_NULL;
static rt_size_t tc_num; static rt_size_t tc_num;
static rt_uint32_t tc_loop;
static struct utest local_utest = {UTEST_PASSED, 0, 0}; static struct utest local_utest = {UTEST_PASSED, 0, 0};
#if defined(__ICCARM__) || defined(__ICCRX__) /* for IAR compiler */ #if defined(__ICCARM__) || defined(__ICCRX__) /* for IAR compiler */
@ -118,18 +121,30 @@ static const char *file_basename(const char *file)
static void utest_run(const char *utest_name) 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); rt_thread_mdelay(1000);
for (index = 0; index < tc_loop; index ++)
{
i = 0;
LOG_I("[==========] [ utest ] started"); LOG_I("[==========] [ utest ] started");
while(i < tc_num) while(i < tc_num)
{ {
if (utest_name && rt_strcmp(utest_name, tc_table[i].name)) if (utest_name)
{
int len = strlen(utest_name);
if (utest_name[len - 1] == '*')
{
len -= 1;
}
if (rt_memcmp(tc_table[i].name, utest_name, len) != 0)
{ {
i++; i++;
continue; continue;
} }
}
LOG_I("[----------] [ testcase ] (%s) started", tc_table[i].name); LOG_I("[----------] [ testcase ] (%s) started", tc_table[i].name);
if (tc_table[i].init != RT_NULL) if (tc_table[i].init != RT_NULL)
@ -167,12 +182,13 @@ static void utest_run(const char *utest_name)
} }
} }
__tc_continue: __tc_continue:
LOG_I("[----------] [ testcase ] (%s) finished", tc_table[i].name); LOG_I("[----------] [ testcase ] (%s) finished", tc_table[i].name);
i++; i++;
} }
LOG_I("[==========] [ utest ] finished"); LOG_I("[==========] [ utest ] finished");
}
} }
static void utest_testcase_run(int argc, char** argv) 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]; static char utest_name[UTEST_NAME_MAX_LEN];
rt_memset(utest_name, 0x0, sizeof(utest_name)); rt_memset(utest_name, 0x0, sizeof(utest_name));
tc_loop = 1;
if (argc == 1) if (argc == 1)
{ {
utest_run(RT_NULL); utest_run(RT_NULL);
return; return;
} }
else if (argc == 2 || argc == 3) else if (argc == 2 || argc == 3 || argc == 4)
{ {
if (rt_strcmp(argv[1], "-thread") == 0) if (rt_strcmp(argv[1], "-thread") == 0)
{ {
rt_thread_t tid = RT_NULL; rt_thread_t tid = RT_NULL;
if (argc == 3) if (argc == 3 || argc == 4)
{ {
rt_strncpy(utest_name, argv[2], sizeof(utest_name) -1); rt_strncpy(utest_name, argv[2], sizeof(utest_name) -1);
thr_param = (void*)utest_name; thr_param = (void*)utest_name;
if (argc == 4) tc_loop = atoi(argv[3]);
} }
tid = rt_thread_create("utest", tid = rt_thread_create("utest",
(void (*)(void *))utest_run, thr_param, (void (*)(void *))utest_run, thr_param,
@ -208,6 +228,7 @@ static void utest_testcase_run(int argc, char** argv)
else else
{ {
rt_strncpy(utest_name, argv[1], sizeof(utest_name) -1); rt_strncpy(utest_name, argv[1], sizeof(utest_name) -1);
if (argc == 3) tc_loop = atoi(argv[2]);
utest_run(utest_name); utest_run(utest_name);
} }
} }