diff --git a/components/console/commands.c b/components/console/commands.c index 0bd72c5221..75ab29e90d 100644 --- a/components/console/commands.c +++ b/components/console/commands.c @@ -62,8 +62,8 @@ esp_err_t esp_console_init(const esp_console_config_t *config) if (s_config.hint_color == 0) { s_config.hint_color = ANSI_COLOR_DEFAULT; } - if (config->heap_alloc_caps != 0) { - s_config.heap_alloc_caps = config->heap_alloc_caps; + if (s_config.heap_alloc_caps == 0) { + s_config.heap_alloc_caps = MALLOC_CAP_DEFAULT; } s_tmp_line_buf = heap_caps_calloc(1, config->max_cmdline_length, s_config.heap_alloc_caps); if (s_tmp_line_buf == NULL) { diff --git a/components/console/test_apps/console/main/test_console.c b/components/console/test_apps/console/main/test_console.c index 677571a176..bcb87e92bf 100644 --- a/components/console/test_apps/console/main/test_console.c +++ b/components/console/test_apps/console/main/test_console.c @@ -67,3 +67,24 @@ TEST_CASE("esp console repl test", "[console][ignore]") TEST_ESP_OK(esp_console_start_repl(s_repl)); vTaskDelay(pdMS_TO_TICKS(2000)); } + +TEST_CASE("esp console init/deinit test, minimal config", "[console]") +{ + /* Test with minimal init config */ + esp_console_config_t console_config = { + .max_cmdline_length = 100, + }; + + TEST_ESP_OK(esp_console_init(&console_config)); + const esp_console_cmd_t cmd = { + .command = "hello", + .help = "Print Hello World", + .hint = NULL, + .func = do_hello_cmd, + }; + + TEST_ESP_OK(esp_console_cmd_register(&cmd)); + // re-register the same command, just for test + TEST_ESP_OK(esp_console_cmd_register(&cmd)); + TEST_ESP_OK(esp_console_deinit()); +}