diff --git a/centipede/centipede_callbacks.cc b/centipede/centipede_callbacks.cc index 65372121..fd8c8bb6 100644 --- a/centipede/centipede_callbacks.cc +++ b/centipede/centipede_callbacks.cc @@ -415,7 +415,8 @@ CentipedeCallbacks::GetOrCreateCommandContextForBinary( std::make_unique( std::move(server_path)); } - std::vector env = {ConstructRunnerFlags( + std::vector env = env_.env_for_binaries; + env.push_back(ConstructRunnerFlags( absl::StrCat(":shmem:test=", env_.test_name, ":arg1=", inputs_blobseq_.path(), ":arg2=", outputs_blobseq_.path(), ":failure_description_path=", failure_description_path_, @@ -425,12 +426,13 @@ CentipedeCallbacks::GetOrCreateCommandContextForBinary( : absl::StrCat(":persistent_mode_socket=", persistent_mode_server->server_path()), ":"), - disable_coverage)}; + disable_coverage)); - if (env_.clang_coverage_binary == binary) - env.emplace_back( + if (env_.clang_coverage_binary == binary) { + env.push_back( absl::StrCat("LLVM_PROFILE_FILE=", WorkDir{env_}.SourceBasedCoverageRawProfilePath())); + } Command::Options cmd_options; cmd_options.env_add = std::move(env); @@ -642,7 +644,8 @@ bool CentipedeCallbacks::GetSeedsViaExternalBinary( "dl_path_suffix=", env_.runner_dl_path_suffix, ":"); } Command::Options cmd_options; - cmd_options.env_add = {std::move(centipede_runner_flags)}; + cmd_options.env_add = env_.env_for_binaries; + cmd_options.env_add.push_back(std::move(centipede_runner_flags)); cmd_options.env_remove = EnvironmentVariablesToUnset(); cmd_options.stdout_file_prefix = execute_log_prefix_; cmd_options.stderr_file_prefix = execute_log_prefix_; @@ -707,7 +710,8 @@ bool CentipedeCallbacks::GetSerializedTargetConfigViaExternalBinary( "dl_path_suffix=", env_.runner_dl_path_suffix, ":"); } Command::Options cmd_options; - cmd_options.env_add = {std::move(centipede_runner_flags)}; + cmd_options.env_add = env_.env_for_binaries; + cmd_options.env_add.push_back(std::move(centipede_runner_flags)); cmd_options.env_remove = EnvironmentVariablesToUnset(); cmd_options.stdout_file_prefix = execute_log_prefix_; cmd_options.stderr_file_prefix = execute_log_prefix_; diff --git a/centipede/centipede_flags.inc b/centipede/centipede_flags.inc index 1a171d76..9871cd95 100644 --- a/centipede/centipede_flags.inc +++ b/centipede/centipede_flags.inc @@ -484,3 +484,11 @@ CENTIPEDE_FLAG( bool, report_crash_summary, true, "If set, reports a summary of crashes found during fuzzing or replay." ) +CENTIPEDE_FLAG( + std::vector, env_for_binaries, {}, + "A comma-separated list of environment variables (KEY=VALUE) to pass to the " + "target binary, coverage binary, and extra binaries. By default, these " + "binaries inherit the parent process's environment, except for certain " + "test-related variables (e.g., Bazel's TEST_*) that are explicitly unset " + "to avoid interference." +)