提交 a305c6cc 编写于 作者: M MurphyZhao

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

[components][utest] utest_run 指定测试用例名字的时候,增加通配符 `*` 的支持,及支持仅指定测试用例名字的前部分字节来运行测试用例。该功能会执行匹配成功的所有测试用例。
Signed-off-by: NMurphyZhao <d2014zjt@163.com>
上级 0dc7b9a5
......@@ -10,6 +10,8 @@
#include <rtthread.h>
#include <string.h>
#include <stdlib.h>
#include "utest.h"
#include <utest_log.h>
......@@ -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,18 +121,30 @@ 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);
for (index = 0; index < tc_loop; index ++)
{
i = 0;
LOG_I("[==========] [ utest ] started");
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++;
continue;
}
}
LOG_I("[----------] [ testcase ] (%s) started", tc_table[i].name);
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);
i++;
}
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);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册