diff options
| author | Yuqiang Wang <[email protected]> | 2025-10-20 12:46:44 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-10-20 12:46:44 +0800 |
| commit | 8816a9dc1b87b6504cc9d54397d06b464df79ebb (patch) | |
| tree | 8e161b2faf0474e44a8da7899ff66a5eaa1bb001 /components | |
| parent | 1ca86c79faff0f1720adc14b931eae072d27bf89 (diff) | |
utest/msh: supports autocomplete of utest cases for utest_run (#10701)
* utest/msh: supports autocomplete of utest cases for utest_run
* docs/utest: explanation of adding the automatic completion function for utest_run
* fix[utest]: Improvement of annotation description
* remove outdated code
Diffstat (limited to 'components')
| -rw-r--r-- | components/utilities/Kconfig | 7 | ||||
| -rw-r--r-- | components/utilities/utest/utest.c | 33 |
2 files changed, 39 insertions, 1 deletions
diff --git a/components/utilities/Kconfig b/components/utilities/Kconfig index 8601eb1e51..abd7c23994 100644 --- a/components/utilities/Kconfig +++ b/components/utilities/Kconfig @@ -216,6 +216,13 @@ config RT_USING_UTEST default n help If enable this option, the test cases will be run automatically when board boot up. + + if FINSH_USING_OPTION_COMPLETION + config RT_UTEST_MAX_OPTIONS + int "Maximum number of utest cases for auto-completion" + default 64 + endif + endif config RT_USING_VAR_EXPORT diff --git a/components/utilities/utest/utest.c b/components/utilities/utest/utest.c index 3d44a8b16a..e222c8efb2 100644 --- a/components/utilities/utest/utest.c +++ b/components/utilities/utest/utest.c @@ -73,6 +73,34 @@ void utest_log_lv_set(rt_uint8_t lv) } } +static struct msh_cmd_opt utest_testcase_run_msh_options[RT_UTEST_MAX_OPTIONS]; +static void utest_build_options(void); +static void utest_build_options(void) +{ + rt_size_t i; + rt_size_t option_index = 0; + + if (tc_num >= RT_UTEST_MAX_OPTIONS - 1) + { + LOG_W("The current number of test cases is (%d). Please expand RT_UTEST_MAX_OPTIONS's size to at least (%d).", tc_num, tc_num + 1); + } + + rt_memset(utest_testcase_run_msh_options, 0, sizeof(utest_testcase_run_msh_options)); + + rt_size_t max_cases = (tc_num < RT_UTEST_MAX_OPTIONS - 1) ? tc_num : RT_UTEST_MAX_OPTIONS - 1; + for (i = 0; i < max_cases; i++) + { + utest_testcase_run_msh_options[option_index].id = i + 1; + utest_testcase_run_msh_options[option_index].name = tc_table[i].name; + utest_testcase_run_msh_options[option_index].des = tc_table[i].name; + option_index++; + } + + utest_testcase_run_msh_options[option_index].id = 0; + utest_testcase_run_msh_options[option_index].name = RT_NULL; + utest_testcase_run_msh_options[option_index].des = RT_NULL; +} + int utest_init(void) { /* initialize the utest commands table.*/ @@ -123,6 +151,9 @@ int utest_init(void) LOG_E("no memory, tc_fail_list init failed!"); } } + + utest_build_options(); + return tc_num; } INIT_COMPONENT_EXPORT(utest_init); @@ -379,7 +410,7 @@ int utest_testcase_run(int argc, char** argv) return RT_EOK; } -MSH_CMD_EXPORT_ALIAS(utest_testcase_run, utest_run, utest_run [-thread or -help] [testcase name] [loop num]); +MSH_CMD_EXPORT_ALIAS(utest_testcase_run, utest_run, utest_run [-thread or -help] [testcase name] [loop num], optenable); utest_t utest_handle_get(void) { |
