[components][utest] 增加 utest 线程模式

Signed-off-by: MurphyZhao <d2014zjt@163.com>
This commit is contained in:
MurphyZhao 2019-02-13 09:37:26 +08:00
parent 821c81e21a
commit 82f022f6f0
2 changed files with 49 additions and 6 deletions

View File

@ -234,4 +234,13 @@ config RT_USING_UTEST
bool "Enable utest (RT-Thread test framework)" bool "Enable utest (RT-Thread test framework)"
default n default n
if RT_USING_UTEST
config UTEST_THR_STACK_SIZE
int "The utest thread stack size"
default 4096
config UTEST_THR_PRIORITY
int "The utest thread priority"
default 20
endif
endmenu endmenu

View File

@ -32,6 +32,18 @@
#error "RT_CONSOLEBUF_SIZE is less than 256!" #error "RT_CONSOLEBUF_SIZE is less than 256!"
#endif #endif
#ifdef UTEST_THR_STACK_SIZE
#define UTEST_THREAD_STACK_SIZE UTEST_THR_STACK_SIZE
#else
#define UTEST_THREAD_STACK_SIZE (4096)
#endif
#ifdef UTEST_THR_PRIORITY
#define UTEST_THREAD_PRIORITY UTEST_THR_PRIORITY
#else
#define UTEST_THREAD_PRIORITY FINSH_THREAD_PRIORITY
#endif
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;
@ -163,24 +175,46 @@ __tc_continue:
static void utest_testcase_run(int argc, char** argv) static void utest_testcase_run(int argc, char** argv)
{ {
char utest_name[UTEST_NAME_MAX_LEN]; void *thr_param = RT_NULL;
static char utest_name[UTEST_NAME_MAX_LEN];
rt_memset(utest_name, 0x0, sizeof(utest_name));
if (argc == 1) if (argc == 1)
{ {
utest_run(RT_NULL); utest_run(RT_NULL);
return;
} }
else if (argc == 2) else if (argc == 2 || argc == 3)
{ {
rt_memset(utest_name, 0x0, sizeof(utest_name)); if (rt_strcmp(argv[1], "-thread") == 0)
rt_strncpy(utest_name, argv[1], sizeof(utest_name) -1); {
utest_run(utest_name); rt_thread_t tid = RT_NULL;
if (argc == 3)
{
rt_strncpy(utest_name, argv[2], sizeof(utest_name) -1);
thr_param = (void*)utest_name;
}
tid = rt_thread_create("utest",
(void (*)(void *))utest_run, thr_param,
UTEST_THREAD_STACK_SIZE, UTEST_THREAD_PRIORITY, 10);
if (tid != NULL)
{
rt_thread_startup(tid);
}
}
else
{
rt_strncpy(utest_name, argv[1], sizeof(utest_name) -1);
utest_run(utest_name);
}
} }
else else
{ {
LOG_E("[ error ] at (%s:%d), in param error.", __func__, __LINE__); LOG_E("[ error ] at (%s:%d), in param error.", __func__, __LINE__);
} }
} }
MSH_CMD_EXPORT_ALIAS(utest_testcase_run, utest_run, utest_run [testcase name]); MSH_CMD_EXPORT_ALIAS(utest_testcase_run, utest_run, utest_run [-thread] [testcase name]);
utest_t utest_handle_get(void) utest_t utest_handle_get(void)
{ {