diff --git a/centipede/engine_worker.cc b/centipede/engine_worker.cc index 19886f86..3c57f1ae 100644 --- a/centipede/engine_worker.cc +++ b/centipede/engine_worker.cc @@ -695,9 +695,9 @@ const char* FuzzTestWorkerGetTestName() { return test_name; } -FuzzTestWorkerStatus WorkerMaybeRun(const FuzzTestAdapterManager& manager) { +FuzzTestWorkerStatus WorkerRun(const FuzzTestAdapterManager& manager) { const auto& flags = GetWorkerFlags(); - if (!flags.present) return kFuzzTestWorkerNotRequired; + WorkerCheck(flags.present, "worker flags must present"); if (HasWorkerSwitchFlag("dump_configuration")) { return kFuzzTestWorkerSuccess; @@ -786,11 +786,26 @@ FuzzTestWorkerStatus WorkerMaybeRun(const FuzzTestAdapterManager& manager) { } // namespace fuzztest::internal +namespace { + +using ::fuzztest::internal::GetWorkerFlags; using ::fuzztest::internal::WorkerCheck; -using ::fuzztest::internal::WorkerMaybeRun; +using ::fuzztest::internal::WorkerRun; + +} // namespace + +FuzzTestWorkerStatus FuzzTestWorkerIsRequired() { + const auto& flags = GetWorkerFlags(); + if (!flags.present) return kFuzzTestWorkerNotRequired; + return kFuzzTestWorkerSuccess; +} FuzzTestWorkerStatus FuzzTestWorkerMaybeRun( const FuzzTestAdapterManager* manager) { WorkerCheck(manager != nullptr, "manager must not be nullptr"); - return WorkerMaybeRun(*manager); + if (FuzzTestWorkerStatus s = FuzzTestWorkerIsRequired(); + s != kFuzzTestWorkerSuccess) { + return s; + } + return WorkerRun(*manager); } diff --git a/centipede/engine_worker_abi.h b/centipede/engine_worker_abi.h index e4357424..23943726 100644 --- a/centipede/engine_worker_abi.h +++ b/centipede/engine_worker_abi.h @@ -29,12 +29,24 @@ extern "C" { #endif typedef enum { - kFuzzTestWorkerSuccess = 0, // Test should finish with a success - kFuzzTestWorkerFailure, // Test should finish with a failure. - kFuzzTestWorkerNotRequired, // Test should continue with controller commands. + kFuzzTestWorkerSuccess = 0, + kFuzzTestWorkerFailure, + kFuzzTestWorkerNotRequired, } FuzzTestWorkerStatus; -// Try to run as a FuzzTest worker with `manager` if needed. +// Queries if the worker is required without performing any work. It can be +// called without context of a test. Returns `kFuzzTestWorkerSuccess` if the +// worker is required to run in the tests, `kFuzzTestWorkerFailure` if it +// encounter a failure, or `kFuzzTestWorkerNotRequired` if the worker is not +// required. +FuzzTestWorkerStatus FuzzTestWorkerIsRequired(); + +// Tries to run as a FuzzTest engine worker with the test adapter `manager` if +// required (by calling `FuzzTestWorkerIsRequired()`). Should be run exactly +// once per test. Returns `kFuzzTestWorkerSuccess` if the worker succeeded for +// the test (and the test shall succeed), `kFuzzTestWorkerFailure` if it +// encountered a failure (and the test shall fail), or +// `kFuzzTestWorkerNotRequired` if the worker is not required. FuzzTestWorkerStatus FuzzTestWorkerMaybeRun( const FuzzTestAdapterManager* manager);