From 82f022f6f0e975243e25888c5ba8b5dfb37fd4f6 Mon Sep 17 00:00:00 2001 From: MurphyZhao Date: Wed, 13 Feb 2019 09:37:26 +0800 Subject: [PATCH] =?UTF-8?q?[components][utest]=20=E5=A2=9E=E5=8A=A0=20utes?= =?UTF-8?q?t=20=E7=BA=BF=E7=A8=8B=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MurphyZhao --- components/utilities/Kconfig | 9 ++++++ components/utilities/utest/utest.c | 46 ++++++++++++++++++++++++++---- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/components/utilities/Kconfig b/components/utilities/Kconfig index 8e43cfa0a0..1175006a58 100644 --- a/components/utilities/Kconfig +++ b/components/utilities/Kconfig @@ -234,4 +234,13 @@ config RT_USING_UTEST bool "Enable utest (RT-Thread test framework)" 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 diff --git a/components/utilities/utest/utest.c b/components/utilities/utest/utest.c index a0a42d7438..ee9710c0df 100644 --- a/components/utilities/utest/utest.c +++ b/components/utilities/utest/utest.c @@ -32,6 +32,18 @@ #error "RT_CONSOLEBUF_SIZE is less than 256!" #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 utest_tc_export_t tc_table = RT_NULL; static rt_size_t tc_num; @@ -163,24 +175,46 @@ __tc_continue: 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) { utest_run(RT_NULL); + return; } - else if (argc == 2) + else if (argc == 2 || argc == 3) { - rt_memset(utest_name, 0x0, sizeof(utest_name)); - rt_strncpy(utest_name, argv[1], sizeof(utest_name) -1); - utest_run(utest_name); + if (rt_strcmp(argv[1], "-thread") == 0) + { + 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 { 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) {