Skip to content

Commit

Permalink
#Centipede Log the execution log of a custom mutator in case it misbe…
Browse files Browse the repository at this point in the history
…haves.

This will give us more clue in cases when a long fuzzing session check fails
with an unreliable custom mutator.

PiperOrigin-RevId: 696933388
  • Loading branch information
fniksic authored and copybara-github committed Nov 15, 2024
1 parent b490b49 commit 7078295
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
28 changes: 20 additions & 8 deletions centipede/centipede_callbacks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,7 @@ int CentipedeCallbacks::ExecuteCentipedeSancovBinaryWithShmem(
<< env_.shmem_size_mb;
}

if (env_.print_runner_log) {
std::string log_text;
ReadFromLocalFile(execute_log_path_, log_text);
for (const auto &log_line :
absl::StrSplit(absl::StripAsciiWhitespace(log_text), '\n')) {
LOG(INFO).NoPrefix() << "LOG: " << log_line;
}
}
if (env_.print_runner_log) PrintExecutionLog();

if (retval != EXIT_SUCCESS) {
ReadFromLocalFile(execute_log_path_, batch_result.log());
Expand Down Expand Up @@ -312,6 +305,11 @@ bool CentipedeCallbacks::MutateViaExternalBinary(
int retval = cmd.Execute();
inputs_blobseq_.ReleaseSharedMemory(); // Inputs are already consumed.

if (retval != EXIT_SUCCESS) {
LOG(WARNING) << "Custom mutator failed with exit code " << retval;
PrintExecutionLog();
}

// Read all mutants.
for (size_t i = 0; i < mutants.size(); ++i) {
auto blob = outputs_blobseq_.Read();
Expand Down Expand Up @@ -364,4 +362,18 @@ size_t CentipedeCallbacks::LoadDictionary(std::string_view dictionary_path) {
return unpacked_dictionary.size();
}

void CentipedeCallbacks::PrintExecutionLog() const {
if (!std::filesystem::exists(execute_log_path_)) {
LOG(WARNING) << "Log file for the last executed binary does not exist: "
<< execute_log_path_;
return;
}
std::string log_text;
ReadFromLocalFile(execute_log_path_, log_text);
for (const auto &log_line :
absl::StrSplit(absl::StripAsciiWhitespace(log_text), '\n')) {
LOG(INFO).NoPrefix() << "LOG: " << log_line;
}
}

} // namespace centipede
3 changes: 3 additions & 0 deletions centipede/centipede_callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ class CentipedeCallbacks {
// creates one if needed.
Command &GetOrCreateCommandForBinary(std::string_view binary);

// Prints the execution log from the last executed binary.
void PrintExecutionLog() const;

// Variables required for ExecuteCentipedeSancovBinaryWithShmem.
// They are computed in CTOR, to avoid extra computation in the hot loop.
std::string temp_dir_ = TemporaryLocalDirPath();
Expand Down

0 comments on commit 7078295

Please sign in to comment.