Skip to content
Open
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
23 changes: 19 additions & 4 deletions centipede/engine_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
20 changes: 16 additions & 4 deletions centipede/engine_worker_abi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Loading