Skip to content

Commit 2372aba

Browse files
committed
utest/msh: supports autocomplete of utest cases for utest_run
1 parent b03bb70 commit 2372aba

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

components/utilities/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,12 @@ config RT_USING_UTEST
217217
help
218218
If enable this option, the test cases will be run automatically when board boot up.
219219

220+
if FINSH_USING_OPTION_COMPLETION
221+
config RT_UTEST_MAX_OPTIONS
222+
int "Maximum number of utest cases for auto-completion"
223+
default 64
224+
endif
225+
220226
config RT_UTEST_USING_ALL_CASES
221227
bool "Enable all selected modules' test cases"
222228
default n

components/utilities/utest/utest.c

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,34 @@ void utest_log_lv_set(rt_uint8_t lv)
7373
}
7474
}
7575

76+
static struct msh_cmd_opt utest_testcase_run_msh_options[RT_UTEST_MAX_OPTIONS];
77+
static void utest_build_options(void);
78+
static void utest_build_options(void)
79+
{
80+
rt_size_t i;
81+
rt_size_t option_index = 0;
82+
83+
if (tc_num >= RT_UTEST_MAX_OPTIONS - 1)
84+
{
85+
LOG_W("Too many test cases (%d), only first %d will have completion", tc_num, RT_UTEST_MAX_OPTIONS - 1);
86+
}
87+
88+
rt_memset(utest_testcase_run_msh_options, 0, sizeof(utest_testcase_run_msh_options));
89+
90+
rt_size_t max_cases = (tc_num < RT_UTEST_MAX_OPTIONS - 1) ? tc_num : RT_UTEST_MAX_OPTIONS - 1;
91+
for (i = 0; i < max_cases; i++)
92+
{
93+
utest_testcase_run_msh_options[option_index].id = i + 1;
94+
utest_testcase_run_msh_options[option_index].name = tc_table[i].name;
95+
utest_testcase_run_msh_options[option_index].des = tc_table[i].name;
96+
option_index++;
97+
}
98+
99+
utest_testcase_run_msh_options[option_index].id = 0;
100+
utest_testcase_run_msh_options[option_index].name = RT_NULL;
101+
utest_testcase_run_msh_options[option_index].des = RT_NULL;
102+
}
103+
76104
int utest_init(void)
77105
{
78106
/* initialize the utest commands table.*/
@@ -123,6 +151,9 @@ int utest_init(void)
123151
LOG_E("no memory, tc_fail_list init failed!");
124152
}
125153
}
154+
155+
utest_build_options();
156+
126157
return tc_num;
127158
}
128159
INIT_COMPONENT_EXPORT(utest_init);
@@ -379,7 +410,7 @@ int utest_testcase_run(int argc, char** argv)
379410

380411
return RT_EOK;
381412
}
382-
MSH_CMD_EXPORT_ALIAS(utest_testcase_run, utest_run, utest_run [-thread or -help] [testcase name] [loop num]);
413+
MSH_CMD_EXPORT_ALIAS(utest_testcase_run, utest_run, utest_run [-thread or -help] [testcase name] [loop num], optenable);
383414

384415
utest_t utest_handle_get(void)
385416
{

0 commit comments

Comments
 (0)