Skip to content
Merged
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
33 changes: 24 additions & 9 deletions centipede/engine_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <cstdlib>
#include <cstring>
#include <memory>
#include <optional>
#include <string>
#include <string_view>
#include <type_traits>
Expand Down Expand Up @@ -218,6 +219,7 @@ enum class WorkerAction {
kTestGetSeeds,
kTestMutate,
kTestExecute,
kNoOp,
};

constexpr std::string_view kWorkerBinaryIdOutputFlagHeader =
Expand Down Expand Up @@ -431,8 +433,11 @@ int GetCrossOverLevel() {
return result;
}

WorkerAction GetWorkerAction() {
static WorkerAction worker_action = [] {
std::optional<WorkerAction> GetWorkerAction() {
static auto worker_action = []() -> std::optional<WorkerAction> {
if (HasWorkerSwitchFlag("dump_configuration")) {
return WorkerAction::kNoOp;
}
if (HasWorkerSwitchFlag("dump_binary_id")) {
return WorkerAction::kGetBinaryId;
}
Expand All @@ -443,7 +448,9 @@ WorkerAction GetWorkerAction() {
return WorkerAction::kTestGetSeeds;
}
auto* inputs_blobseq = GetInputsBlobSequence();
WorkerCheck(inputs_blobseq != nullptr, "input blob sequence is not found");
if (inputs_blobseq == nullptr) {
return std::nullopt;
}
auto request_type_blob = inputs_blobseq->Read();
if (IsMutationRequest(request_type_blob)) {
inputs_blobseq->Reset();
Expand All @@ -453,9 +460,7 @@ WorkerAction GetWorkerAction() {
inputs_blobseq->Reset();
return WorkerAction::kTestExecute;
}
WorkerCheck(false, "unknown worker action from the flags");
// should not reach here.
std::abort();
return std::nullopt;
}();
return worker_action;
}
Expand Down Expand Up @@ -908,6 +913,12 @@ FuzzTestWorkerStatus WorkerRun(const FuzzTestAdapterManager& manager) {
}

const auto action = GetWorkerAction();
WorkerCheck(action.has_value(), "No worker action to run");

if (action == WorkerAction::kNoOp) {
return kFuzzTestWorkerSuccess;
}

if (action == WorkerAction::kGetBinaryId) {
WorkerDoGetBinaryId(manager);
return kFuzzTestWorkerSuccess;
Expand Down Expand Up @@ -952,8 +963,8 @@ FuzzTestWorkerStatus WorkerRun(const FuzzTestAdapterManager& manager) {
WorkerCheck(manager.ConstructAdapter != nullptr,
"ConstructAdapter is not defined");
FuzzTestAdapter adapter = {};
manager.ConstructAdapter(manager.ctx, /*diagnostic_sink=*/&diagnostic_sink,
&adapter);
manager.ConstructAdapter(manager.ctx,
/*diagnostic_sink=*/&diagnostic_sink, &adapter);
WORKER_CHECK_FOR_ERROR();
WorkerCheck(adapter.SetUpCoverageDomains != nullptr,
"SetUpCoverageDomains must be defined");
Expand Down Expand Up @@ -1000,7 +1011,11 @@ using ::fuzztest::internal::WorkerRun;

} // namespace

int FuzzTestWorkerIsRequired() { return GetWorkerFlags().present; }
int FuzzTestWorkerIsRequired() {
static int result = GetWorkerFlags().present &&
fuzztest::internal::GetWorkerAction().has_value();
return result;
}

FuzzTestWorkerStatus FuzzTestWorkerMaybeRun(
const FuzzTestAdapterManager* manager) {
Expand Down
Loading