Skip to content

Commit dcf7ff6

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

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
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 MAX_UTEST_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_run_msh_options[MAX_UTEST_OPTIONS];
77+
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 >= MAX_UTEST_OPTIONS - 1)
84+
{
85+
LOG_W("Too many test cases (%d), only first %d will have completion", tc_num, MAX_UTEST_OPTIONS - 1);
86+
}
87+
88+
rt_memset(utest_run_msh_options, 0, sizeof(utest_run_msh_options));
89+
90+
rt_size_t max_cases = (tc_num < MAX_UTEST_OPTIONS - 1) ? tc_num : MAX_UTEST_OPTIONS - 1;
91+
for (i = 0; i < max_cases; i++)
92+
{
93+
utest_run_msh_options[option_index].id = i + 1;
94+
utest_run_msh_options[option_index].name = tc_table[i].name;
95+
utest_run_msh_options[option_index].des = tc_table[i].name;
96+
option_index++;
97+
}
98+
99+
utest_run_msh_options[option_index].id = 0;
100+
utest_run_msh_options[option_index].name = RT_NULL;
101+
utest_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
{
43.6 KB
Loading

documentation/6.components/utest/utest.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,13 @@ As shown in the figure above, the log of the test case run is divided into four
290290
From the above flow chart you can get the following:
291291

292292
* The utest framework is a sequential execution of all **test units** in the *testcase* function
293-
* Assert of the previous UTEST_UNIT_RUN macro has occurred, and all subsequent UTEST_UNIT_RUN will skip execution.
293+
* Assert of the previous UTEST_UNIT_RUN macro has occurred, and all subsequent UTEST_UNIT_RUN will skip executio
294+
295+
## utest_run auto-completion Function
296+
297+
The utest_run tool now supports dynamic auto-completion for test case names. After entering the utest_run command in the terminal, users can press the TAB key to activate the auto-completion feature. The system will then dynamically match and suggest available test case names in real time.
298+
299+
![utest_run_auto_option](.\figures\utest_run_auto_option.png)
294300

295301
# NOTE
296302

0 commit comments

Comments
 (0)