From 6fd2a7822460707636bc869f48faf289d2611599 Mon Sep 17 00:00:00 2001 From: HN026 Date: Sat, 18 Nov 2023 17:31:09 +0530 Subject: [PATCH] AFL_NO_CFG_FUZZING test added --- cargo-afl/Cargo.toml | 1 + cargo-afl/src/fuzz.rs | 6 ++++++ cargo-afl/tests/fuzz_test.rs | 12 ++++++++++++ 3 files changed, 19 insertions(+) create mode 100644 cargo-afl/src/fuzz.rs create mode 100644 cargo-afl/tests/fuzz_test.rs diff --git a/cargo-afl/Cargo.toml b/cargo-afl/Cargo.toml index 6553b9fba..60bd336a7 100644 --- a/cargo-afl/Cargo.toml +++ b/cargo-afl/Cargo.toml @@ -36,3 +36,4 @@ tempfile = "3.8" [features] default = [] plugins = [] +fuzzing = [] \ No newline at end of file diff --git a/cargo-afl/src/fuzz.rs b/cargo-afl/src/fuzz.rs new file mode 100644 index 000000000..f28e7903b --- /dev/null +++ b/cargo-afl/src/fuzz.rs @@ -0,0 +1,6 @@ +fn main() { + if !cfg!(fuzzing) { + panic!("Crash because fuzzing is not set. "); + } + println!("Running Normally"); +} \ No newline at end of file diff --git a/cargo-afl/tests/fuzz_test.rs b/cargo-afl/tests/fuzz_test.rs new file mode 100644 index 000000000..c47ccf369 --- /dev/null +++ b/cargo-afl/tests/fuzz_test.rs @@ -0,0 +1,12 @@ +#[cfg(test)] +mod tests { + use assert_cmd::Command; + + #[test] + fn test_fuzz(){ + let mut cmd = Command::cargo_bin("fuzz").unwrap(); + cmd.env("RUSTFLAGS", "-C passes=sancov -Zsanitizer=address"); + let output = cmd.unwrap(); + assert!(output.status.success()); + } +} \ No newline at end of file