Source code coverage is data indicating the count and frequency of every program execution path that has been taken within a program’s runtime. Gcov is a GCC tool that, when used in concert with the compiler, can generate log files indicating the execution count of each line of a source code. The Gcovr tool is utility for managing Gcov and generating summarized code coverage results.
Please read GCOV Code coverage to learn more about code coverage with gcov in ESP-IDf projects.
Your ESP-IDF project should be configured to generate gcda/gcno coverage files using gcov as shown in GCOV Code coverage. Please take a look at the ESP-IDF gcov example as example project.
This extension requires gcovr
to generate JSON and HTML reports from generated files. This is installed as part of this extension SETUP.
Make sure you had properly configure the 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.
The ESP-IDF: Configure project sdkconfig for coverage command can set required values in your project sdkconfig to enable Code coverage.
For the text editor highlighting, the ESP-IDF: Add Editor coverage command execute a child process with gcovr -r . --gcov-executable {TOOLCHAIN_PREFIX}-gcov --json
. You can remove the coverage highlight with ESP-IDF; Remove Editor coverage.
NOTE: This assumes you had configure your extension with Xtensa toolchain in
idf.customExtraPaths
and installed thegcovr
from Debug adapter's python requirements.
For the text editor, we use the json object generated by the previous command to highlight each line if it is covered or if it is not. We don't highlight noncode lines.
You can customize highlight color using the extension settings. Visual Studio code support "red"
, rgb(255,0,120)
or rgba(120,0,0,0.1)
values.
- 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.
The ESP-IDF: Get HTML Coverage Report for project execute a child process with command gcovr -r . --gcov-executable {TOOLCHAIN_PREFIX}-gcov --html
for the HTML report.
NOTE: This assumes you had configure your extension with Xtensa toolchain in
idf.customExtraPaths
and installed thegcovr
from Debug adapter's python requirements.
With the generated HTML from gcovr
, a Webview Panel is launched to show the gcov html report.