PlatformIO Community

Gcov and lcov for esp32 project

Hi I have developed a platformio project for esp32 using the arduino framework and some external libs.
I would like to run gcov and lcov on the the uni test on the esp32.
I wa able to run them without gcov and lcov…
How can I run on the native env (host pc) … which is the process ?

Thanks a lot

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
check_tool = cppcheck
check_flags = cppcheck: --enable=all --language=c++ --addon=misra.json
lib_ldf_mode = deep
lib_deps =
  me-no-dev/AsyncTCP@^1.1.1
  me-no-dev/ESP Async WebServer@^1.2.3
  knolleary/PubSubClient@^2.8
  miq19/eModbus@^1.3.0
  emelianov/modbus-esp8266@^4.0.0
; Custom Serial Monitor speed (baud rate)
monitor_speed = 115200

[env:native]
platform = native
lib_ldf_mode = deep
lib_deps =
    me-no-dev/AsyncTCP@^1.1.1
    me-no-dev/ESP Async WebServer@^1.2.3
    knolleary/PubSubClient@^2.8
    miq19/eModbus@^1.3.0
    emelianov/modbus-esp8266@^4.0.0
 build_flags =
    -lgcov
    --coverage

You can actually do that, but you need to implement a few functoins like _write and _open to hijack the writing of the coverage file and redirect them to UART (or print a command that when entered into the GDB console dumps that memory content into the file). That’s e.g. showcased in Code Coverage for Embedded Target with Eclipse, gcc and gcov | MCU on Eclipse.

Please see Unit Testing — PlatformIO latest documentation, especially the example projects repository. When using it in an Arduino-based project, you probably want to use ArduinoFake.