Skip to content
Merged
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
17 changes: 17 additions & 0 deletions rust/e2e_tests/testdata/fuzz_tests_as_gtests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,20 @@ fn bool_fuzz_test(_a: bool) {
_c = Arbitrary::<bool>::default(),
)]
fn multi_arg_fuzz_test(_a: i32, _b: f32, _c: bool) {}

mod sub {
use super::*;

#[fuzztest(_a = Arbitrary::<bool>::default())]
fn bool_fuzz_test(_a: bool) {
static ONCE: Once = Once::new();
ONCE.call_once(|| {
println!("sub::bool_fuzz_test property function ran...");
});
}
}

#[googletest::prelude::gtest]
fn regular_gtest() {
println!("regular_gtest ran...");
}
31 changes: 22 additions & 9 deletions rust/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ impl CentipedeArgs {
let argv0 = env::args().next().context("while attempting to get argv[0]")?;

let stripped_test_name = strip_crate_name(current_test_name);
add_arg(format!("--binary={argv0} {stripped_test_name} --exact --nocapture"))?;
// Under libtest harness, will parse everything until the first `--`.
add_arg(format!("--binary={argv0} {stripped_test_name} --exact --nocapture --"))?;
let normalized_test_name = current_test_name.replace("::", ".");
add_arg(format!("--test_name={normalized_test_name}"))?;

Expand Down Expand Up @@ -205,7 +206,7 @@ impl CentipedeArgs {
// ==============================================================================
// 3. Common Environment Variables Differential
// ==============================================================================
let env_diff = Self::default_env_diff();
let env_diff = Self::default_env_diff(current_test_name);
add_arg(format!("--env_diff_for_binaries={}", env_diff.join(",")))?;

// ==============================================================================
Expand Down Expand Up @@ -303,7 +304,7 @@ impl CentipedeArgs {
/// could cause the subprocess to think it's running in a sharded environment, try to
/// write to restricted output files, or trigger other harness-specific behavior that
/// interferes with fuzzing.
fn default_env_diff() -> Vec<String> {
fn default_env_diff(current_test_name: &str) -> Vec<String> {
let env_diff = vec![
"-TEST_DIAGNOSTICS_OUTPUT_DIR".to_string(),
"-TEST_INFRASTRUCTURE_FAILURE_FILE".to_string(),
Expand All @@ -319,6 +320,7 @@ impl CentipedeArgs {
"-TEST_WARNINGS_OUTPUT_FILE".to_string(),
"-GTEST_OUTPUT".to_string(),
"-XML_OUTPUT_FILE".to_string(),
format!("TESTBRIDGE_TEST_ONLY={current_test_name}"),
];

env_diff
Expand Down Expand Up @@ -482,7 +484,8 @@ mod tests {

expect_true!(args_str
.iter()
.any(|s| s.starts_with("--binary=") && s.contains("my_mod::my_test --exact")));
.any(|s| s.starts_with("--binary=")
&& s.contains("my_mod::my_test --exact --nocapture --")));

expect_true!(args_str.contains(&"--stop_after=10s"));
expect_true!(args_str.contains(&"--test_name=my_crate.my_mod.my_test"));
Expand Down Expand Up @@ -563,6 +566,7 @@ mod tests {

expect_true!(env_diff_arg.contains("-TEST_SHARD_INDEX"));
expect_true!(env_diff_arg.contains("-XML_OUTPUT_FILE"));
expect_true!(env_diff_arg.contains("TESTBRIDGE_TEST_ONLY=my_crate::my_mod::my_test"));
expect_true!(env_diff_arg.contains("-GTEST_OUTPUT"));
}

Expand Down Expand Up @@ -594,8 +598,15 @@ mod tests {
args._c_strings.iter().map(|s| s.to_str().expect("invalid utf8")).collect();

expect_true!(args_str.iter().any(|s| s.starts_with("--binary=")
&& s.contains("outer::inner::__fuzztest_mod__foo::foo --exact")));
&& s.contains("outer::inner::__fuzztest_mod__foo::foo --exact --nocapture --")));
expect_true!(args_str.contains(&"--test_name=my_crate.outer.inner.__fuzztest_mod__foo.foo"));

let env_diff_arg = args_str
.iter()
.find(|s| s.starts_with("--env_diff_for_binaries="))
.expect("missing --env_diff_for_binaries arg");
expect_true!(env_diff_arg
.contains("TESTBRIDGE_TEST_ONLY=my_crate::outer::inner::__fuzztest_mod__foo::foo"));
}

#[gtest]
Expand Down Expand Up @@ -662,9 +673,10 @@ mod tests {
let args_str: Vec<&str> =
args._c_strings.iter().map(|s| s.to_str().expect("invalid utf8")).collect();

assert!(args_str
expect_true!(args_str
.iter()
.any(|s| s.starts_with("--binary=") && s.contains("my_mod::my_test --exact")));
.any(|s| s.starts_with("--binary=")
&& s.contains("my_mod::my_test --exact --nocapture --")));
assert!(args_str.contains(&"--fuzztest_only_replay=true"));
assert!(args_str.contains(&"--fuzztest_time_limit_per_test=10s"));
assert!(!args_str.iter().any(|s| s.starts_with("--j=")));
Expand Down Expand Up @@ -709,9 +721,10 @@ mod tests {
let args_str: Vec<&str> =
args._c_strings.iter().map(|s| s.to_str().expect("invalid utf8")).collect();

assert!(args_str
expect_true!(args_str
.iter()
.any(|s| s.starts_with("--binary=") && s.contains("my_mod::my_test --exact")));
.any(|s| s.starts_with("--binary=")
&& s.contains("my_mod::my_test --exact --nocapture --")));
assert!(args_str.contains(&"--fuzztest_only_replay=true"));
assert!(args_str.contains(&"--fuzztest_replay_coverage_inputs=true"));
assert!(args_str.contains(&"--load_shards_only=true"));
Expand Down
Loading