code-coverage-with-gcov
Automates gcov and gcovr integration for C/C++ builds to generate line-by-line code coverage reports.
Install
mkdir -p .claude/skills/code-coverage-with-gcov && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/184" && unzip -o skill.zip -d .claude/skills/code-coverage-with-gcov && rm skill.zipInstalls to .claude/skills/code-coverage-with-gcov
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Add gcov code coverage instrumentation to C/C++ projectsKey capabilities
- →Instrument C and C++ source code with gcov flags
- →Integrate coverage flags into Makefile and CMake build systems
- →Generate line-by-line text coverage reports
- →Produce interactive HTML coverage reports using gcovr
- →Calculate line, branch, and function coverage metrics
How it works
The tool adds the --coverage flag to compiler and linker settings to generate .gcda and .gcno files during execution. These files are then processed by gcov or gcovr to produce human-readable coverage reports.
Inputs & outputs
When to use code-coverage-with-gcov
- →Instrument C++ code for coverage analysis
- →Generate HTML coverage reports
- →Configure build systems for testing
About this skill
Code Coverage with gcov
Purpose
Instrument C/C++ programs with gcov to measure test coverage.
How It Works
Build with Coverage
gcc --coverage -o program source.c
Run Program
./program
# Creates .gcda files with execution data
Generate Reports
Text report:
gcov source.c
# Creates source.c.gcov with line-by-line coverage
HTML report:
gcovr --html-details -o coverage.html
Coverage Flags
--coverage(shorthand for-fprofile-arcs -ftest-coverage -lgcov)- Add to both
CFLAGSandLDFLAGS
Build System Integration
Makefile
ENABLE_COVERAGE ?= 0
ifeq ($(ENABLE_COVERAGE),1)
CFLAGS += --coverage
LDFLAGS += --coverage
endif
CMake
option(ENABLE_COVERAGE "Enable coverage" OFF)
if(ENABLE_COVERAGE)
add_compile_options(--coverage)
add_link_options(--coverage)
endif()
When User Requests Coverage
Steps
- Detect build system (Makefile/CMake/other)
- Add
--coverageto CFLAGS and LDFLAGS - Clean previous build:
make cleanorrm -f *.gcda *.gcno - Build with coverage:
make ENABLE_COVERAGE=1orcmake -DENABLE_COVERAGE=ON - Run tests:
make testor./test_suite - Generate report:
gcovr --html-details coverage.html --print-summary - Present summary and path to HTML report
Output
Text (.gcov files):
-: 0:Source:main.c
5: 42: int x = 10;
#####: 43: unused_code();
5:= executed 5 times#####:= not executed-:= non-executable
HTML: Interactive report with color-coded coverage
Metrics
- Line coverage: Executed lines / total lines
- Branch coverage: Taken branches / total branches
- Function coverage: Called functions / total functions
Target: 80%+ line coverage, 70%+ branch coverage
When not to use it
- →Projects not written in C or C++
- →Environments where gcov or gcovr tools are unavailable
Limitations
- →Requires manual cleaning of previous build artifacts to ensure accurate data
- →Depends on the presence of gcov and gcovr utilities
How it compares
This workflow automates the manual process of injecting compiler flags and executing post-build report generation commands.
Compared to similar skills
code-coverage-with-gcov side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| code-coverage-with-gcov (this skill) | 15 | 4mo | Review | Intermediate |
| 3d-games | 16 | 6mo | No flags | Advanced |
| quality-checker | 0 | 3mo | Review | Advanced |
| qt-cpp-review | 0 | 3mo | Review | Advanced |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by gadievron
View all by gadievron →You might also like
3d-games
davila7
3D game development principles. Rendering, shaders, physics, cameras.
quality-checker
rdkcentral
Run comprehensive quality checks (static analysis, memory safety, thread safety, build verification) on the MemCapture codebase. Use when validating code changes or debugging before committing.
qt-cpp-review
x-tools-author
>-
validate-render
kzahedi
Validates YARS rendering by exporting first frame as PNG and comparing with reference screenshot
cpp-expert
Tr3kkR
Review Yuzu C++ source changes for C++23 correctness, idiomatic standard-library use, ABI boundaries, threading primitives, and cross-compiler portability across GCC, Clang, MSVC, and Apple Clang. Use for any governance Gate 3 review when `.cpp`, `.hpp`, or `.h` files change.
dev_unity_unreal
AllurinsX
dev_unity_unreal — an agent skill by AllurinsX.