This extension's code coverage feature uses the gcovr
python package which is included in the extension's requirements.txt and installed during install tutorial as part of this extension ESP-IDF Debug Adapter Python requirements when following the ESP-IDF: Configure ESP-IDF extension command.
Your ESP-IDF project should be configured to generate gcda/gcno
coverage files using gcov
. Please read GCOV Code coverage to learn more about code coverage with gcov in ESP-IDF projects.
Please take a look at COVERAGE for more information about code coverage in this extension.
Let's use the ESP-IDF gcov example for this tutorial.
-
Click menu View -> Command Palette... and type ESP-IDF: Show Examples Projects and choose
Use current ESP-IDF (/path/to/esp-idf)
. If the user doesn't see the option, please review the setup in Install tutorial. -
A window will be open with a list a projects, go the system section and choose the
gcov
. You will see a Create project using example gcov button in the top and a description of the project below. Click Create project using example gcov button.
-
Now select a container directory where to copy the example project. For example, if the user choose
/Users/myUser/someFolder
the resulting folder will be/Users/myUser/someFolder/gcov
. This new project directory will be created and opened in Visual Studio Code. -
First the user should select an Espressif target (esp32, esp32s2, etc.) with the ESP-IDF: Set Espressif device target command. Default is
esp32
and the one used in this tutorial. -
Next configure your sdkconfig project with the ESP-IDF: Configure project sdkconfig for coverage command or by yourself using the ESP-IDF: SDK Configuration editor command (CTRL E G keyboard shortcut ) where the user can modify the ESP-IDF project settings. After all changes are made, click save and close this window.
The example will enable the following options by default:
- Enable the Application Tracing Module under
Component config -> Application Level Tracing -> Data Destination
by choosingTrace memory
. - Enable GCOV to host interface under
Component config -> Application Level Tracing -> GCOV to Host Enable
. - Enable OpenOCD Debug Stubs under
Component config -> ESP32-specific -> OpenOCD debug stubs
NOTE: For any project that you want to generate code coverage, you should enable these settings in your sdkconfig.
- Now to build the project, flash your device and start the ESP-IDF Monitor you can use the ESP-IDF: Build your project, ESP-IDF: Flash your project and ESP-IDF: Monitor your device commands as explained in the basic use tutorial. If everything is executed correctly, there will be a message in ESP-IDF Monitor saying
Ready to dump GCOV data...
NOTE: There is also a ESP-IDF: Build, Flash and start a monitor on your device command (CTRL E D keyboard shortcut).
-
Next step is to launch openOCD and send some commands. To start openOCD from the extension, execute the ESP-IDF: OpenOCD Manager command or from the
OpenOCD Server (Running | Stopped)
button in the Visual Studio Code status bar. OpenOCD server output is shown in menuView
->Output
->OpenOCD
. -
Launch a new terminal with menu Terminal -> New Terminal and execute
telnet <oocd_host> <oocd_port>
which by default istelnet localhost 4444
. Latest macOS users can usenc <oocd_host> <oocd_port>
iftelnet
is not in the system.
NOTE: The user can modify
openocd.tcl.host
andopenocd.tcl.port
configuration settings to modify these values. Please review ESP-IDF Settings to see how to modify these configuration settings.
- First send the openOCD command
esp gcov dump
for hard-coded dump which will dump two hard-coded dumps based on this example. After that send theesp gcov
command for instant run-time dump.
- After dumping data one or more times, open the desired file in your editor and execute the ESP-IDF: Add Editor coverage command to highlight the editor with code coverage.
You can customize highlight color using these extension settings:
- Covered lines use
idf.coveredLightTheme
for light themes andidf.coveredDarkTheme
for dark themes. - Partially covered lines use
idf.partialLightTheme
for light themes andidf.partialDarkTheme
for dark themes. - Non-covered lines use
idf.uncoveredLightTheme
for light themes andidf.uncoveredDarkTheme
for dark themes.
Visual Studio code support "red"
, rgb(255,0,120)
or rgba(120,0,0,0.1)
.
Please review ESP-IDF Settings to see how to modify these configuration settings.
-
When finished, use the ESP-IDF: Remove Editor coverage command to remove the code coverage.
-
The user can generate a html report using the ESP-IDF: Get HTML Coverage Report for project command.
Make sure you had properly configure the required toolchain in idf.customExtraPaths
or in your environment variable PATH since the gcov executable used is {TOOLCHAIN_PREFIX}-gcov
(replacing TOOLCHAIN_PREFIX
for your IDF_TARGET
toolchain prefix) and gcovr
exists in the same directory as your ${idf.pythonBinPath}
path.
An easy way is to verify this is to execute ESP-IDF: Open ESP-IDF Terminal and type {TOOLCHAIN_PREFIX}-gcov --version
and gcovr --version
.