Compute differential coverage, a better way of comparing testing tools.
Project description
Differential Coverage
A better way of comparing testing tools.
Why?
Looking only at absolute (code) coverage when comparing testing tools loses a lot of information: Do all approaches cover the same blocks? Or just the same total count? How different is their coverage?
Here, differential coverage can help: By comparing what parts of the target is covered by each approach, we get much better insight into what is actually happening.
What?
In principle, differential coverage measures how much of approach $a_2$'s coverage can also be covered by approach $a_1$. This can be done in multiple ways:
relcovdoes exactly this. It is an asymetrical measure between coverage of two approaches. If the approach relies on randomness (such as most fuzzers), it can aggregate over multiple trials of these.relscoreaggregates all this data to an order of all approaches. This measure, compared to simple coverage numbers, takes into account and values higher approaches that can cover code that no other approach covers. However, compared torelcov, this hides a lot of information in this aggregation.
For more precise definitions, including formulas, look at DEFINITIONS.md.
How?
differential-coverage currently reads afl-showmap-style data: files with <edge_id>: <count> rows, where <count> is only checked to contain a number $\geq 1$. These files are expected to be in the following structure:
coverage_data
|-- approach_1
| |-- showmap_trial_1.out
| |-- showmap_trial_2.out
| `-- showmap_trial_3.out
|-- approach_2
| |-- showmap_trial_1.out
| |-- showmap_trial_2.out
| `-- showmap_trial_3.out
`-- seeds
`-- showmap.out
If you would like support for other input formats, please raise an issue in the GitHub repository!
Installation
Install differential-coverage directly from pypi:
pip install differential-coverage
# if you need latex output support
pip install differential-coverage[latex]
Command Line Interface
Generally, the command line interface follows the following structure:
differential-coverage {relcov,relscore} <your-input-dir>
There are some options available, e.g. for output as csv or (colored) LaTeX table:
differential-coverage --help
API
from differential_coverage import (
DifferentialCoverage,
ApproachData,
CollectionReducer,
ValueReducer,
)
# last part (EdgeId) can be any comparable type, e.g. str, int
dc: DifferentialCoverage[str, str, Any]
# read from campaign directory, see above for structure
dc = DifferentialCoverage.from_campaign_dir("<your-input-dir>")
# or from a memory structure
dc = DifferentialCoverage(
{
"approach_1": {"trial_1": {1, 2}, "trial_2": {1, 3}},
"approach_2": {"trial_1": {1, 3}, "trial_2": {1, 3}},
"approach_3": {"trial_1": {1, 2, 3}, "trial_2": {1, 2, 3}},
"seeds": {"seeds": {1}},
}
)
a1_name: str
a1_data: ApproachData[str, Any]
a2_name: str
a2_data: ApproachData[str, Any]
for a1_name, a1_data in dc.approaches.items():
for a2_name, a2_data in dc.approaches.items():
relcov: float = a1_data.relcov(
a2_data,
value_reducer=ValueReducer.MEDIAN, # how to reduce relcov values from multiple trials from a1
collection_reducer=CollectionReducer.UNION, # how to reduce the edges from multiple trials from a2
)
print(f"relcov {a1_name} vs {a2_name}: {relcov}")
relscores: dict[str, float] = dc.relscores()
for approach_name, relscore in relscores.items():
print(f"relscore {approach_name}: {relscore}")
Hints
When using differential coverage to compare different testing approaches, you may want to do the following:
- Use this approach early on in your development process already, it has helped me uncover problems with my evaluation setup. And you want to discover those before having to redo your entire evaluation.
- For approaches that rely on radomness, such as most fuzzers, run multiple trials! This is generally necessary, not just for differential coverage[^sok].
- For approaches that rely on some sort of input corpus, such as some fuzzers, record coverage of the target when passed just the input corpus, and add that to your data. This allows analyzing how much extra coverage a fuzzer reaches, and how the corpus itself compares to other fuzzers.
- Related: If you compare an approach with different seed corpora, add coverage maps from all input corpora to your table, to compare them within each other, and against the approaches' results based on them.
Development
Install dev dependencies and set up the pre-commit hook (runs a couple of checks before committing):
pip install -e ".[dev]"
pre-commit install
[^sok] SoK: Prudent Evaluation Practices for Fuzzing, https://ieeexplore.ieee.org/document/10646824
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file differential_coverage-1.0.0rc1.tar.gz.
File metadata
- Download URL: differential_coverage-1.0.0rc1.tar.gz
- Upload date:
- Size: 16.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e923e10c2c7df0b4e80e23fe0b9ac5ea14199d04d2882ef4751ee5ad389a33d9
|
|
| MD5 |
65b3185d7eec42624f2a733aaac21efd
|
|
| BLAKE2b-256 |
e4fa613de6a2fbd97ec448483ed25e7c98930910507baa2158b97ddc393641d6
|
Provenance
The following attestation bundles were made for differential_coverage-1.0.0rc1.tar.gz:
Publisher:
ci.yml on riesentoaster/differential-coverage
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
differential_coverage-1.0.0rc1.tar.gz -
Subject digest:
e923e10c2c7df0b4e80e23fe0b9ac5ea14199d04d2882ef4751ee5ad389a33d9 - Sigstore transparency entry: 940415867
- Sigstore integration time:
-
Permalink:
riesentoaster/differential-coverage@dac5fccd1a920245b839792e97f3a43afd27bc51 -
Branch / Tag:
refs/tags/v1.0.0rc1 - Owner: https://github.com/riesentoaster
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@dac5fccd1a920245b839792e97f3a43afd27bc51 -
Trigger Event:
push
-
Statement type:
File details
Details for the file differential_coverage-1.0.0rc1-py3-none-any.whl.
File metadata
- Download URL: differential_coverage-1.0.0rc1-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
62eeec09c29b6bac628d4451036bea85338a1b2b9585a44660b5ca2a6b13ef19
|
|
| MD5 |
bac7bd6b74a429bc2303bd39c0f0565a
|
|
| BLAKE2b-256 |
54416e47e3fd22d48502a3e5a5296118962c96200aee64f98b415251b06256ea
|
Provenance
The following attestation bundles were made for differential_coverage-1.0.0rc1-py3-none-any.whl:
Publisher:
ci.yml on riesentoaster/differential-coverage
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
differential_coverage-1.0.0rc1-py3-none-any.whl -
Subject digest:
62eeec09c29b6bac628d4451036bea85338a1b2b9585a44660b5ca2a6b13ef19 - Sigstore transparency entry: 940415872
- Sigstore integration time:
-
Permalink:
riesentoaster/differential-coverage@dac5fccd1a920245b839792e97f3a43afd27bc51 -
Branch / Tag:
refs/tags/v1.0.0rc1 - Owner: https://github.com/riesentoaster
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@dac5fccd1a920245b839792e97f3a43afd27bc51 -
Trigger Event:
push
-
Statement type: