[PATCH] D27921: [libFuzzer] Diff 26 - Update afl driver to use std clocks instead of posix API.

Marcos Pividori via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 19 08:38:21 PST 2016


mpividori created this revision.
mpividori added reviewers: kcc, zturner.
mpividori added a subscriber: llvm-commits.
mpividori set the repository for this revision to rL LLVM.

Repository:
  rL LLVM

https://reviews.llvm.org/D27921

Files:
  lib/Fuzzer/afl/afl_driver.cpp


Index: lib/Fuzzer/afl/afl_driver.cpp
===================================================================
--- lib/Fuzzer/afl/afl_driver.cpp
+++ lib/Fuzzer/afl/afl_driver.cpp
@@ -50,15 +50,15 @@
 
 */
 #include <assert.h>
+#include <chrono>
 #include <stdio.h>
 #include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 #include <errno.h>
 #include <signal.h>
 #include <sys/resource.h>
-#include <sys/time.h>
 // Platform detection. Copied from FuzzerInternal.h
 #ifdef __linux__
 #define LIBFUZZER_LINUX 1
@@ -104,7 +104,7 @@
 // Variables we need for writing to the extra stats file.
 static FILE *extra_stats_file = NULL;
 static uint32_t previous_peak_rss = 0;
-static time_t slowest_unit_time_secs = 0;
+auto slowest_unit_time_secs = std::chrono::seconds::zero();
 static const int kNumExtraStats = 2;
 static const char *kExtraStatsFormatString = "peak_rss_mb            : %u\n"
                                              "slowest_unit_time_sec  : %u\n";
@@ -262,7 +262,6 @@
   if (argc >= 2)
     N = atoi(argv[1]);
   assert(N > 0);
-  time_t unit_time_secs;
   int num_runs = 0;
   while (__afl_persistent_loop(N)) {
     ssize_t n_read = read(0, AflInputBuf, kMaxAflInputSize);
@@ -272,19 +271,15 @@
       uint8_t *copy = new uint8_t[n_read];
       memcpy(copy, AflInputBuf, n_read);
 
-      struct timeval unit_start_time;
-      CHECK_ERROR(gettimeofday(&unit_start_time, NULL) == 0,
-                  "Calling gettimeofday failed");
+      auto unit_start_time = std::chrono::system_clock::now();
 
       num_runs++;
       LLVMFuzzerTestOneInput(copy, n_read);
 
-      struct timeval unit_stop_time;
-      CHECK_ERROR(gettimeofday(&unit_stop_time, NULL) == 0,
-                  "Calling gettimeofday failed");
+      auto unit_time_secs = std::chrono::duration_cast<std::chrono::seconds>(
+        std::chrono::system_clock::now() - unit_start_time);
 
       // Update slowest_unit_time_secs if we see a new max.
-      unit_time_secs = unit_stop_time.tv_sec - unit_start_time.tv_sec;
       if (slowest_unit_time_secs < unit_time_secs)
         slowest_unit_time_secs = unit_time_secs;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27921.81956.patch
Type: text/x-patch
Size: 2140 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161219/86a90a2a/attachment.bin>


More information about the llvm-commits mailing list