diff options
author | Kostya Serebryany <kcc@google.com> | 2015-10-24 01:16:40 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2015-10-24 01:16:40 +0000 |
commit | 9cc3b0ddb60f7515b5216fdb568e71aa7a7596c8 (patch) | |
tree | 6d1fcc00f09413ab0d9308a99f5e5197b01e6185 /llvm/lib/Fuzzer/FuzzerLoop.cpp | |
parent | edb35d95d1ffa14fca9dfdb97d30cc0f834155ba (diff) | |
download | bcm5719-llvm-9cc3b0ddb60f7515b5216fdb568e71aa7a7596c8.tar.gz bcm5719-llvm-9cc3b0ddb60f7515b5216fdb568e71aa7a7596c8.zip |
[libFuzzer] add -merge flag to merge corpora
llvm-svn: 251168
Diffstat (limited to 'llvm/lib/Fuzzer/FuzzerLoop.cpp')
-rw-r--r-- | llvm/lib/Fuzzer/FuzzerLoop.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/llvm/lib/Fuzzer/FuzzerLoop.cpp b/llvm/lib/Fuzzer/FuzzerLoop.cpp index 268989f103a..4f07961e066 100644 --- a/llvm/lib/Fuzzer/FuzzerLoop.cpp +++ b/llvm/lib/Fuzzer/FuzzerLoop.cpp @@ -286,6 +286,38 @@ void Fuzzer::ReportNewCoverage(const Unit &U) { exit(0); } +void Fuzzer::Merge(const std::vector<std::string> &Corpora) { + if (Corpora.size() <= 1) { + Printf("Merge requires two or more corpus dirs\n"); + return; + } + auto InitialCorpusDir = Corpora[0]; + ReadDir(InitialCorpusDir, nullptr); + Printf("Merge: running the initial corpus '%s' of %d units\n", + InitialCorpusDir.c_str(), Corpus.size()); + for (auto &U : Corpus) + RunOne(U); + + std::vector<std::string> ExtraCorpora(Corpora.begin() + 1, Corpora.end()); + + size_t NumTried = 0; + size_t NumMerged = 0; + for (auto &C : ExtraCorpora) { + Corpus.clear(); + ReadDir(C, nullptr); + Printf("Merge: merging the extra corpus '%s' of %zd units\n", C.c_str(), + Corpus.size()); + for (auto &U : Corpus) { + NumTried++; + if (RunOne(U)) { + WriteToOutputCorpus(U); + NumMerged++; + } + } + } + Printf("Merge: written %zd out of %zd units\n", NumMerged, NumTried); +} + void Fuzzer::MutateAndTestOne(Unit *U) { for (int i = 0; i < Options.MutateDepth; i++) { StartTraceRecording(); |