diff --git a/components/console/test_apps/console/main/test_app_main.c b/components/console/test_apps/console/main/test_app_main.c index cc9ee8d9cc..8dffdfd32f 100644 --- a/components/console/test_apps/console/main/test_app_main.c +++ b/components/console/test_apps/console/main/test_app_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -7,10 +7,10 @@ #include "unity.h" #include "unity_test_runner.h" #include "esp_heap_caps.h" - +#include // Some resources are lazy allocated (newlib locks) in the console code, the threshold is left for that case -#define TEST_MEMORY_LEAK_THRESHOLD (-100) +#define TEST_MEMORY_LEAK_THRESHOLD (-150) static size_t before_free_8bit; static size_t before_free_32bit; @@ -40,6 +40,12 @@ void tearDown(void) void app_main(void) { + /* Preallocate some newlib locks to avoid it from + registering as memory leaks */ + + struct timeval tv = { 0 }; + gettimeofday(&tv, NULL); + printf("Running console component tests\n"); unity_run_menu(); } diff --git a/components/console/test_apps/console/main/test_console.c b/components/console/test_apps/console/main/test_console.c index 08861a72e9..677571a176 100644 --- a/components/console/test_apps/console/main/test_console.c +++ b/components/console/test_apps/console/main/test_console.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -9,6 +9,7 @@ #include "unity.h" #include "esp_console.h" #include "argtable3/argtable3.h" +#include "linenoise/linenoise.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" @@ -41,10 +42,15 @@ static int do_cmd_quit(int argc, char **argv) { printf("ByeBye\r\n"); s_repl->del(s_repl); + + linenoiseHistoryFree(); // Free up memory + return 0; } // Enter "quit" to exit REPL environment +/* Marked as ignore since it cannot run as a normal unity test case + ran separately in test_console_repl */ TEST_CASE("esp console repl test", "[console][ignore]") { esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT(); diff --git a/components/console/test_apps/console/pytest_console.py b/components/console/test_apps/console/pytest_console.py index ee69b43f8f..6a1a2f31ba 100644 --- a/components/console/test_apps/console/pytest_console.py +++ b/components/console/test_apps/console/pytest_console.py @@ -9,3 +9,16 @@ from pytest_embedded import Dut @pytest.mark.supported_targets def test_console(dut: Dut) -> None: dut.run_all_single_board_cases() + + +@pytest.mark.generic +@pytest.mark.supported_targets +def test_console_repl(dut: Dut) -> None: + dut.expect_exact('Press ENTER to see the list of tests') + dut.write('"esp console repl test"') + + dut.expect_exact('esp>') + dut.write('quit') + + dut.expect_exact('ByeBye') + dut.expect_unity_test_output()