From 8afadda165e5cb6e67239ea2fba1827f02e90a90 Mon Sep 17 00:00:00 2001 From: Shell Date: Wed, 12 Jun 2024 11:16:18 +0800 Subject: [PATCH 1/2] [utest] remove delay for on thread testing The delay is introduced from 0dc7b9a5a26030a945723569c64f5be46bd70ae1. Though this is unnecessary for on sync utest. So this is removed by a new entry and delay for asynchronous utest only. Signed-off-by: Shell --- components/utilities/utest/utest.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/components/utilities/utest/utest.c b/components/utilities/utest/utest.c index 6b480dd1e10..afc0205d0d2 100644 --- a/components/utilities/utest/utest.c +++ b/components/utilities/utest/utest.c @@ -131,7 +131,7 @@ int utest_init(void) } INIT_COMPONENT_EXPORT(utest_init); -static void utest_tc_list(void) +static long utest_tc_list(void) { rt_size_t i = 0; @@ -141,6 +141,8 @@ static void utest_tc_list(void) { LOG_I("[testcase name]:%s; [run timeout]:%d", tc_table[i].name, tc_table[i].run_timeout); } + + return 0; } MSH_CMD_EXPORT_ALIAS(utest_tc_list, utest_list, output all utest testcase); @@ -197,8 +199,6 @@ static void utest_run(const char *utest_name) rt_uint32_t tc_fail_num = 0; rt_uint32_t tc_run_num = 0; - rt_thread_mdelay(1000); - for (index = 0; index < tc_loop; index ++) { i = 0; @@ -300,9 +300,16 @@ static void utest_run(const char *utest_name) } } -static void utest_testcase_run(int argc, char** argv) +static void utest_thr_entry(const char *utest_name) +{ + /* see commit:0dc7b9a for details */ + rt_thread_mdelay(1000); + + utest_run(utest_name); +} + +void utest_testcase_run(int argc, char** argv) { - void *thr_param = RT_NULL; static char utest_name[UTEST_NAME_MAX_LEN]; rt_memset(utest_name, 0x0, sizeof(utest_name)); @@ -322,13 +329,12 @@ static void utest_testcase_run(int argc, char** argv) 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, - UTEST_THREAD_STACK_SIZE, UTEST_THREAD_PRIORITY, 10); + (void (*)(void *))utest_thr_entry, utest_name, + UTEST_THREAD_STACK_SIZE, UTEST_THREAD_PRIORITY, 10); if (tid != NULL) { rt_thread_startup(tid); From ec736d6a433efe57605f18cc2f28febe57143f1a Mon Sep 17 00:00:00 2001 From: Shell Date: Wed, 12 Jun 2024 11:31:35 +0800 Subject: [PATCH 2/2] fixup: msh cmd prototype --- components/utilities/utest/utest.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/components/utilities/utest/utest.c b/components/utilities/utest/utest.c index afc0205d0d2..4871735d6f5 100644 --- a/components/utilities/utest/utest.c +++ b/components/utilities/utest/utest.c @@ -308,7 +308,7 @@ static void utest_thr_entry(const char *utest_name) utest_run(utest_name); } -void utest_testcase_run(int argc, char** argv) +long utest_testcase_run(int argc, char** argv) { static char utest_name[UTEST_NAME_MAX_LEN]; @@ -319,7 +319,7 @@ void utest_testcase_run(int argc, char** argv) if (argc == 1) { utest_run(RT_NULL); - return; + return 0; } else if (argc == 2 || argc == 3 || argc == 4) { @@ -356,6 +356,7 @@ void utest_testcase_run(int argc, char** argv) LOG_E("[ error ] at (%s:%d), in param error.", __func__, __LINE__); utest_help(); } + return 0; } MSH_CMD_EXPORT_ALIAS(utest_testcase_run, utest_run, utest_run [-thread or -help] [testcase name] [loop num]);