summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2017-07-13 01:56:37 +0000
committerKostya Serebryany <kcc@google.com>2017-07-13 01:56:37 +0000
commit8050ea16b55992ef7bf8e2e30530d9aff2851a18 (patch)
tree5723ce6aa80a2375e4fa91fcd9c6ac171c02bda4
parent094105a0c73070a8ebfe46d575b352e16ecc139e (diff)
downloadbcm5719-llvm-8050ea16b55992ef7bf8e2e30530d9aff2851a18.tar.gz
bcm5719-llvm-8050ea16b55992ef7bf8e2e30530d9aff2851a18.zip
[libFuzzer] make sure that -reduce_inputs=1 deletes redundant files in the corpus
llvm-svn: 307875
-rw-r--r--llvm/lib/Fuzzer/FuzzerCorpus.h11
-rw-r--r--llvm/lib/Fuzzer/test/reduce_inputs.test13
2 files changed, 21 insertions, 3 deletions
diff --git a/llvm/lib/Fuzzer/FuzzerCorpus.h b/llvm/lib/Fuzzer/FuzzerCorpus.h
index c4d1db74014..218ae5b6ac4 100644
--- a/llvm/lib/Fuzzer/FuzzerCorpus.h
+++ b/llvm/lib/Fuzzer/FuzzerCorpus.h
@@ -139,6 +139,9 @@ class InputCorpus {
}
void Replace(InputInfo *II, const Unit &U) {
+ assert(II->U.size());
+ Hashes.erase(Sha1ToString(II->Sha1));
+ DeleteFile(*II);
ComputeSHA1(U.data(), U.size(), II->Sha1);
Hashes.insert(Sha1ToString(II->Sha1));
II->U = U;
@@ -182,10 +185,14 @@ class InputCorpus {
Printf("\n");
}
- void DeleteInput(size_t Idx) {
- InputInfo &II = *Inputs[Idx];
+ void DeleteFile(const InputInfo &II) {
if (!OutputCorpus.empty() && II.MayDeleteFile)
RemoveFile(DirPlusFile(OutputCorpus, Sha1ToString(II.Sha1)));
+ }
+
+ void DeleteInput(size_t Idx) {
+ InputInfo &II = *Inputs[Idx];
+ DeleteFile(II);
Unit().swap(II.U);
if (FeatureDebug)
Printf("EVICTED %zd\n", Idx);
diff --git a/llvm/lib/Fuzzer/test/reduce_inputs.test b/llvm/lib/Fuzzer/test/reduce_inputs.test
index cc803d789d8..a4a5c57123d 100644
--- a/llvm/lib/Fuzzer/test/reduce_inputs.test
+++ b/llvm/lib/Fuzzer/test/reduce_inputs.test
@@ -1,2 +1,13 @@
+# Test -reduce_inputs=1
+
+RUN: rm -rf %t/C
+RUN: mkdir -p %t/C
+RUN: LLVMFuzzer-ShrinkControlFlowSimpleTest -exit_on_item=0eb8e4ed029b774d80f2b66408203801cb982a60 -reduce_inputs=1 -runs=1000000 %t/C 2>&1 | FileCheck %s
CHECK: INFO: found item with checksum '0eb8e4ed029b774d80f2b66408203801cb982a60'
-RUN: LLVMFuzzer-ShrinkControlFlowSimpleTest -exit_on_item=0eb8e4ed029b774d80f2b66408203801cb982a60 -reduce_inputs=1 -runs=1000000 2>&1 | FileCheck %s
+
+# Test that reduce_inputs deletes redundant files in the corpus.
+RUN: LLVMFuzzer-ShrinkControlFlowSimpleTest -runs=0 %t/C 2>&1 | FileCheck %s --check-prefix=COUNT
+COUNT: READ units: 3
+
+
+
OpenPOWER on IntegriCloud