Skip to content

Commit

Permalink
Allow passing serialized FuzzTest configuration in env.
Browse files Browse the repository at this point in the history
When the env field is set, Centipede will not query the configuration using the runner callback.

Eventually, we will merge the Configuration fields used in Centipede as proper env fields, and eliminate the configuration callback.

PiperOrigin-RevId: 722681102
  • Loading branch information
xinhaoyuan authored and copybara-github committed Feb 3, 2025
1 parent 2efcd1e commit 4fe5ffb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion centipede/centipede_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,10 @@ int CentipedeMain(const Environment &env,
// We don't update the corpus database for standalone binaries (i.e., when
// `env.has_input_wildcards` is true).
if (!env.binary.empty() && !env.has_input_wildcards) {
const absl::StatusOr<std::string> serialized_target_config = [&] {
const auto serialized_target_config = [&]() -> absl::StatusOr<std::string> {
if (!env.fuzztest_configuration.empty()) {
return env.fuzztest_configuration;
}
ScopedCentipedeCallbacks scoped_callbacks(callbacks_factory, env);
return scoped_callbacks.callbacks()->GetSerializedTargetConfig();
}();
Expand Down
3 changes: 3 additions & 0 deletions centipede/environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ struct Environment {
// If set, operate on the corpus database for a single test specified by
// FuzzTest instead of all the tests.
bool fuzztest_single_test_mode = false;
// If set, deserializes the configuration from the value instead of querying
// the configuration via runner callbacks.
std::string fuzztest_configuration;

// Command line-related fields -----------------------------------------------

Expand Down
9 changes: 9 additions & 0 deletions fuzztest/internal/centipede_adaptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,15 @@ centipede::Environment CreateCentipedeEnvironmentFromConfiguration(
run_mode == RunMode::kUnitTest) {
total_time_limit = kUnitTestDefaultDuration;
}
{
Configuration single_test_configuration = configuration;
single_test_configuration.fuzz_tests_in_current_shard = {
std::string{test_name}};
single_test_configuration.time_limit = total_time_limit;
single_test_configuration.time_budget_type = TimeBudgetType::kTotal;
env.fuzztest_configuration = single_test_configuration.Serialize();
}

absl::StrAppend(&env.binary,
" --" FUZZTEST_FLAG_PREFIX
"internal_override_total_time_limit=",
Expand Down

0 comments on commit 4fe5ffb

Please sign in to comment.