Skip to content

Commit f4e3a6e

Browse files
xinhaoyuancopybara-github
authored andcommitted
No public description
PiperOrigin-RevId: 949720443
1 parent df6fca2 commit f4e3a6e

1 file changed

Lines changed: 24 additions & 9 deletions

File tree

centipede/engine_worker.cc

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <cstdlib>
2828
#include <cstring>
2929
#include <memory>
30+
#include <optional>
3031
#include <string>
3132
#include <string_view>
3233
#include <type_traits>
@@ -218,6 +219,7 @@ enum class WorkerAction {
218219
kTestGetSeeds,
219220
kTestMutate,
220221
kTestExecute,
222+
kNoOp,
221223
};
222224

223225
constexpr std::string_view kWorkerBinaryIdOutputFlagHeader =
@@ -431,8 +433,11 @@ int GetCrossOverLevel() {
431433
return result;
432434
}
433435

434-
WorkerAction GetWorkerAction() {
435-
static WorkerAction worker_action = [] {
436+
std::optional<WorkerAction> GetWorkerAction() {
437+
static auto worker_action = []() -> std::optional<WorkerAction> {
438+
if (HasWorkerSwitchFlag("dump_configuration")) {
439+
return WorkerAction::kNoOp;
440+
}
436441
if (HasWorkerSwitchFlag("dump_binary_id")) {
437442
return WorkerAction::kGetBinaryId;
438443
}
@@ -443,7 +448,9 @@ WorkerAction GetWorkerAction() {
443448
return WorkerAction::kTestGetSeeds;
444449
}
445450
auto* inputs_blobseq = GetInputsBlobSequence();
446-
WorkerCheck(inputs_blobseq != nullptr, "input blob sequence is not found");
451+
if (inputs_blobseq == nullptr) {
452+
return std::nullopt;
453+
}
447454
auto request_type_blob = inputs_blobseq->Read();
448455
if (IsMutationRequest(request_type_blob)) {
449456
inputs_blobseq->Reset();
@@ -453,9 +460,7 @@ WorkerAction GetWorkerAction() {
453460
inputs_blobseq->Reset();
454461
return WorkerAction::kTestExecute;
455462
}
456-
WorkerCheck(false, "unknown worker action from the flags");
457-
// should not reach here.
458-
std::abort();
463+
return std::nullopt;
459464
}();
460465
return worker_action;
461466
}
@@ -908,6 +913,12 @@ FuzzTestWorkerStatus WorkerRun(const FuzzTestAdapterManager& manager) {
908913
}
909914

910915
const auto action = GetWorkerAction();
916+
WorkerCheck(action.has_value(), "No worker action to run");
917+
918+
if (action == WorkerAction::kNoOp) {
919+
return kFuzzTestWorkerSuccess;
920+
}
921+
911922
if (action == WorkerAction::kGetBinaryId) {
912923
WorkerDoGetBinaryId(manager);
913924
return kFuzzTestWorkerSuccess;
@@ -952,8 +963,8 @@ FuzzTestWorkerStatus WorkerRun(const FuzzTestAdapterManager& manager) {
952963
WorkerCheck(manager.ConstructAdapter != nullptr,
953964
"ConstructAdapter is not defined");
954965
FuzzTestAdapter adapter = {};
955-
manager.ConstructAdapter(manager.ctx, /*diagnostic_sink=*/&diagnostic_sink,
956-
&adapter);
966+
manager.ConstructAdapter(manager.ctx,
967+
/*diagnostic_sink=*/&diagnostic_sink, &adapter);
957968
WORKER_CHECK_FOR_ERROR();
958969
WorkerCheck(adapter.SetUpCoverageDomains != nullptr,
959970
"SetUpCoverageDomains must be defined");
@@ -1000,7 +1011,11 @@ using ::fuzztest::internal::WorkerRun;
10001011

10011012
} // namespace
10021013

1003-
int FuzzTestWorkerIsRequired() { return GetWorkerFlags().present; }
1014+
int FuzzTestWorkerIsRequired() {
1015+
static int result = GetWorkerFlags().present &&
1016+
fuzztest::internal::GetWorkerAction().has_value();
1017+
return result;
1018+
}
10041019

10051020
FuzzTestWorkerStatus FuzzTestWorkerMaybeRun(
10061021
const FuzzTestAdapterManager* manager) {

0 commit comments

Comments
 (0)