Skip to content

Commit 7b6e707

Browse files
xinhaoyuancopybara-github
authored andcommitted
No public description
PiperOrigin-RevId: 764797536
1 parent 89005b7 commit 7b6e707

File tree

5 files changed

+45
-43
lines changed

5 files changed

+45
-43
lines changed

centipede/centipede_callbacks.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ std::string CentipedeCallbacks::ConstructRunnerFlags(
112112
std::string_view extra_flags, bool disable_coverage) {
113113
std::vector<std::string> flags = {
114114
"CENTIPEDE_RUNNER_FLAGS=",
115-
absl::StrCat("timeout_per_input=", env_.timeout_per_input),
116-
absl::StrCat("timeout_per_batch=", env_.timeout_per_batch),
115+
absl::StrCat("timeout_per_input_ms=", env_.timeout_per_input * 1000),
116+
absl::StrCat("timeout_per_batch_ms=", env_.timeout_per_batch * 1000),
117117
absl::StrCat("address_space_limit_mb=", env_.address_space_limit_mb),
118118
absl::StrCat("rss_limit_mb=", env_.rss_limit_mb),
119119
absl::StrCat("stack_limit_kb=", env_.stack_limit_kb),

centipede/runner.cc

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ static uint64_t TimeInUsec() {
185185
}
186186

187187
static void CheckWatchdogLimits() {
188-
const uint64_t curr_time = time(nullptr);
188+
const uint64_t curr_time_ms = TimeInUsec() / 1000;
189189
struct Resource {
190190
const char *what;
191191
const char *units;
@@ -194,23 +194,23 @@ static void CheckWatchdogLimits() {
194194
bool ignore_report;
195195
const char *failure;
196196
};
197-
const uint64_t input_start_time = state.input_start_time;
198-
const uint64_t batch_start_time = state.batch_start_time;
199-
if (input_start_time == 0 || batch_start_time == 0) return;
197+
const uint64_t input_start_time_ms = state.input_start_time_ms;
198+
const uint64_t batch_start_time_ms = state.batch_start_time_ms;
199+
if (input_start_time_ms == 0 || batch_start_time_ms == 0) return;
200200
const Resource resources[] = {
201201
{Resource{
202202
/*what=*/"Per-input timeout",
203-
/*units=*/"sec",
204-
/*value=*/curr_time - input_start_time,
205-
/*limit=*/state.run_time_flags.timeout_per_input,
203+
/*units=*/"ms",
204+
/*value=*/curr_time_ms - input_start_time_ms,
205+
/*limit=*/state.run_time_flags.timeout_per_input_ms,
206206
/*ignore_report=*/state.run_time_flags.ignore_timeout_reports != 0,
207207
/*failure=*/kExecutionFailurePerInputTimeout.data(),
208208
}},
209209
{Resource{
210210
/*what=*/"Per-batch timeout",
211-
/*units=*/"sec",
212-
/*value=*/curr_time - batch_start_time,
213-
/*limit=*/state.run_time_flags.timeout_per_batch,
211+
/*units=*/"ms",
212+
/*value=*/curr_time_ms - batch_start_time_ms,
213+
/*limit=*/state.run_time_flags.timeout_per_batch_ms,
214214
/*ignore_report=*/state.run_time_flags.ignore_timeout_reports != 0,
215215
/*failure=*/kExecutionFailurePerBatchTimeout.data(),
216216
}},
@@ -270,7 +270,7 @@ static void CheckWatchdogLimits() {
270270
sleep(1);
271271

272272
// No calls to ResetInputTimer() yet: input execution hasn't started.
273-
if (state.input_start_time == 0) continue;
273+
if (state.input_start_time_ms == 0) continue;
274274

275275
CheckWatchdogLimits();
276276
}
@@ -282,7 +282,7 @@ __attribute__((noinline)) void CheckStackLimit(uintptr_t sp) {
282282
// Check for the stack limit only if sp is inside the stack region.
283283
if (stack_limit > 0 && tls.stack_region_low &&
284284
tls.top_frame_sp - sp > stack_limit) {
285-
const bool test_not_running = state.input_start_time == 0;
285+
const bool test_not_running = state.input_start_time_ms == 0;
286286
if (test_not_running) return;
287287
if (stack_limit_exceeded.test_and_set()) return;
288288
fprintf(stderr,
@@ -308,11 +308,11 @@ void GlobalRunnerState::CleanUpDetachedTls() {
308308

309309
void GlobalRunnerState::StartWatchdogThread() {
310310
fprintf(stderr,
311-
"Starting watchdog thread: timeout_per_input: %" PRIu64
312-
" sec; timeout_per_batch: %" PRIu64 " sec; rss_limit_mb: %" PRIu64
311+
"Starting watchdog thread: timeout_per_input_ms: %" PRIu64
312+
" sec; timeout_per_batch_ms: %" PRIu64 " sec; rss_limit_mb: %" PRIu64
313313
" MB; stack_limit_kb: %" PRIu64 " KB\n",
314-
state.run_time_flags.timeout_per_input.load(),
315-
state.run_time_flags.timeout_per_batch,
314+
state.run_time_flags.timeout_per_input_ms.load(),
315+
state.run_time_flags.timeout_per_batch_ms,
316316
state.run_time_flags.rss_limit_mb.load(),
317317
state.run_time_flags.stack_limit_kb.load());
318318
pthread_t watchdog_thread;
@@ -325,12 +325,12 @@ void GlobalRunnerState::StartWatchdogThread() {
325325
}
326326

327327
void GlobalRunnerState::ResetTimers() {
328-
const auto curr_time = time(nullptr);
329-
input_start_time = curr_time;
330-
// batch_start_time is set only once -- just before the first input of the
328+
const auto curr_time_ms = TimeInUsec() / 1000;
329+
input_start_time_ms = curr_time_ms;
330+
// batch_start_time_ms is set only once -- just before the first input of the
331331
// batch is about to start running.
332-
if (batch_start_time == 0) {
333-
batch_start_time = curr_time;
332+
if (batch_start_time_ms == 0) {
333+
batch_start_time_ms = curr_time_ms;
334334
}
335335
}
336336

@@ -627,7 +627,7 @@ static void RunOneInput(const uint8_t *data, size_t size,
627627
int target_return_value = callbacks.Execute({data, size}) ? 0 : -1;
628628
state.stats.exec_time_usec = UsecSinceLast();
629629
CheckWatchdogLimits();
630-
if (fuzztest::internal::state.input_start_time.exchange(0) != 0) {
630+
if (fuzztest::internal::state.input_start_time_ms.exchange(0) != 0) {
631631
PostProcessCoverage(target_return_value);
632632
}
633633
state.stats.post_time_usec = UsecSinceLast();
@@ -1207,13 +1207,14 @@ extern "C" void CentipedeSetStackLimit(size_t stack_limit_kb) {
12071207
fuzztest::internal::state.run_time_flags.stack_limit_kb = stack_limit_kb;
12081208
}
12091209

1210-
extern "C" void CentipedeSetTimeoutPerInput(uint64_t timeout_per_input) {
1211-
fprintf(stderr,
1212-
"CentipedeSetTimeoutPerInput: changing timeout_per_input to %" PRIu64
1213-
"\n",
1214-
timeout_per_input);
1215-
fuzztest::internal::state.run_time_flags.timeout_per_input =
1216-
timeout_per_input;
1210+
extern "C" void CentipedeSetTimeoutPerInput(uint64_t timeout_per_input_ms) {
1211+
fprintf(
1212+
stderr,
1213+
"CentipedeSetTimeoutPerInput: changing timeout_per_input_ms to %" PRIu64
1214+
"\n",
1215+
timeout_per_input_ms);
1216+
fuzztest::internal::state.run_time_flags.timeout_per_input_ms =
1217+
timeout_per_input_ms;
12171218
}
12181219

12191220
extern "C" __attribute__((weak)) const char *absl_nullable
@@ -1244,8 +1245,8 @@ extern "C" void CentipedeEndExecutionBatch() {
12441245
_exit(EXIT_FAILURE);
12451246
}
12461247
in_execution_batch = false;
1247-
fuzztest::internal::state.input_start_time = 0;
1248-
fuzztest::internal::state.batch_start_time = 0;
1248+
fuzztest::internal::state.input_start_time_ms = 0;
1249+
fuzztest::internal::state.batch_start_time_ms = 0;
12491250
}
12501251

12511252
extern "C" void CentipedePrepareProcessing() {
@@ -1255,7 +1256,7 @@ extern "C" void CentipedePrepareProcessing() {
12551256

12561257
extern "C" void CentipedeFinalizeProcessing() {
12571258
fuzztest::internal::CheckWatchdogLimits();
1258-
if (fuzztest::internal::state.input_start_time.exchange(0) != 0) {
1259+
if (fuzztest::internal::state.input_start_time_ms.exchange(0) != 0) {
12591260
fuzztest::internal::PostProcessCoverage(/*target_return_value=*/0);
12601261
}
12611262
}

centipede/runner.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ struct RunTimeFlags {
6464
uint64_t callstack_level : 8;
6565
uint64_t use_counter_features : 1;
6666
uint64_t use_auto_dictionary : 1;
67-
std::atomic<uint64_t> timeout_per_input;
68-
uint64_t timeout_per_batch;
67+
std::atomic<uint64_t> timeout_per_input_ms;
68+
uint64_t timeout_per_batch_ms;
6969
std::atomic<uint64_t> stack_limit_kb;
7070
std::atomic<uint64_t> rss_limit_mb;
7171
uint64_t crossover_level;
@@ -171,8 +171,8 @@ struct GlobalRunnerState {
171171
/*callstack_level=*/HasIntFlag(":callstack_level=", 0),
172172
/*use_counter_features=*/HasFlag(":use_counter_features:"),
173173
/*use_auto_dictionary=*/HasFlag(":use_auto_dictionary:"),
174-
/*timeout_per_input=*/HasIntFlag(":timeout_per_input=", 0),
175-
/*timeout_per_batch=*/HasIntFlag(":timeout_per_batch=", 0),
174+
/*timeout_per_input_ms=*/HasIntFlag(":timeout_per_input_ms=", 0),
175+
/*timeout_per_batch_ms=*/HasIntFlag(":timeout_per_batch_ms=", 0),
176176
/*stack_limit_kb=*/HasIntFlag(":stack_limit_kb=", 0),
177177
/*rss_limit_mb=*/HasIntFlag(":rss_limit_mb=", 0),
178178
/*crossover_level=*/HasIntFlag(":crossover_level=", 50),
@@ -339,10 +339,10 @@ struct GlobalRunnerState {
339339

340340
// Per-input timer. Initially, zero. ResetInputTimer() sets it to the current
341341
// time.
342-
std::atomic<time_t> input_start_time;
342+
std::atomic<time_t> input_start_time_ms;
343343
// Per-batch timer. Initially, zero. ResetInputTimer() sets it to the current
344344
// time before the first input and never resets it.
345-
std::atomic<time_t> batch_start_time;
345+
std::atomic<time_t> batch_start_time_ms;
346346

347347
// The Watchdog thread sets this to true.
348348
std::atomic<bool> watchdog_thread_started;

centipede/runner_interface.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ extern "C" void CentipedeSetRssLimit(size_t rss_limit_mb);
7272
// Reconfigures the stack limit to `stack_limit_kb` - 0 indicates no limit.
7373
extern "C" void CentipedeSetStackLimit(size_t stack_limit_kb);
7474

75-
// Reconfigures `timeout_per_input` accordingly in seconds - 0 means no timeout.
76-
extern "C" void CentipedeSetTimeoutPerInput(uint64_t timeout_per_input);
75+
// Reconfigures input timeout to `timeout_per_input_ms` - 0 means no timeout.
76+
extern "C" void CentipedeSetTimeoutPerInput(uint64_t timeout_per_input_ms);
7777

7878
// An overridable function to get the runner flags for configuring the runner
7979
// during the initialization. The default implementation (as a weak function)

fuzztest/internal/centipede_adaptor.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,8 @@ void PopulateTestLimitsToCentipedeRunner(const Configuration& configuration) {
583583
absl::FPrintF(GetStderr(),
584584
"[.] Per-input time limit set to: %" PRId64 "s\n",
585585
time_limit_seconds);
586-
CentipedeSetTimeoutPerInput(time_limit_seconds);
586+
CentipedeSetTimeoutPerInput(/*timeout_per_input_ms=*/time_limit_seconds *
587+
1000);
587588
}
588589
}
589590

0 commit comments

Comments
 (0)