I am writing my first platformio unit tests but can’t see the output of printf() calls in the test. Is there a way to get the printf output, in the pio console or on an external terminal?
My setup:
The ESP32 is connected to the computer via a single USB cable and I can run ‘release’ programs and see their printf output with no problem.
platformio.ini
; Base
[env]
platform = espressif32
board = esp32dev
framework = espidf
monitor_speed = 115200
upload_port=COM6
board_build.partitions = partitions_singleapp_large.csv
upload_speed=921600
; For IntelliSense. Notice the embded framework id.
build_flags =
-I$PROJECT_CORE_DIR/packages/framework-espidf/components/driver
-I$PROJECT_CORE_DIR/packages/framework-espidf/components/freertos
-I$PROJECT_CORE_DIR/packages/framework-espidf/components/bt/host/bluedroid/api
-I$PROJECT_CORE_DIR/packages/framework-espidf/components/bt/host/bluedroid/stack/gatt
[env:release]
build_type = release
[env:debug]
build_type = debug
debug_tool=esp-prog
[env:test]
build_type = test
test_port=COM6
test_framework = unity
test_speed = 115200
Unit test test_main,cpp
#include <unity.h>
#include <stdio.h>
void setUp(void) { printf("setUp() called."); }
void tearDown(void) { printf("tearDown() called."); }
void test_foo(void) { printf("test_foo() called."); }
extern "C" void app_main() {
UNITY_BEGIN();
RUN_TEST(test_foo);
UNITY_END();
}
Test output. I had to press the reset button for the test to proceed.
Processing test_code_gen in test environment
--------------------------------------------------------------------------------------------------------------------------------------------------------Building & Uploading...
Testing...
If you don't see any output for the first 10 secs, please reset board (press reset button)
test/test_code_gen/test_main.cpp:12: test_foo [PASSED]
---------------------------------------------------- test:test_code_gen [PASSED] Took 67.77 seconds ----------------------------------------------------
======================================================================= SUMMARY =======================================================================
Environment Test Status Duration
------------- ------------- -------- ------------
test test_code_gen PASSED 00:01:07.770
====================================================== 1 test cases: 1 succeeded in 00:01:07.770 ======================================================
* Terminal will be reused by tasks, press any key to close it.
test output when connecting to a serial terminal and resettin the esp32
I (27) boot: chip revision: 3
I (27) boot_comm: chip revision: 3, min. bootloader chip revision: 0
I (33) boot.esp32: SPI Speed : 40MHz
I (37) boot.esp32: SPI Mode : DIO
I (41) boot.esp32: SPI Flash Size : 4MB
I (44) boot: Enabling RNG early entropy source...
I (49) boot: Partition Table:
I (51) boot: ## Label Usage Type ST Offset Length
I (58) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (64) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (71) boot: 2 factory factory app 00 00 00010000 00177000
I (77) boot: End of partition table
I (80) boot_comm: chip revision: 3, min. application chip revision: 0
I (86) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=07da8h ( 32168) map
I (106) esp_image: segment 1: paddr=00017dd0 vaddr=3ffbdb60 size=03534h ( 13620) load
I (111) esp_image: segment 2: paddr=0001b30c vaddr=40080000 size=04d0ch ( 19724) load
I (120) esp_image: segment 3: paddr=00020020 vaddr=400d0020 size=152fch ( 86780) map
I (151) esp_image: segment 4: paddr=00035324 vaddr=40084d0c size=07574h ( 30068) load
I (164) esp_image: segment 5: paddr=0003c8a0 vaddr=50000000 size=00010h ( 16) load
I (170) boot: Loaded app from partition at offset 0x10000
I (171) boot: Disabling RNG early entropy source...
I (181) cpu_start: Pro cpu up.
I (181) cpu_start: Starting app cpu, entry point is 0x400817e4
I (0) cpu_start: App cpu up.
I (193) cpu_start: Pro cpu start user code
I (193) cpu_start: cpu freq: 160000000
I (193) cpu_start: Application information:
I (194) cpu_start: Project name: ESP32
I (198) cpu_start: App version: 09f455e-dirty
I (203) cpu_start: Compile time: Jan 22 2023 11:13:52
I (208) cpu_start: ELF file SHA256: e6e819fa466ba972...
I (213) cpu_start: ESP-IDF: 4.4.2
I (217) heap_init: Initializing. RAM available for dynamic allocation:
I (223) heap_init: At 3FFAE6E0 len 0000F480 (61 KiB): DRAM
I (228) heap_init: At 3FFC1B60 len 0001E4A0 (121 KiB): DRAM
I (233) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (239) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (244) heap_init: At 4008C280 len 00013D80 (79 KiB): IRAM
I (251) spi_flash: detected chip: generic
I (253) spi_flash: flash io: dio
I (257) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
test/test_code_gen/test_main.cpp:12:test_foo:PASS
-----------------------
1 Tests 0 Failures 0 Ignored
OK