Skip to content

Commit

Permalink
Add fuzz_parallel test
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed May 10, 2024
1 parent ad46819 commit 0d21c2b
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
1 change: 1 addition & 0 deletions cargo-test-fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ rustc_version = "0.4"
semver = "1.0"
serde_json = "1.0"
tempfile = "3.10"
walkdir = "2.5"
xshell = "0.2"

testing = { path = "../testing", package = "test-fuzz-testing" }
Expand Down
46 changes: 46 additions & 0 deletions cargo-test-fuzz/tests/fuzz_parallel.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use internal::dirs::output_directory_from_target;
use predicates::prelude::*;
use std::{ffi::OsStr, fs::remove_dir_all};
use testing::{examples, retry, CommandExt};

const CPUS: &str = "2";
const TIME_SLICE: &str = "30";

#[test]
fn fuzz_parallel() {
for i in 0..6 {
let output_dir = output_directory_from_target("parallel", &format!("target_{i}"));
remove_dir_all(output_dir).unwrap_or_default();
}

examples::test("parallel", "test")
.unwrap()
.logged_assert()
.success();

retry(3, || {
examples::test_fuzz_inexact("parallel", "target")
.unwrap()
.args([
"--exit-code",
"--run-until-crash",
"--cpus",
CPUS,
"--slice",
TIME_SLICE,
])
.logged_assert()
.try_code(predicate::eq(1))
})
.unwrap();

// smoelius: Verify that all `.cur_input` files were removed.
for i in 0..6 {
let output_dir = output_directory_from_target("parallel", &format!("target_{i}"));
if output_dir.exists() {
assert!(!walkdir::WalkDir::new(output_dir)
.into_iter()
.any(|entry| entry.unwrap().path().file_name() == Some(OsStr::new(".cur_input"))));
}
}
}
29 changes: 29 additions & 0 deletions examples/tests/parallel.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#[test_fuzz::test_fuzz]
fn target_0(x: bool) {}

#[test_fuzz::test_fuzz]
fn target_1(x: bool) {}

#[test_fuzz::test_fuzz]
fn target_2(x: bool) {}

#[test_fuzz::test_fuzz]
fn target_3(x: bool) {
assert!(!x);
}

#[test_fuzz::test_fuzz]
fn target_4(x: bool) {}

#[test_fuzz::test_fuzz]
fn target_5(x: bool) {}

#[test]
fn test() {
target_0(false);
target_1(false);
target_2(false);
target_3(false);
target_4(false);
target_5(false);
}
7 changes: 7 additions & 0 deletions testing/src/examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,10 @@ pub fn test_fuzz(krate: &str, target: &str) -> Result<Command> {
command
})
}

pub fn test_fuzz_inexact(krate: &str, target: &str) -> Result<Command> {
test_fuzz_all().map(|mut command| {
command.args(["--test", krate, target]);
command
})
}

0 comments on commit 0d21c2b

Please sign in to comment.