Skip to content

Latest commit

 

History

History
37 lines (20 loc) · 3.21 KB

COVERAGE.md

File metadata and controls

37 lines (20 loc) · 3.21 KB

Using gcov and gcovr to provide code coverage

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.

Requirements

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.

Editor 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 the gcovr 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 and idf.coveredDarkTheme for dark themes.
  • Partially covered lines use idf.partialLightTheme for light themes and idf.partialDarkTheme for dark themes.
  • Non-covered lines use idf.uncoveredLightTheme for light themes and idf.uncoveredDarkTheme for dark themes.

HTML report

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 the gcovr from Debug adapter's python requirements.

With the generated HTML from gcovr, a Webview Panel is launched to show the gcov html report.