Skip to content

Commit e4ad715

Browse files
authored
Merge pull request #253 from fitzgen/0.10.0-release
0.10.0 release
2 parents b6395b3 + 1c8064d commit e4ad715

File tree

5 files changed

+54
-64
lines changed

5 files changed

+54
-64
lines changed

CHANGELOG.md

+24
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,30 @@ Released YYYY-MM-DD.
2828

2929
--------------------------------------------------------------------------------
3030

31+
## 0.10.0
32+
33+
Released 2021-03-10.
34+
35+
### Added
36+
37+
* Added the `cargo fuzz coverage` subcommand to generate coverage data for a
38+
fuzz target. Learn more in [the Coverage chapter of the Rust Fuzzing
39+
Book!](https://rust-fuzz.github.io/book/cargo-fuzz/coverage.html)
40+
41+
--------------------------------------------------------------------------------
42+
43+
## 0.9.2
44+
45+
--------------------------------------------------------------------------------
46+
47+
## 0.9.1
48+
49+
--------------------------------------------------------------------------------
50+
51+
## 0.9.0
52+
53+
--------------------------------------------------------------------------------
54+
3155
## 0.8.0
3256

3357
Released 2020-06-25.

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cargo-fuzz"
3-
version = "0.9.2"
3+
version = "0.10.0"
44
authors = ["The rust-fuzz Project Developers"]
55
license = "MIT OR Apache-2.0"
66
description = "A `cargo` subcommand for using `libFuzzer`! Easy to use! No need to recompile LLVM!"

README.md

-53
Original file line numberDiff line numberDiff line change
@@ -65,59 +65,6 @@ You can also always find the full command-line options that are available with
6565
$ cargo fuzz --help
6666
```
6767

68-
## Code coverage
69-
70-
### Prerequisites
71-
Install the LLVM-coverage tools as described in the [Unstable book](https://doc.rust-lang.org/beta/unstable-book/compiler-flags/source-based-code-coverage.html#installing-llvm-coverage-tools).
72-
73-
We recommend using at least LLVM 11 and a recent nightly version of the Rust toolchain.
74-
This code was tested with `1.51.0-nightly (2021-02-10)`.
75-
76-
### Generate code-coverage data
77-
78-
After you fuzzed your program, use the `coverage` command to generate precise
79-
[source-based code coverage](https://blog.rust-lang.org/inside-rust/2020/11/12/source-based-code-coverage.html)
80-
information:
81-
```
82-
$ cargo fuzz coverage <target> [corpus dirs] [-- <args>]
83-
```
84-
This command
85-
86-
- compiles your project using the `-Zinstrument-coverage` Rust compiler flag,
87-
- runs the program _without fuzzing_ on the provided corpus (if no corpus directory is provided it uses `fuzz/corpus/<target>` by default),
88-
- for each input file in the corpus, generates raw coverage data in the `fuzz/coverage/<target>/raw` subdirectory,
89-
- merges the raw files into a `coverage.profdata` file located in the `fuzz/coverage/<target>` subdirectory.
90-
91-
Use the generated `coverage.profdata` file to generate coverage reports and visualize code-coverage information
92-
as described in the [Unstable book](https://doc.rust-lang.org/beta/unstable-book/compiler-flags/source-based-code-coverage.html#creating-coverage-reports).
93-
94-
### Example
95-
96-
Suppose we have a `compiler` fuzz target for which we want to visualize code coverage.
97-
98-
1. Run the fuzzer on the `compiler` target:
99-
100-
```
101-
$ cargo fuzz run compiler
102-
```
103-
104-
2. Produce code-coverage information:
105-
106-
```
107-
$ cargo fuzz coverage compiler
108-
```
109-
110-
2. Visualize the coverage data in HTML:
111-
112-
```
113-
$ cargo cov -- show target/.../compiler \
114-
--format=html \
115-
-instr-profile=fuzz/coverage/compiler/coverage.profdata \
116-
> index.html
117-
```
118-
119-
There are many visualization and coverage-report options available (see `llvm-cov show --help`).
120-
12168
## Trophy case
12269

12370
[The trophy case](https://github.com/rust-fuzz/trophy-case) has a list of bugs

src/project.rs

+28-9
Original file line numberDiff line numberDiff line change
@@ -588,10 +588,10 @@ impl FuzzProject {
588588

589589
/// Produce coverage information for a given corpus
590590
pub fn exec_coverage(self, coverage: &options::Coverage) -> Result<()> {
591-
// Build project with source-based coverage generation enabled
591+
// Build project with source-based coverage generation enabled.
592592
self.exec_build(&coverage.build, Some(&coverage.target))?;
593593

594-
// Retrieve corpus directories
594+
// Retrieve corpus directories.
595595
let corpora = if coverage.corpus.is_empty() {
596596
vec![self.corpus_for(&coverage.target)?]
597597
} else {
@@ -602,7 +602,7 @@ impl FuzzProject {
602602
.collect()
603603
};
604604

605-
// Collect the (non-directory) readable input files from the corpora
605+
// Collect the (non-directory) readable input files from the corpora.
606606
let files_and_dirs = corpora.iter().flat_map(fs::read_dir).flatten().flatten();
607607
let mut readable_input_files = files_and_dirs
608608
.filter(|file| match file.file_type() {
@@ -621,16 +621,21 @@ impl FuzzProject {
621621

622622
let (coverage_out_raw_dir, coverage_out_file) = self.coverage_for(&coverage.target)?;
623623

624-
// Generating individual coverage data for all files in corpora
624+
// Generating individual coverage data for all files in corpora.
625625
for input_file in readable_input_files {
626626
let (mut cmd, file_name) =
627627
self.create_coverage_cmd(coverage, &coverage_out_raw_dir, &input_file.path())?;
628628
eprintln!("Generating coverage data for {:?}", file_name);
629629
let status = cmd
630630
.status()
631-
.with_context(|| format!("failed to run command: {:?}", cmd))?;
631+
.with_context(|| format!("Failed to run command: {:?}", cmd))?;
632632
if !status.success() {
633-
bail!("failed to generate coverage data: {}", status);
633+
Err(anyhow!(
634+
"Command exited with failure status {}: {:?}",
635+
status,
636+
cmd
637+
))
638+
.context("Failed to generage coverage data")?;
634639
}
635640
}
636641

@@ -677,10 +682,24 @@ impl FuzzProject {
677682
merge_cmd.arg(raw_file?.path());
678683
}
679684
merge_cmd.arg("-o").arg(profdata_out_path);
685+
680686
eprintln!("Merging raw coverage data...");
681-
merge_cmd
682-
.output()
683-
.with_context(|| "Merging raw coverage files failed.")?;
687+
let status = merge_cmd
688+
.status()
689+
.with_context(|| format!("Failed to run command: {:?}", merge_cmd))
690+
.with_context(|| "Merging raw coverage files failed.\n\
691+
\n\
692+
Do you have LLVM coverage tools installed?\n\
693+
https://doc.rust-lang.org/beta/unstable-book/compiler-flags/source-based-code-coverage.html#installing-llvm-coverage-tools")?;
694+
if !status.success() {
695+
Err(anyhow!(
696+
"Command exited with failure status {}: {:?}",
697+
status,
698+
merge_cmd
699+
))
700+
.context("Merging raw coverage files failed")?;
701+
}
702+
684703
if profdata_out_path.exists() {
685704
eprintln!("Coverage data merged and saved in {:?}.", profdata_out_path);
686705
Ok(())

0 commit comments

Comments
 (0)