Просмотр исходного кода

Merge branch 'feature/console_repl_test' into 'master'

console: add running repl test in CI

Closes IDF-6611

See merge request espressif/esp-idf!23016
Marius Vikhammer 2 лет назад
Родитель
Сommit
1a1b0036a6

+ 9 - 3
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 <sys/time.h>
 
 // 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();
 }

+ 7 - 1
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();

+ 13 - 0
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()