KCOV(1)
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 is25,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 onstdoutafter execution.--report-onlyβ only report HTML/Cobertura output, don't collect data.--mergeβ merge the result of multiplekcovruns. 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 tocoveralls.iousing secretrepo_tokenor Travis CI service job ID id. the ID is taken as arepo_tokenif 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 is2.--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, ascov.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 ispython). 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 eitherPS4, for use of thePS4environment variable, orDEBUGfor use of theDEBUGtrap.--bash-handle-sh-invocationβ handle invocations of/bin/shscripts via using aLD_PRELOADed library that replacesexecve(i.e.,/bin/shis executed as/bin/bash). does not work well on some systems, so the default is not to use this.--bash-dont-parse-binary-dirβkcovparses 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 withLD_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. seedoc/full-system-instrumentation.mdfor 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 is0for no debug output.--output-interval=MSβ set the output writing interval in milliseconds. the default is5000.--configure=KEY=VALβ configure key/value pairs of internal options. see--help --uncommon-optionsfor possible configuration options.--patchelf=CMDβ for system mode, set thepatchelfcommand (defaultpatchelf).
π 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
- arch rolling: kcov 43-1 Β· GPL-2.0-or-later
- debian trixie: kcov 43+dfsg-1+b4 Β· GPL-2.0-only
- fedora 43: kcov 43-3.fc43 Β· GPL-2.0-only AND MIT AND (GPL-2.0-only OR MIT)
- fedora 44: kcov 43-4.fc44 Β· GPL-2.0-only AND MIT AND (GPL-2.0-only OR MIT)
- nixos 26.05: kcov 43
- nixpkgs unstable: kcov 43
- ubuntu resolute: kcov 43+dfsg-2 Β· GPL-2.0-only
- ubuntu stonking: kcov 43+dfsg-3 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms