diff --git a/centipede/centipede_callbacks.cc b/centipede/centipede_callbacks.cc index a9e0d7dc..3f6f817d 100644 --- a/centipede/centipede_callbacks.cc +++ b/centipede/centipede_callbacks.cc @@ -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(); @@ -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()`. diff --git a/centipede/centipede_test.cc b/centipede/centipede_test.cc index dac43024..c06298bc 100644 --- a/centipede/centipede_test.cc +++ b/centipede/centipede_test.cc @@ -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" @@ -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 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 =