KCOV(1)

πŸ“¦
version 43 Β· 3 versions
, in arch rolling, debian trixie, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, ubuntu resolute, ubuntu stonking

KCOV(1) πŸ’–

okay so bestie, welcome to the kcov manual page β€” this is a General Commands Manual entry and it's literally the group chat lore you need. sit down, grab a boba, we're doing coverage analysis πŸ§‹βœ¨


✨ NAME ✨

kcov β€” code coverage analysis for compiled programs and Python scripts πŸ’…


✨ SYNOPSIS ✨

kcov [options] out-dir in-file [args-for-executable...]

kcov --merge outdir <path-to-coverage> [path-to-more-coverage...]

✨ DESCRIPTION ✨

so this page gives you the briefly rundown on the kcov command, no cap. kcov is a code coverage tester for ELF binaries, Python scripts and shell scripts. the way it does it is so iconic β€” it collects code coverage info from executables without needing special compiler directives, and it keeps continuously producing output from long-running applications. main character energy fr fr πŸ‘‘

if you want even more docs, go look at the GitHub page, https://github.com/SimonKagstrom/kcov πŸ¦‹


✨ OPTIONS ✨

  • -p, --pid=PID β€” trace PID instead of executing the executable (and ngl, passing the executable is optional in this case). ⚠️ heads up though: under this mode, coverage collection for shared libraries will not work.
  • -l, --limits=low,high β€” set up the limits for low/high coverage. default is 25,75 πŸŽ€
  • --include-path=P1[,P2...] β€” comma-separated list of paths to include in the report.
  • --exclude-path=P1[,P2...] β€” comma-separated list of paths to exclude from the report.
  • --include-pattern=P1[,P2...] β€” comma-separated list of path patterns to include in the report.
  • --exclude-pattern=P1[,P2...] β€” comma-separated list of path patterns to exclude from the report.
  • --exclude-line=P1[,P2...] β€” comma-separated list of line patterns to exclude (mark as non-code).
  • --exclude-region=START:END[,START1:END1...] β€” comma-separated list of regions of line patterns to exclude (mark as non-code). the region begins with START and ends with END.
  • --clean β€” don't accumulate data from multiple runs. fresh start slay ✨
  • --collect-only β€” only collect coverage data, don't produce HTML/Cobertura output.
  • --dump-summary β€” dump a brief coverage summary on stdout after execution.
  • --report-only β€” only report HTML/Cobertura output, don't collect data.
  • --merge β€” merge the result of multiple kcov runs. instead of a program to test, the output paths from previous runs should be given on the command line, or through a wildcard (*) πŸŒ€
  • --coveralls-id=id β€” upload data to coveralls.io using secret repo_token or Travis CI service job ID id. the ID is taken as a repo_token if it's longer or equal to 32 characters.
  • --strip-path=path β€” if not set, max common path will be stripped away.

πŸ’… UNCOMMON OPTIONS πŸ’…

  • --path-strip-level=N β€” number of path levels to show for common paths. default is 2.
  • --skip-solibs β€” skip coverage collection for shared libraries (improves performance πŸƒβ™€οΈ).
  • --verify β€” verify that breakpoints are setup on instruction boundaries. this will slow down execution greatly, but it can catch problems where the compiler generates bad DWARF data.
  • --exit-first-process β€” exit when the first process exits, i.e., honor the behavior of daemons. the default behavior is to return to the console when the last process exits.
  • --cobertura-only β€” generate only cobertura output, as cov.xml, in the output directory. the intended usage is for e.g., vscode coverage gutters, where the output directory can then be pointed to somewhere in the project directory to get coverage with little droppings πŸ“
  • --python-parser=PARSER β€” set the python parser to use for Python programs (the default is python). can be used to run with Python 3 on systems where Python 2 is the default.
  • --bash-parser=PARSER β€” set the bash parser to use for shell scripts (the default is /bin/bash).
  • --bash-method=METHOD β€” use collection method METHOD for bash scripts. the method can be either PS4, for use of the PS4 environment variable, or DEBUG for use of the DEBUG trap.
  • --bash-handle-sh-invocation β€” handle invocations of /bin/sh scripts via using a LD_PRELOADed library that replaces execve (i.e., /bin/sh is executed as /bin/bash). does not work well on some systems, so the default is not to use this.
  • --bash-dont-parse-binary-dir β€” kcov parses the directory of the binary for other scripts and adds these to the report. if you don't want this behavior, this option turns that off.
  • --bash-parse-files-in-dir=P1[,P2...] β€” parse directories for bash scripts.
  • --bash-tracefd-closeexec β€” force children to not be traced by configuring the trace fd as non-cloneable with LD_PRELOAD. buggy on some systems πŸ’€
  • --replace-src-path=P1:P2 β€” replace source file path P1 with P2, if found.
  • --system-record β€” perform full-system instrumentation on a sysroot, outputting patched binaries which collect coverage data. see doc/full-system-instrumentation.md for more information on full-system instrumentation.
  • --system-report β€” produce coverage output for a full-system coverage run.
  • --debug=level β€” set the debug level, 0...31 (as a mask). default is 0 for no debug output.
  • --output-interval=MS β€” set the output writing interval in milliseconds. the default is 5000.
  • --configure=KEY=VAL β€” configure key/value pairs of internal options. see --help --uncommon-options for possible configuration options.
  • --patchelf=CMD β€” for system mode, set the patchelf command (default patchelf).

🌈 EXAMPLES 🌈

check coverage for ./frodo and generate HTML output in /tmp/kcov and cobertura output in /tmp/kcov/frodo/cobertura.xml:

kcov /tmp/kcov ./frodo

check coverage for ./frodo but only include source files names with the string src/frodo:

kcov --include-pattern=src/frodo /tmp/kcov ./frodo

same as above but split collecting and reporting (perhaps on two different computers πŸ–₯️πŸ–₯️):

kcov --collect-only /tmp/kcov ./frodo

kcov --report-only --include-pattern=src/frodo /tmp/kcov ./frodo

πŸ¦‹ HTML OUTPUT πŸ¦‹

the HTML output shows executed and non-executed lines of the source code. some lines can map to multiple instrumentation points, for example for inlined functions (where every inlining of them will generate a separate instrumentation point). this is shown in the left column as 1/3 for example, which means that one of the three instrumentation points has been executed.

there's a special output link called [merged] πŸ‘‘ which shows the union of all covered programs. this can be useful for example when you have unit tests in multiple binaries which share a subset of source files. obsessed with that actually.


⭐ COBERTURA OUTPUT ⭐

kcov also outputs data in the Cobertura XML format, which allows integrating kcov output in Jenkins (see https://cobertura.github.io/cobertura/ and https://www.jenkins.io/).

the Cobertura output is placed in a file named out-path/exec-filename/cobertura.xml.


πŸŽ€ JSON OUTPUT πŸŽ€

kcov generates a very generic json file which includes the overall percent covered for a single command and the count of lines instrumented and covered. it also includes a summary of each source file with a percentage and line counts. this allows easy integration with GitlabCI (see https://docs.gitlab.com/ce/user/project/pipelines/settings.html).

the JSON output is placed in a file named out-path/exec-filename/coverage.json.


πŸ’œ AUTHOR πŸ’œ

kcov was written by Simon Kagstrom, building upon bcov by Thomas Neumann.

this manual page was written by Michael Tautschnig <mt@debian.org>, for the Debian project (but may be used by others).


and that's a wrap bestie 🫢 this was the KCOV(1) page, dated July 8, 2024 β€” go forth and get those coverage numbers up, you've got this πŸ’–βœ¨

πŸ“¦ where this page comes from