feat(system/console): add help command verbose level option

Support users to demonstrate command info in different verbose levels.

Closes https://github.com/espressif/esp-idf/issues/9158
This commit is contained in:
Xiaoyu Liu
2024-05-17 18:09:32 +08:00
parent ea2f512cb5
commit 18f6be771d
4 changed files with 176 additions and 4 deletions

View File

@@ -273,3 +273,37 @@ TEST_CASE("esp console test with context", "[console]")
TEST_ESP_OK(esp_console_deinit());
}
TEST_CASE("esp console help command - set verbose level = 0", "[console][ignore]")
{
esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT();
esp_console_dev_uart_config_t uart_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT();
TEST_ESP_OK(esp_console_new_repl_uart(&uart_config, &repl_config, &s_repl));
TEST_ESP_OK(esp_console_register_help_command());
TEST_ESP_ERR(ESP_ERR_INVALID_ARG, esp_console_set_help_verbose_level(ESP_CONSOLE_HELP_VERBOSE_LEVEL_MAX_NUM));
TEST_ESP_OK(esp_console_set_help_verbose_level(ESP_CONSOLE_HELP_VERBOSE_LEVEL_0));
TEST_ESP_OK(esp_console_start_repl(s_repl));
vTaskDelay(pdMS_TO_TICKS(5000));
}
TEST_CASE("esp console help command - set verbose level = 1", "[console][ignore]")
{
esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT();
esp_console_dev_uart_config_t uart_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT();
TEST_ESP_OK(esp_console_new_repl_uart(&uart_config, &repl_config, &s_repl));
TEST_ESP_OK(esp_console_register_help_command());
TEST_ESP_ERR(ESP_ERR_INVALID_ARG, esp_console_set_help_verbose_level(ESP_CONSOLE_HELP_VERBOSE_LEVEL_MAX_NUM));
TEST_ESP_OK(esp_console_set_help_verbose_level(ESP_CONSOLE_HELP_VERBOSE_LEVEL_1));
TEST_ESP_OK(esp_console_start_repl(s_repl));
vTaskDelay(pdMS_TO_TICKS(5000));
}
TEST_CASE("esp console help command - --verbose sub command", "[console][ignore]")
{
esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT();
esp_console_dev_uart_config_t uart_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT();
TEST_ESP_OK(esp_console_new_repl_uart(&uart_config, &repl_config, &s_repl));
TEST_ESP_OK(esp_console_register_help_command());
TEST_ESP_OK(esp_console_start_repl(s_repl));
vTaskDelay(pdMS_TO_TICKS(5000));
}

View File

@@ -183,3 +183,81 @@ def test_console_sorted_help_reverse_registration(dut: Dut, test_on: str) -> Non
)
def test_console_help_quit(dut: Dut, test_on: str) -> None:
do_test_help_quit(dut)
@pytest.mark.parametrize(
'config', [
pytest.param('defaults'),
]
)
@pytest.mark.parametrize(
'test_on', [
pytest.param('host', marks=[pytest.mark.linux, pytest.mark.host_test]),
pytest.param('target', marks=[pytest.mark.esp32, pytest.mark.generic]),
pytest.param('target', marks=[pytest.mark.esp32c3, pytest.mark.generic]),
pytest.param('qemu', marks=[pytest.mark.esp32, pytest.mark.host_test, pytest.mark.qemu]),
]
)
def test_console_help_verbose_level_0(dut: Dut, test_on: str) -> None:
help_verbose_info = 'Print the summary of all registered commands if no arguments are given,'
dut.expect_exact('Press ENTER to see the list of tests')
dut.write('"esp console help command - set verbose level = 0"')
dut.expect_exact('esp>', timeout=5)
# verify help command
dut.write('help')
dut.write('help')
dut.expect_exact('help', not_matching=help_verbose_info)
@pytest.mark.parametrize(
'config', [
pytest.param('defaults'),
]
)
@pytest.mark.parametrize(
'test_on', [
pytest.param('host', marks=[pytest.mark.linux, pytest.mark.host_test]),
pytest.param('target', marks=[pytest.mark.esp32, pytest.mark.generic]),
pytest.param('target', marks=[pytest.mark.esp32c3, pytest.mark.generic]),
pytest.param('qemu', marks=[pytest.mark.esp32, pytest.mark.host_test, pytest.mark.qemu]),
]
)
def test_console_help_verbose_level_1(dut: Dut, test_on: str) -> None:
help_verbose_info = 'Print the summary of all registered commands if no arguments are given,'
dut.expect_exact('Press ENTER to see the list of tests')
dut.write('"esp console help command - set verbose level = 1"')
dut.expect_exact('esp>', timeout=5)
# verify help command
dut.write('help')
dut.expect_exact(help_verbose_info)
@pytest.mark.parametrize(
'config', [
pytest.param('defaults'),
]
)
@pytest.mark.parametrize(
'test_on', [
pytest.param('host', marks=[pytest.mark.linux, pytest.mark.host_test]),
pytest.param('target', marks=[pytest.mark.esp32, pytest.mark.generic]),
pytest.param('target', marks=[pytest.mark.esp32c3, pytest.mark.generic]),
pytest.param('qemu', marks=[pytest.mark.esp32, pytest.mark.host_test, pytest.mark.qemu]),
]
)
def test_console_help_verbose_subcommand(dut: Dut, test_on: str) -> None:
help_verbose_info = 'Print the summary of all registered commands if no arguments are given,'
dut.expect_exact('Press ENTER to see the list of tests')
dut.write('"esp console help command - --verbose sub command"')
dut.expect_exact('esp>', timeout=5)
# verify help --verbose=0 subcommand
dut.write('help --verbose=0')
dut.write('help --verbose=0')
dut.expect_exact('help --verbose=0',not_matching=help_verbose_info)
# verify help --verbose=1 subcommand
dut.write('help --verbose=1')
dut.expect_exact(help_verbose_info)