2018-06-14 22:00:46 +00:00
|
|
|
# Code Coverage
|
|
|
|
|
|
|
|
You can generate code coverage report for your project using [Clang Source-based
|
|
|
|
Code Coverage].
|
|
|
|
|
|
|
|
|
|
|
|
## Build fuzz targets
|
|
|
|
|
|
|
|
Code Coverage report generation requires a special build configuration to be
|
|
|
|
used. In order to produce such build for your project, run:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
python infra/helper.py build_image $project_name
|
|
|
|
python infra/helper.py build_fuzzers --sanitizer=profile $project_name
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## Establish access to GCS
|
|
|
|
|
|
|
|
To get a good understanding of quality of the fuzz testing established for your
|
|
|
|
project, code coverage should be generated by running fuzz targets against the
|
|
|
|
corpus aggregated by OSS-Fuzz. The helper script will download the corpus
|
2018-06-15 17:44:18 +00:00
|
|
|
automatically using `gsutil` tool. To make it work, you need:
|
|
|
|
|
|
|
|
* Install [gsutil tool]
|
|
|
|
* Check whether you have access to the corpus for your project:
|
2018-06-14 22:00:46 +00:00
|
|
|
|
|
|
|
```bash
|
|
|
|
gsutil ls gs://${project_name}-corpus.clusterfuzz-external.appspot.com/
|
|
|
|
```
|
|
|
|
|
|
|
|
If you see an authorization error from the command above, run:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
gcloud auth login
|
|
|
|
```
|
|
|
|
|
|
|
|
and try again. Once `gsutil` works, you can run the report generation.
|
|
|
|
|
|
|
|
|
|
|
|
## Generating code coverage reports
|
|
|
|
|
|
|
|
To generate code coverage report using the corpus aggregated on OSS-Fuzz, run:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
python infra/helper.py profile $project_name
|
|
|
|
```
|
|
|
|
|
|
|
|
If you want to generate code coverage report using the corpus you have locally,
|
2018-06-15 17:44:18 +00:00
|
|
|
copy the corpus into `build/corpus/$project_name/$fuzz_target/` directories for
|
|
|
|
each fuzz target, then run:
|
2018-06-14 22:00:46 +00:00
|
|
|
|
|
|
|
```bash
|
|
|
|
python infra/helper.py profile --no-corpus-download $project_name
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
[Clang Source-based Code Coverage]: https://clang.llvm.org/docs/SourceBasedCodeCoverage.html
|
2018-06-15 17:44:18 +00:00
|
|
|
[gsutil tool]: https://cloud.google.com/storage/docs/gsutil_install
|