[libFuzzer] When -test_single_input crashes the test it is not necessary to write...
authorKostya Serebryany <kcc@google.com>
Fri, 16 Oct 2015 22:41:47 +0000 (22:41 +0000)
committerKostya Serebryany <kcc@google.com>
Fri, 16 Oct 2015 22:41:47 +0000 (22:41 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250564 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Fuzzer/FuzzerDriver.cpp
lib/Fuzzer/FuzzerIO.cpp
lib/Fuzzer/FuzzerInternal.h
lib/Fuzzer/FuzzerLoop.cpp
lib/Fuzzer/test/fuzzer.test

index b5cf231e0f2036c9873a517114ef7c16a968d85a..55d1491c7cf3f4553efe24b8226a84a316be01d2 100644 (file)
@@ -277,12 +277,17 @@ int FuzzerDriver(const std::vector<std::string> &Args,
       return 1;
   if (Flags.verbosity > 0 && !Options.Dictionary.empty())
     Printf("Dictionary: %zd entries\n", Options.Dictionary.size());
+  Options.SaveArtifacts = !Flags.test_single_input;
 
   Fuzzer F(USF, Options);
 
   if (Flags.apply_tokens)
     return ApplyTokens(F, Flags.apply_tokens);
 
+  // Timer
+  if (Flags.timeout > 0)
+    SetTimer(Flags.timeout / 2 + 1);
+
   if (Flags.test_single_input)
     return RunOneTest(&F, Flags.test_single_input);
 
@@ -294,10 +299,6 @@ int FuzzerDriver(const std::vector<std::string> &Args,
     Printf("Seed: %u\n", Seed);
   USF.GetRand().ResetSeed(Seed);
 
-  // Timer
-  if (Flags.timeout > 0)
-    SetTimer(Flags.timeout / 2 + 1);
-
   if (Flags.verbosity >= 2) {
     Printf("Tokens: {");
     for (auto &T : Options.Tokens)
index b6ffb752de310dd8afbf78c15d4ce8ee6316894f..4bb2df5d71ae6f9f25eb693beac53b62287ed89e 100644 (file)
@@ -49,6 +49,10 @@ static std::vector<std::string> ListFilesInDir(const std::string &Dir,
 
 Unit FileToVector(const std::string &Path) {
   std::ifstream T(Path);
+  if (!T) {
+    Printf("No such directory: %s; exiting\n", Path.c_str());
+    exit(1);
+  }
   return Unit((std::istreambuf_iterator<char>(T)),
               std::istreambuf_iterator<char>());
 }
index 500989072c39a941afb5e6228b99b5c2a680d5c6..c672f23d95f18b0dac3469e280c481041524a21a 100644 (file)
@@ -93,6 +93,7 @@ class Fuzzer {
     std::string ArtifactPrefix = "./";
     std::vector<std::string> Tokens;
     std::vector<Unit> Dictionary;
+    bool SaveArtifacts = true;
   };
   Fuzzer(UserSuppliedFuzzer &USF, FuzzingOptions Options);
   void AddToCorpus(const Unit &U) { Corpus.push_back(U); }
index ec0b1176e2854fa5f004f616d3dd7446028e31de..9b238cb05b143e2a290b4bba84b2b0897521af53 100644 (file)
@@ -237,6 +237,8 @@ void Fuzzer::WriteToOutputCorpus(const Unit &U) {
 }
 
 void Fuzzer::WriteUnitToFileWithPrefix(const Unit &U, const char *Prefix) {
+  if (!Options.SaveArtifacts)
+    return;
   std::string Path = Options.ArtifactPrefix + Prefix + Hash(U);
   WriteToFile(U, Path);
   Printf("artifact_prefix='%s'; Test unit written to %s\n",
index f3794dc3d3803fbdb988ff55359caef80286d418..dccc5e482500649f00ef0899aa11be6f8f0777ea 100644 (file)
@@ -1,7 +1,8 @@
 CHECK: BINGO
 
 RUN: LLVMFuzzer-SimpleTest 2>&1 | FileCheck %s
-RUN: LLVMFuzzer-SimpleTest -test_single_input=%S/hi.txt 2>&1 | FileCheck %s 
+RUN: not LLVMFuzzer-NullDerefTest -test_single_input=%S/hi.txt 2>&1 | FileCheck %s --check-prefix=SingleInput
+SingleInput-NOT: Test unit written to ./crash-
 
 RUN: not LLVMFuzzer-InfiniteTest -timeout=2 2>&1 | FileCheck %s --check-prefix=InfiniteTest
 InfiniteTest: ALARM: working on the last Unit for
@@ -14,6 +15,10 @@ RUN: not LLVMFuzzer-TimeoutTest -timeout=5 2>&1 | FileCheck %s --check-prefix=Ti
 TimeoutTest: ALARM: working on the last Unit for
 TimeoutTest: Test unit written to ./timeout-
 
+RUN: not LLVMFuzzer-TimeoutTest -timeout=5 -test_single_input=%S/hi.txt 2>&1 | FileCheck %s --check-prefix=SingleInputTimeoutTest
+SingleInputTimeoutTest: ALARM: working on the last Unit for
+SingleInputTimeoutTest-NOT: Test unit written to ./timeout-
+
 RUN: not LLVMFuzzer-NullDerefTest 2>&1 | FileCheck %s --check-prefix=NullDerefTest
 NullDerefTest: Test unit written to ./crash-
 RUN: not LLVMFuzzer-NullDerefTest  -artifact_prefix=ZZZ 2>&1 | FileCheck %s --check-prefix=NullDerefTestPrefix