@@ -185,7 +185,7 @@ static uint64_t TimeInUsec() {
185185}
186186
187187static 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
309309void 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
327327void 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
12191220extern " 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
12511252extern " C" void CentipedePrepareProcessing () {
@@ -1255,7 +1256,7 @@ extern "C" void CentipedePrepareProcessing() {
12551256
12561257extern " 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}
0 commit comments