From f41132792f457be67aa001599f545d8a82ef923b Mon Sep 17 00:00:00 2001 From: Xinhao Yuan Date: Thu, 29 May 2025 11:34:03 -0700 Subject: [PATCH] No public description PiperOrigin-RevId: 764815381 --- centipede/runner.cc | 32 +++++++++++++------------- centipede/runner.h | 4 ++-- fuzztest/internal/centipede_adaptor.cc | 2 +- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/centipede/runner.cc b/centipede/runner.cc index d998350b5..305511a71 100644 --- a/centipede/runner.cc +++ b/centipede/runner.cc @@ -185,7 +185,7 @@ static uint64_t TimeInUsec() { } static void CheckWatchdogLimits() { - const uint64_t curr_time = time(nullptr); + const uint64_t curr_time_us = TimeInUsec(); struct Resource { const char *what; const char *units; @@ -194,14 +194,14 @@ static void CheckWatchdogLimits() { bool ignore_report; const char *failure; }; - const uint64_t input_start_time = state.input_start_time; - const uint64_t batch_start_time = state.batch_start_time; - if (input_start_time == 0 || batch_start_time == 0) return; + const uint64_t input_start_time_us = state.input_start_time_us; + const uint64_t batch_start_time_us = state.batch_start_time_us; + if (input_start_time_us == 0 || batch_start_time_us == 0) return; const Resource resources[] = { {Resource{ /*what=*/"Per-input timeout", /*units=*/"sec", - /*value=*/curr_time - input_start_time, + /*value=*/(curr_time_us - input_start_time_us) / 1000000, /*limit=*/state.run_time_flags.timeout_per_input, /*ignore_report=*/state.run_time_flags.ignore_timeout_reports != 0, /*failure=*/kExecutionFailurePerInputTimeout.data(), @@ -209,7 +209,7 @@ static void CheckWatchdogLimits() { {Resource{ /*what=*/"Per-batch timeout", /*units=*/"sec", - /*value=*/curr_time - batch_start_time, + /*value=*/(curr_time_us - batch_start_time_us) / 1000000, /*limit=*/state.run_time_flags.timeout_per_batch, /*ignore_report=*/state.run_time_flags.ignore_timeout_reports != 0, /*failure=*/kExecutionFailurePerBatchTimeout.data(), @@ -270,7 +270,7 @@ static void CheckWatchdogLimits() { sleep(1); // No calls to ResetInputTimer() yet: input execution hasn't started. - if (state.input_start_time == 0) continue; + if (state.input_start_time_us == 0) continue; CheckWatchdogLimits(); } @@ -282,7 +282,7 @@ __attribute__((noinline)) void CheckStackLimit(uintptr_t sp) { // Check for the stack limit only if sp is inside the stack region. if (stack_limit > 0 && tls.stack_region_low && tls.top_frame_sp - sp > stack_limit) { - const bool test_not_running = state.input_start_time == 0; + const bool test_not_running = state.input_start_time_us == 0; if (test_not_running) return; if (stack_limit_exceeded.test_and_set()) return; fprintf(stderr, @@ -325,12 +325,12 @@ void GlobalRunnerState::StartWatchdogThread() { } void GlobalRunnerState::ResetTimers() { - const auto curr_time = time(nullptr); - input_start_time = curr_time; + const auto curr_time_us = TimeInUsec(); + input_start_time_us = curr_time_us; // batch_start_time is set only once -- just before the first input of the // batch is about to start running. - if (batch_start_time == 0) { - batch_start_time = curr_time; + if (batch_start_time_us == 0) { + batch_start_time_us = curr_time_us; } } @@ -627,7 +627,7 @@ static void RunOneInput(const uint8_t *data, size_t size, int target_return_value = callbacks.Execute({data, size}) ? 0 : -1; state.stats.exec_time_usec = UsecSinceLast(); CheckWatchdogLimits(); - if (fuzztest::internal::state.input_start_time.exchange(0) != 0) { + if (fuzztest::internal::state.input_start_time_us.exchange(0) != 0) { PostProcessCoverage(target_return_value); } state.stats.post_time_usec = UsecSinceLast(); @@ -1244,8 +1244,8 @@ extern "C" void CentipedeEndExecutionBatch() { _exit(EXIT_FAILURE); } in_execution_batch = false; - fuzztest::internal::state.input_start_time = 0; - fuzztest::internal::state.batch_start_time = 0; + fuzztest::internal::state.input_start_time_us = 0; + fuzztest::internal::state.batch_start_time_us = 0; } extern "C" void CentipedePrepareProcessing() { @@ -1255,7 +1255,7 @@ extern "C" void CentipedePrepareProcessing() { extern "C" void CentipedeFinalizeProcessing() { fuzztest::internal::CheckWatchdogLimits(); - if (fuzztest::internal::state.input_start_time.exchange(0) != 0) { + if (fuzztest::internal::state.input_start_time_us.exchange(0) != 0) { fuzztest::internal::PostProcessCoverage(/*target_return_value=*/0); } } diff --git a/centipede/runner.h b/centipede/runner.h index 8e4ff8eff..9d9ecdedc 100644 --- a/centipede/runner.h +++ b/centipede/runner.h @@ -339,10 +339,10 @@ struct GlobalRunnerState { // Per-input timer. Initially, zero. ResetInputTimer() sets it to the current // time. - std::atomic input_start_time; + std::atomic input_start_time_us; // Per-batch timer. Initially, zero. ResetInputTimer() sets it to the current // time before the first input and never resets it. - std::atomic batch_start_time; + std::atomic batch_start_time_us; // The Watchdog thread sets this to true. std::atomic watchdog_thread_started; diff --git a/fuzztest/internal/centipede_adaptor.cc b/fuzztest/internal/centipede_adaptor.cc index 7eb0e8785..3aec123f7 100644 --- a/fuzztest/internal/centipede_adaptor.cc +++ b/fuzztest/internal/centipede_adaptor.cc @@ -191,7 +191,7 @@ fuzztest::internal::Environment CreateCentipedeEnvironmentFromConfiguration( const Configuration& configuration, absl::string_view workdir, absl::string_view test_name, RunMode run_mode) { fuzztest::internal::Environment env = CreateDefaultCentipedeEnvironment(); - constexpr absl::Duration kUnitTestDefaultDuration = absl::Seconds(3); + constexpr absl::Duration kUnitTestDefaultDuration = absl::Seconds(1); env.fuzztest_single_test_mode = true; if (configuration.time_limit_per_input < absl::InfiniteDuration()) { const int64_t time_limit_seconds =