Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions components/utilities/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 32 additions & 1 deletion components/utilities/utest/utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.*/
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion documentation/6.components/utest/utest.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,13 @@ As shown in the figure above, the log of the test case run is divided into four
From the above flow chart you can get the following:

* The utest framework is a sequential execution of all **test units** in the *testcase* function
* Assert of the previous UTEST_UNIT_RUN macro has occurred, and all subsequent UTEST_UNIT_RUN will skip execution.
* Assert of the previous UTEST_UNIT_RUN macro has occurred, and all subsequent UTEST_UNIT_RUN will skip executio

## utest_run auto-completion Function

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.

![utest_run_auto_option](.\figures\utest_run_auto_option.png)

# NOTE

Expand Down
Loading