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
19 changes: 16 additions & 3 deletions centipede/centipede_callbacks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -631,9 +631,22 @@ bool CentipedeCallbacks::GetSeedsViaExternalBinary(
cmd_options.stderr_file = execute_log_path_;
cmd_options.temp_file_path = temp_input_file_path_;
Command cmd{binary, std::move(cmd_options)};
const int retval = cmd.Execute();
const int retval = [&] {
if (!cmd.ExecuteAsync()) {
FUZZTEST_LOG(ERROR) << "Failed to execute seeding command "
<< cmd.ToString();
return EXIT_FAILURE;
}
const auto wait_result = cmd.Wait(GetStopTime());
if (!wait_result.has_value()) {
FUZZTEST_LOG(ERROR) << "Failed to wait for the seeding command "
<< cmd.ToString();
return EXIT_FAILURE;
}
return *wait_result;
}();

if (env_.print_runner_log) {
if (env_.print_runner_log || retval != EXIT_SUCCESS) {
FUZZTEST_LOG(INFO) << "Getting seeds via external binary returns "
<< retval;
PrintExecutionLog();
Expand All @@ -659,7 +672,7 @@ bool CentipedeCallbacks::GetSeedsViaExternalBinary(
FUZZTEST_LOG_IF(ERROR, error)
<< "Failed to remove seed inputs directory: " << error.message();

return retval == 0;
return retval == EXIT_SUCCESS;
}

// See also: `DumpSerializedTargetConfigToFile()`.
Expand Down
15 changes: 15 additions & 0 deletions centipede/centipede_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "gtest/gtest.h"
#include "absl/container/flat_hash_set.h"
#include "absl/strings/str_cat.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
#include "./centipede/centipede_callbacks.h"
#include "./centipede/centipede_default_callbacks.h"
Expand Down Expand Up @@ -1200,6 +1201,20 @@ TEST_F(CentipedeWithTemporaryLocalDir,
EXPECT_NE(inputs, mutants);
}

TEST_F(CentipedeWithTemporaryLocalDir,
GetsSeedViaExternalBinaryStopsAfterStopTime) {
Environment env;
env.binary = "sleep 100";
CentipedeDefaultCallbacks callbacks(env);
const auto start = absl::Now();
ClearEarlyStopRequestAndSetStopTime(start + absl::Seconds(3));
std::vector<ByteArray> seeds;
callbacks.GetSeeds(/*num_seeds=*/1, seeds);
// Give it some slack to stop in 5s.
EXPECT_LE(absl::Now() - start, absl::Seconds(5));
ClearEarlyStopRequestAndSetStopTime(absl::InfiniteFuture());
}

TEST_F(CentipedeWithTemporaryLocalDir, HangingFuzzTargetExitsAfterTimeout) {
Environment env;
env.binary =
Expand Down
Loading