Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions rust/e2e_tests/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,24 @@ pub fn run_centipede_with_args_expect_termination(fixture: &EnvVars, args: &[&st

String::from_utf8_lossy(&process.stderr).to_string()
}

/// Returns stderr of the target binary with `args` and `envs` that is expected to terminate.
///
/// In addition to `envs`, the function will also pass `FUZZTEST_CENTIPEDE_BINARY_PATH`,
/// `FUZZTEST_PRINT_SUBPROCESS_LOG=true`, and `RUST_TEST_NOCAPTURE=1`.
pub fn run_target_binary_with_args_and_env_expect_termination(
fixture: &EnvVars,
args: &[&str],
envs: &[(&str, &str)],
) -> String {
let process = Command::new(&fixture.target_binary_path)
.args(args)
.env("FUZZTEST_PRINT_SUBPROCESS_LOG", "true")
.env("FUZZTEST_CENTIPEDE_BINARY_PATH", &fixture.centipede_path)
.env("RUST_TEST_NOCAPTURE", "1")
.envs(envs.iter().copied())
.output()
.expect("Target binary should have executed");

String::from_utf8_lossy(&process.stderr).to_string()
}
36 changes: 26 additions & 10 deletions rust/e2e_tests/worker_with_centipede_sanitizer_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,19 @@ fn ensure_use_after_free_signature_with_asan(fixture: &EnvVars) {

let stderr = test_utils::run_centipede_with_args_expect_termination(fixture, &args);

expect_that!(
stderr,
matchers::contains_substring("Property function ran but address sanitizer caught a bug")
);
expect_that!(stderr, matchers::contains_regex("Failure[ \t]*: heap-use-after-free"));
}

#[gtest]
#[cfg(sanitize = "address")]
fn standalone_mode_reports_use_after_free_with_asan(fixture: &EnvVars) {
let args = ["__fuzztest_mod__use_after_free_asan_death_test::use_after_free_asan_death_test"];
let envs = [("FUZZTEST_FUZZ_FOR", "15s")];

let stderr =
test_utils::run_target_binary_with_args_and_env_expect_termination(fixture, &args, &envs);

expect_that!(stderr, matchers::contains_regex("Failure[ \t]*: heap-use-after-free"));
}

// TODO(yamilmorales): Enable this test on presubmit with --config=msan.
Expand All @@ -56,14 +65,21 @@ fn ensure_sanitizer_crash_signature_with_msan(fixture: &EnvVars) {
&format!("--workdir={}", work_dir.display()),
"--exit_on_crash",
"--test_name=__fuzztest_mod__msan_death_test.msan_death_test",
"--use_cmp_features=0", // Prevent msan from detecting nested bugs and aborting without
// triggering the death callback.
];

let stderr = test_utils::run_centipede_with_args_expect_termination(fixture, &args);

expect_that!(
stderr,
matchers::contains_substring("Property function ran but a sanitizer caught a bug")
);
expect_that!(stderr, matchers::contains_regex("Failure[ \t]*: use-of-uninitialized-value"));
}

#[gtest]
#[cfg(sanitize = "memory")]
fn standalone_mode_reports_uninitialized_value_with_msan(fixture: &EnvVars) {
let args = ["__fuzztest_mod__msan_death_test::msan_death_test"];
let envs = [("FUZZTEST_FUZZ_FOR", "15s")];

let stderr =
test_utils::run_target_binary_with_args_and_env_expect_termination(fixture, &args, &envs);

expect_that!(stderr, matchers::contains_regex("Failure[ \t]*: use-of-uninitialized-value"));
}
Loading
Loading