Skip to content
/ kcov Public
forked from SimonKagstrom/kcov

a fork of kcov, for better covering zig/c/cpp, with same usage as kcov

License

GPL-2.0, Unknown licenses found

Licenses found

GPL-2.0
COPYING
Unknown
COPYING.externals
Notifications You must be signed in to change notification settings

liyu1981/kcov

 
 

Repository files navigation

A fork of kcov for better covering Zig

This is a rather than naive fork of wonderful kcov for better supporting Zig projects.

It adds the ability to auto recognize Zig's unreachable and @panic for auto ignoring.

Here is a screenshot of auto ignoring unreachable.

zig-unreachable-example

Here is another screenshot of auto ignoring @panic.

zig-panic-example

It also adds the ability in c/c++ source file of using /* no-cover */ to mark a line to be ignored.

Here is a screenshot of manual ignoring by placing /* no-cover */ in c source file.

c-no-cover example

Usage

There is no change of original kcov usage, it will just work. Please follow the below original Kcov README.

But how can I get the binary?

The best way is to compile from source. It can be done as follows (you will need cmake, ninja, llvm@>16 as I tried)

git clone https://github.com/liyu1981/kcov.git
cd kcov
mkdir build
cd build
CC="clang" CXX="clang++" cmake -G Ninja ..
ninja

after building is done. The binary is at build/src/kcov. Copy somewhere and use it.

(Or you can download a copy of Apple Silicon version binary from the release section.)

But can I build it with zig?

There is now an experimental build.zig file, and you can use zig build sign_kcov to build on Macos with M1/M2/M3 chip. The built result will be at zig-out/bin/kcov, and it will work as same to the one compiled from CMake. (need this sign_kcov step because macos needs to sign before use for debugging purpose, which is how kcov underlying works).

I am planning to complete this build.zig in future for Linux/Windows on x86_64 or even arm/arm64, but it needs some time.

File Support

  • for Zig, support source file with .zig extension.
  • for C/C++, support source file with .c/.cpp/.cc extension.

Original Kcov Readme

Coveralls coverage status Codecov coverage status Coverity Scan Build Status Docker Pulls

PayPal Donate Github All Releases

kcov

Kcov is a FreeBSD/Linux/OSX code coverage tester for compiled languages, Python and Bash. Kcov was originally a fork of Bcov, but has since evolved to support a large feature set in addition to that of Bcov.

Kcov, like Bcov, uses DWARF debugging information for compiled programs to make it possible to collect coverage information without special compiler switches.

For a video introduction, look at this presentation from SwedenCPP

Installing

Refer to the INSTALL file for build instructions, or use our official Docker images:

How to use it

Basic usage is straight-forward:

kcov /path/to/outdir executable [args for the executable]

/path/to/outdir will contain lcov-style HTML output generated continuously while the application runs. Kcov will also write cobertura- compatible XML output and generic JSON coverage information and can easily be integrated in various CI systems.

Filtering output

It's often useful to filter output, since e.g., /usr/include is seldom of interest. This can be done in two ways:

kcov --exclude-pattern=/usr/include --include-pattern=part/of/path,other/path \
      /path/to/outdir executable

which will do a string-comparison and include everything which contains part/of/path or other/path but exclude everything that has the /usr/include string in it.

kcov --include-path=/my/src/path /path/to/outdir executable
kcov --exclude-path=/usr/include /path/to/outdir executable

Does the same thing, but with proper path lookups.

Merging multiple kcov runs

Kcov can also merge the results of multiple earlier runs. To use this mode, call kcov with --merge, an output path and one or more paths to an earlier run, e.g.,

kcov --merge /tmp/merged-output /tmp/kcov-output1 /tmp/kcov-output2
kcov --merge /tmp/merged-output /tmp/kcov-output*    # With a wildcard

Use from continuous integration systems

kcov is easy to integrate with travis-ci together with coveralls.io or codecov.io. It can also be used from Jenkins, SonarQube and GitLab CI. Refer to

  • coveralls for details about travis-ci + coveralls, or
  • codecov for details about travis-ci + codecov
  • jenkins for details about how to integrate in Jenkins
  • sonarqube for how to use kcov and sonarqube together
  • gitlab for use with GitLab

More information

kcov is written by Simon Kagstrom simon.kagstrom@gmail.com and more information can be found at the web page

About

a fork of kcov, for better covering zig/c/cpp, with same usage as kcov

Topics

Resources

License

GPL-2.0, Unknown licenses found

Licenses found

GPL-2.0
COPYING
Unknown
COPYING.externals

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 54.9%
  • JavaScript 13.4%
  • Python 9.5%
  • C 9.3%
  • CMake 5.9%
  • Zig 2.9%
  • Other 4.1%