Git Product home page Git Product logo

gcov-example's Introduction

Gcov Example

Use Gcov + LCOV / gcovr to show C/C++ projects code coverage results.

pages-build-deployment Build

This repo shows how to use Gcov to create lcov/gcovr coverage reports for C/C++ projects.

Code coverage reports online

Note: The source code is under the master branch, and code coverage report under branch coverage.

What problem does Gcov solve

The problem I encountered: A C/C++ project from decades ago has no unit tests, only regression tests. But I want to know:

  • What code is tested by regression tests?
  • Which code is untested?
  • What is the code coverage?
  • Where do I need to improve automated test cases in the future?

Can code coverage be measured without unit tests? The answer is Yes.

There 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.

I tried Squish Coco but I have some build issues are not resolved.

How Gcov works

Gcov workflow diagram

flow

There are three main steps:

  1. Adding special compile options to the GCC compilation to generate the executable, and *.gcno.
  2. Running (testing) the generated executable, which generates the *.gcda data file.
  3. With *.gcno and *.gcda, generate the gcov file from the source code, and finally generate the code coverage report.

Here's how each of these steps is done exactly.

Getting started

You can clone this repository and run make help to see how to use it.

$ git clone https://github.com/shenxianpeng/gcov-example.git
cd gcov-example

$ make help
help                           Makefile help
build                          Make build
coverage                       Run code coverage
lcov-report                    Generate lcov report
gcovr-report                   Generate gcovr report
deps                           Install dependencies
clean                          Clean all generate files
lint                           Lint code with clang-format

Steps to generate code coverage reports

# 1. compile
make build

# 2. run executable
./main

# 3. run code coverage
make coverage

# 4. generate report
# support lcov and gcovr reports
# to make report need to install dependencies first
make deps
# then
make lcov-report
# or
make gcovr-report

gcov-example's People

Contributors

shenxianpeng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

gcov-example's Issues

Additional support on Gcov usage

  1. There are 2 configurations for a file [trigger.c] due to a macro i.e #define TRIGGER which can have values ON and OFF [ and hence 2 configurations ]. By 2 configurations, it is meant that

a. Configuration 1 : trigger.c - #define TRIGGER ON
b. Configuration 1 : trigger.c - #define TRIGGER OFF

Due to 2 different macros, different parts of code are enabled. But a consolidated coverage report is required, i.e which combines both coverage reports of configuration 1 and configuration 2 into a single report to show if any part of the code is missed to test.

Is this possible by directly using gcov and/or Gcovr and/or Gcov-tool and/or Gcov-dump?

  1. Is it possible to check for coverage of a particular file? i.e in a project there are multiple files such as trigger.c , trigger_internal.c etc but consolidated coverage of only trigger.c is required.

Please advise how to proceed on these 2 queries.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.