Skip to content

Commit

Permalink
Move domain setup checking to a new runner function `InitializeForExe…
Browse files Browse the repository at this point in the history
…cution()`.

The function is called in `RunnerMain()` immediately before we start executing
inputs. This allows long-running initialization (e.g., one that triggers loading
large seeds into a seeded domain) to happen separately, and thus not to be timed
as part of executing an input.

PiperOrigin-RevId: 726191912
  • Loading branch information
fniksic authored and copybara-github committed Feb 12, 2025
1 parent 15e7f45 commit b855d25
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions centipede/runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,8 @@ int RunnerMain(int argc, char **argv, RunnerCallbacks &callbacks) {
WriteFailureDescription(std::string(failure_description).c_str());
});

callbacks.InitializeForExecution();

// Inputs / outputs from shmem.
if (state.HasFlag(":shmem:")) {
if (!state.arg1 || !state.arg2) return EXIT_FAILURE;
Expand Down
3 changes: 3 additions & 0 deletions centipede/runner_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ namespace centipede {
// no stability is guaranteed for other usages.
class RunnerCallbacks {
public:
// Runs any initialization logic that should happen once before subsequent
// calls to `Execute()`.
virtual void InitializeForExecution() {}
// Attempts to execute the test logic using `input`, and returns false if the
// input should be ignored from the corpus, true otherwise.
virtual bool Execute(ByteSpan input) = 0;
Expand Down
4 changes: 3 additions & 1 deletion fuzztest/internal/centipede_adaptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,16 @@ class CentipedeAdaptorRunnerCallbacks : public centipede::RunnerCallbacks {
cmp_tables_(std::make_unique<TablesOfRecentCompares>()),
prng_(GetRandomSeed()) {}

bool Execute(centipede::ByteSpan input) override {
void InitializeForExecution() override {
if (!domain_setup_is_checked_) {
// Create a new domain input to trigger any domain setup
// failures here. (e.g. Ineffective Filter)
fuzzer_impl_.params_domain_.Init(prng_);
domain_setup_is_checked_ = true;
}
}

bool Execute(centipede::ByteSpan input) override {
auto parsed_input =
fuzzer_impl_.TryParse({(char*)input.data(), input.size()});
if (parsed_input.ok()) {
Expand Down

0 comments on commit b855d25

Please sign in to comment.