summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorMurphyZhao <[email protected]>2019-02-14 15:23:07 +0800
committerMurphyZhao <[email protected]>2019-02-14 15:28:56 +0800
commita305c6cca93cb7c33cd522098163ae52d6964e90 (patch)
treec69df28913ac4dc7145f51a5ded69187c0e5d9dc /components
parent0dc7b9a5a26030a945723569c64f5be46bd70ae1 (diff)
[components][utest] utest_run 增加 loop 功能,方便持续运行单一一个测试用例;
[components][utest] utest_run 指定测试用例名字的时候,增加通配符 `*` 的支持,及支持仅指定测试用例名字的前部分字节来运行测试用例。该功能会执行匹配成功的所有测试用例。 Signed-off-by: MurphyZhao <[email protected]>
Diffstat (limited to 'components')
-rw-r--r--components/utilities/utest/utest.c93
1 files changed, 57 insertions, 36 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 <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,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;
- }
+ 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)
- {
- if (tc_table[i].init() != RT_EOK)
+ LOG_I("[----------] [ testcase ] (%s) started", tc_table[i].name);
+ if (tc_table[i].init != RT_NULL)
{
- LOG_E("[ FAILED ] [ result ] testcase (%s)", tc_table[i].name);
- goto __tc_continue;
+ 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)
+ if (tc_table[i].tc != RT_NULL)
{
- LOG_I("[ PASSED ] [ result ] testcase (%s)", tc_table[i].name);
+ 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);
+ __tc_continue:
+ 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)
@@ -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);
}
}