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
32 changes: 16 additions & 16 deletions centipede/runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -194,22 +194,22 @@ 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(),
}},
{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(),
Expand Down Expand Up @@ -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();
}
Expand All @@ -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,
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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() {
Expand All @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions centipede/runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,10 @@ struct GlobalRunnerState {

// Per-input timer. Initially, zero. ResetInputTimer() sets it to the current
// time.
std::atomic<time_t> input_start_time;
std::atomic<uint64_t> 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<time_t> batch_start_time;
std::atomic<uint64_t> batch_start_time_us;

// The Watchdog thread sets this to true.
std::atomic<bool> watchdog_thread_started;
Expand Down
2 changes: 1 addition & 1 deletion fuzztest/internal/centipede_adaptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down