Skip to content

Commit

Permalink
Add basic forking coverage support
Browse files Browse the repository at this point in the history
  • Loading branch information
louismerlin committed Oct 16, 2023
1 parent 205a95e commit c3dfe48
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 72 deletions.
94 changes: 42 additions & 52 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ cargo_metadata = { version = "0.18.0", optional = true }
clap = { version = "4.4.6", features = ["cargo", "derive", "env"], optional = true }
console = { version = "0.15.7", optional = true }
env_logger = { version = "0.10.0", optional = true }
fork = { version = "0.1.22", optional = true }
glob = { version = "0.3.1", optional = true }
# We use our own fork of honggfuzz to use the tool's latest release
# https://github.com/rust-fuzz/honggfuzz-rs/pull/85
Expand Down Expand Up @@ -49,3 +50,4 @@ cli = [
"time-humanize",
"cargo_metadata",
]
coverage = ["fork", "libc"]
2 changes: 1 addition & 1 deletion examples/arbitrary/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ edition = "2021"
publish = false

[dependencies]
ziggy = { path = "../../", default-features = false }
ziggy = { path = "../../", features = ["coverage"], default-features = false }
arbitrary = { version = "1", features= ["derive"] }
28 changes: 11 additions & 17 deletions src/bin/cargo-ziggy/coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ impl Cover {

// We build the runner with the appropriate flags for coverage
process::Command::new(cargo)
.args(["rustc", "--target-dir=target/coverage"])
.args([
"rustc",
"--target-dir=target/coverage",
"--features=ziggy/coverage",
])
.env("RUSTFLAGS", coverage_rustflags)
.env("RUSTDOCFLAGS", "-Cpanic=unwind")
.env("CARGO_INCREMENTAL", "0")
Expand Down Expand Up @@ -56,22 +60,12 @@ impl Cover {

info!("Corpus directory is {}", shared_corpus.display());

// We run the target against the corpus
shared_corpus.canonicalize()?.read_dir()?.for_each(|item| {
let item = item.unwrap();
let item_path = item.path();

let result = process::Command::new(format!("./target/coverage/debug/{}", &self.target))
.args([item_path.as_os_str()])
.spawn()
.unwrap()
.wait_with_output()
.unwrap();

if !result.status.success() {
eprintln!("Coverage crashed on {}, continuing.", item_path.display())
}
});
let _ = process::Command::new(format!("./target/coverage/debug/{}", &self.target))
.arg(format!("{}", shared_corpus.display()))
.spawn()
.unwrap()
.wait_with_output()
.unwrap();

let source_or_workspace_root = match &self.source {
Some(s) => s.display().to_string(),
Expand Down
Loading

0 comments on commit c3dfe48

Please sign in to comment.