{"id":16139707,"url":"https://github.com/shenxianpeng/gcov-example","last_synced_at":"2026-01-18T23:34:16.737Z","repository":{"id":53917420,"uuid":"384930905","full_name":"shenxianpeng/gcov-example","owner":"shenxianpeng","description":"Use Gcov + LCOV/gcovr to show C/C++ projects code coverage results","archived":false,"fork":false,"pushed_at":"2025-08-18T11:49:04.000Z","size":190,"stargazers_count":50,"open_issues_count":2,"forks_count":22,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-26T02:05:13.373Z","etag":null,"topics":["code-coverage","coverage","gcov","gcovr","lcov"],"latest_commit_sha":null,"homepage":"https://shenxianpeng.github.io/gcov-example/","language":"Makefile","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shenxianpeng.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-07-11T11:27:21.000Z","updated_at":"2025-10-21T07:47:40.000Z","dependencies_parsed_at":"2023-02-10T13:46:37.963Z","dependency_job_id":null,"html_url":"https://github.com/shenxianpeng/gcov-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/shenxianpeng/gcov-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shenxianpeng%2Fgcov-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shenxianpeng%2Fgcov-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shenxianpeng%2Fgcov-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shenxianpeng%2Fgcov-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shenxianpeng","download_url":"https://codeload.github.com/shenxianpeng/gcov-example/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shenxianpeng%2Fgcov-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28553536,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T23:10:22.888Z","status":"ssl_error","status_checked_at":"2026-01-18T23:07:19.656Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code-coverage","coverage","gcov","gcovr","lcov"],"created_at":"2024-10-09T23:49:38.470Z","updated_at":"2026-01-18T23:34:16.731Z","avatar_url":"https://github.com/shenxianpeng.png","language":"Makefile","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Gcov Example\n\n**Use [Gcov](https://gcc.gnu.org/onlinedocs/gcc/Gcov.html) + [LCOV](https://github.com/linux-test-project/lcov) / [gcovr](https://github.com/gcovr/gcovr) to show C/C++ projects code coverage results.**\n\n[![Build](https://github.com/shenxianpeng/gcov-example/actions/workflows/build.yml/badge.svg)](https://github.com/shenxianpeng/gcov-example/actions/workflows/build.yml)\n[![Cpp Linter](https://github.com/shenxianpeng/gcov-example/actions/workflows/cpp-linter.yml/badge.svg)](https://github.com/shenxianpeng/gcov-example/actions/workflows/cpp-linter.yml)\n\nThis repo shows how to use Gcov to create lcov/gcovr coverage reports for C/C++ projects.\n\n**Code coverage reports online**\n\n* 📊 [LCOV - code coverage report](https://shenxianpeng.github.io/gcov-example/lcov-report/index.html)\n* 📊 [gcovr - code coverage report](https://shenxianpeng.github.io/gcov-example/gcovr-report/coverage.html)\n\nNote: The source code is under the `master` branch, and code coverage report under branch `coverage`.\n\n## What problem does Gcov solve\n\nThe problem I encountered: A C/C++ project from decades ago has no unit tests, only regression tests. But I want to know:\n\n* What code is tested by regression tests? \n* Which code is untested?\n* What is the code coverage? \n* Where do I need to improve automated test cases in the future?\n\nCan code coverage be measured without unit tests? The answer is Yes.\n\nThere are some tools on the market that can measure the code coverage of black-box testing, such as Squish Coco, Bullseye, etc but need to be charged. their principle is to insert instrumentation during build.\n\nI tried Squish Coco but I have some build issues are not resolved.\n\n## How Gcov works\n\nGcov workflow diagram\n\n![flow](img/gcov-flow.jpg)\n\nThere are three main steps:\n\n1. Adding special compile options to the GCC compilation to generate the executable, and `*.gcno`.\n2. Running (testing) the generated executable, which generates the `*.gcda` data file.\n3. With `*.gcno` and `*.gcda`, generate the `gcov` file from the source code, and finally generate the code coverage report.\n\nHere's how each of these steps is done exactly.\n\n## Getting started\n\nYou can clone this repository and run `make help` to see how to use it.\n\n```bash\n$ git clone https://github.com/shenxianpeng/gcov-example.git\ncd gcov-example\n\n$ make help\nhelp                           Makefile help\nbuild                          Make build\ncoverage                       Run code coverage\nlcov-report                    Generate lcov report\ngcovr-report                   Generate gcovr report\ndeps                           Install dependencies\nclean                          Clean all generate files\nlint                           Lint code with clang-format\n```\n\nSteps to generate code coverage reports\n\n```bash\n# 1. compile\nmake build\n\n# 2. run executable\n./main\n\n# 3. run code coverage\nmake coverage\n\n# 4. generate report\n# support lcov and gcovr reports\n# to make report need to install dependencies first\nmake deps\n# then\nmake lcov-report\n# or\nmake gcovr-report\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshenxianpeng%2Fgcov-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshenxianpeng%2Fgcov-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshenxianpeng%2Fgcov-example/lists"}