Code coverage

November 28, 2019 ยท View on GitHub

"test coverage is a measure used to describe the degree to which the source code of a program is executed when a particular test suite runs." - src

Kcov

Kcov is a code coverage tester for compiled programs, Python scripts and shell scripts. It allows collecting code coverage information from executables without special command-line arguments, and continuously produces output from long-running applications. - website / github / video

kcov is also available using cargo:

Installation

Check the official INSTALL.md

How that's works?

Here is the global command:

# First, go inside your fuzzing folder
# like fuzz or hfuzz ou afl-fuzz
cd fuzz
# Create a folder for the coverage results
mkdir cov
# Run kcov on your FUZZ_TARGET
kcov ./cov ./target/debug/FUZZ_TARGET corpus/FUZZ_TARGET/*

Example with wasmer/compile_debug

Copy compile_debug inside wasmer repo.

$ cp wasm-fuzz/debug_tools/compile_debug .
# compile compile_debug with cargo
$ cd compile_debug
$ cargo build
# create cov output folder
$ mkdir cov
$ kcov --include-path .,.. ./cov ./target/debug/compile_debug ../hfuzz/hfuzz_workspace/compile_with_llvm/input/*
# look the result / open cov/index.html
$ firefox cov/index.html