@@ -185,7 +185,7 @@ static uint64_t TimeInUsec() {
185
185
}
186
186
187
187
static void CheckWatchdogLimits () {
188
- const uint64_t curr_time = time ( nullptr ) ;
188
+ const uint64_t curr_time_ms = TimeInUsec () / 1000 ;
189
189
struct Resource {
190
190
const char *what;
191
191
const char *units;
@@ -194,23 +194,23 @@ static void CheckWatchdogLimits() {
194
194
bool ignore_report;
195
195
const char *failure;
196
196
};
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 ;
200
200
const Resource resources[] = {
201
201
{Resource{
202
202
/* 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 ,
206
206
/* ignore_report=*/ state.run_time_flags .ignore_timeout_reports != 0 ,
207
207
/* failure=*/ kExecutionFailurePerInputTimeout .data (),
208
208
}},
209
209
{Resource{
210
210
/* 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 ,
214
214
/* ignore_report=*/ state.run_time_flags .ignore_timeout_reports != 0 ,
215
215
/* failure=*/ kExecutionFailurePerBatchTimeout .data (),
216
216
}},
@@ -270,7 +270,7 @@ static void CheckWatchdogLimits() {
270
270
sleep (1 );
271
271
272
272
// 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 ;
274
274
275
275
CheckWatchdogLimits ();
276
276
}
@@ -282,7 +282,7 @@ __attribute__((noinline)) void CheckStackLimit(uintptr_t sp) {
282
282
// Check for the stack limit only if sp is inside the stack region.
283
283
if (stack_limit > 0 && tls.stack_region_low &&
284
284
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 ;
286
286
if (test_not_running) return ;
287
287
if (stack_limit_exceeded.test_and_set ()) return ;
288
288
fprintf (stderr,
@@ -308,11 +308,11 @@ void GlobalRunnerState::CleanUpDetachedTls() {
308
308
309
309
void GlobalRunnerState::StartWatchdogThread () {
310
310
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
313
313
" 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 ,
316
316
state.run_time_flags .rss_limit_mb .load (),
317
317
state.run_time_flags .stack_limit_kb .load ());
318
318
pthread_t watchdog_thread;
@@ -325,12 +325,12 @@ void GlobalRunnerState::StartWatchdogThread() {
325
325
}
326
326
327
327
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
331
331
// 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 ;
334
334
}
335
335
}
336
336
@@ -627,7 +627,7 @@ static void RunOneInput(const uint8_t *data, size_t size,
627
627
int target_return_value = callbacks.Execute ({data, size}) ? 0 : -1 ;
628
628
state.stats .exec_time_usec = UsecSinceLast ();
629
629
CheckWatchdogLimits ();
630
- if (fuzztest::internal::state.input_start_time .exchange (0 ) != 0 ) {
630
+ if (fuzztest::internal::state.input_start_time_ms .exchange (0 ) != 0 ) {
631
631
PostProcessCoverage (target_return_value);
632
632
}
633
633
state.stats .post_time_usec = UsecSinceLast ();
@@ -1207,13 +1207,14 @@ extern "C" void CentipedeSetStackLimit(size_t stack_limit_kb) {
1207
1207
fuzztest::internal::state.run_time_flags .stack_limit_kb = stack_limit_kb;
1208
1208
}
1209
1209
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;
1217
1218
}
1218
1219
1219
1220
extern " C" __attribute__((weak)) const char *absl_nullable
@@ -1244,8 +1245,8 @@ extern "C" void CentipedeEndExecutionBatch() {
1244
1245
_exit (EXIT_FAILURE);
1245
1246
}
1246
1247
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 ;
1249
1250
}
1250
1251
1251
1252
extern " C" void CentipedePrepareProcessing () {
@@ -1255,7 +1256,7 @@ extern "C" void CentipedePrepareProcessing() {
1255
1256
1256
1257
extern " C" void CentipedeFinalizeProcessing () {
1257
1258
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 ) {
1259
1260
fuzztest::internal::PostProcessCoverage (/* target_return_value=*/ 0 );
1260
1261
}
1261
1262
}
0 commit comments