[llvm] r260649 - [libFuzzer] make -runs=N flag also affect the simple runner (will execute every input N times)

Kostya Serebryany via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 11 18:32:03 PST 2016


Author: kcc
Date: Thu Feb 11 20:32:03 2016
New Revision: 260649

URL: http://llvm.org/viewvc/llvm-project?rev=260649&view=rev
Log:
[libFuzzer] make -runs=N flag also affect the simple runner (will execute every input N times)

Added:
    llvm/trunk/lib/Fuzzer/test/NthRunCrashTest.cpp
Modified:
    llvm/trunk/lib/Fuzzer/FuzzerDriver.cpp
    llvm/trunk/lib/Fuzzer/test/CMakeLists.txt
    llvm/trunk/lib/Fuzzer/test/fuzzer.test

Modified: llvm/trunk/lib/Fuzzer/FuzzerDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerDriver.cpp?rev=260649&r1=260648&r2=260649&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerDriver.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerDriver.cpp Thu Feb 11 20:32:03 2016
@@ -335,10 +335,13 @@ int FuzzerDriver(const std::vector<std::
   }
 
   if (AllInputsAreFiles()) {
-    Printf("%s: Running %zd inputs.\n", ProgName->c_str(), Inputs->size());
+    int Runs = std::max(1, Flags.runs);
+    Printf("%s: Running %zd inputs %d time(s) each.\n", ProgName->c_str(),
+           Inputs->size(), Runs);
     for (auto &Path : *Inputs) {
       auto StartTime = system_clock::now();
-      RunOneTest(&F, Path.c_str());
+      while (Runs-- > 0)
+        RunOneTest(&F, Path.c_str());
       auto StopTime = system_clock::now();
       auto MS = duration_cast<milliseconds>(StopTime - StartTime).count();
       Printf("%s: %zd ms\n", Path.c_str(), (long)MS);

Modified: llvm/trunk/lib/Fuzzer/test/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/CMakeLists.txt?rev=260649&r1=260648&r2=260649&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/CMakeLists.txt (original)
+++ llvm/trunk/lib/Fuzzer/test/CMakeLists.txt Thu Feb 11 20:32:03 2016
@@ -22,6 +22,7 @@ set(Tests
   MemcmpTest
   LeakTest
   NullDerefTest
+  NthRunCrashTest
   RepeatedMemcmp
   SimpleCmpTest
   SimpleDictionaryTest

Added: llvm/trunk/lib/Fuzzer/test/NthRunCrashTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/NthRunCrashTest.cpp?rev=260649&view=auto
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/NthRunCrashTest.cpp (added)
+++ llvm/trunk/lib/Fuzzer/test/NthRunCrashTest.cpp Thu Feb 11 20:32:03 2016
@@ -0,0 +1,15 @@
+// Crash on the N-th execution.
+#include <cstdint>
+#include <cstddef>
+#include <iostream>
+
+static int Counter;
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
+  if (Counter++ == 1000) {
+    std::cout << "BINGO; Found the target, exiting\n";
+    exit(1);
+  }
+  return 0;
+}
+

Modified: llvm/trunk/lib/Fuzzer/test/fuzzer.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/fuzzer.test?rev=260649&r1=260648&r2=260649&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/fuzzer.test (original)
+++ llvm/trunk/lib/Fuzzer/test/fuzzer.test Thu Feb 11 20:32:03 2016
@@ -53,10 +53,16 @@ RUN: echo aaa > %tmp/SINGLE_INPUTS/aaa
 RUN: echo bbb > %tmp/SINGLE_INPUTS/bbb
 RUN: LLVMFuzzer-SimpleTest %tmp/SINGLE_INPUTS/aaa %tmp/SINGLE_INPUTS/bbb 2>&1 | FileCheck %s --check-prefix=SINGLE_INPUTS
 RUN: rm -rf  %tmp/SINGLE_INPUTS
-SINGLE_INPUTS: LLVMFuzzer-SimpleTest: Running 2 inputs.
+SINGLE_INPUTS: LLVMFuzzer-SimpleTest: Running 2 inputs 1 time(s) each.
 SINGLE_INPUTS: aaa:
 SINGLE_INPUTS: bbb:
 
 RUN: not LLVMFuzzer-LeakTest -runs=10 2>&1 | FileCheck %s --check-prefix=LEAK
 LEAK: ERROR: LeakSanitizer: detected memory leaks
 LEAK-NOT: DEATH:
+
+RUN: echo abcd > %t/NthRunCrashTest.in
+RUN: LLVMFuzzer-NthRunCrashTest %t/NthRunCrashTest.in
+RUN: LLVMFuzzer-NthRunCrashTest %t/NthRunCrashTest.in -runs=10
+RUN: not LLVMFuzzer-NthRunCrashTest %t/NthRunCrashTest.in -runs=10000 2>&1 | FileCheck %s
+RUN: rm %t/NthRunCrashTest.in




More information about the llvm-commits mailing list