diff options
Diffstat (limited to 'llvm/lib/Fuzzer/test/FuzzerUnittest.cpp')
-rw-r--r-- | llvm/lib/Fuzzer/test/FuzzerUnittest.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/llvm/lib/Fuzzer/test/FuzzerUnittest.cpp b/llvm/lib/Fuzzer/test/FuzzerUnittest.cpp index 7b49f2f08e4..66e9285eb05 100644 --- a/llvm/lib/Fuzzer/test/FuzzerUnittest.cpp +++ b/llvm/lib/Fuzzer/test/FuzzerUnittest.cpp @@ -13,6 +13,10 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { abort(); } +static int EmptyLLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { + return 0; +} + TEST(Fuzzer, CrossOver) { Random Rand(0); MutationDispatcher MD(Rand); @@ -423,3 +427,21 @@ TEST(Corpus, Distribution) { EXPECT_GT(Hist[i], TriesPerUnit / N / 3); } } + +TEST(Corpus, TruncateUnits) { + Random Rand(0); + MutationDispatcher MD(Rand); + Fuzzer::FuzzingOptions Options; + Options.OutputCorpus = ""; // stops from writing new units. + Fuzzer Fuzz(EmptyLLVMFuzzerTestOneInput, MD, Options); + + Fuzz.AddToCorpus(Unit(1024, static_cast<uint8_t>(1))); + Fuzz.ResetCoverage(); + + std::vector<Unit> NewCorpus; + Fuzz.TruncateUnits(&NewCorpus); + + // New corpus should have a shorter unit. + EXPECT_EQ(1ul, NewCorpus.size()); + EXPECT_EQ(1ul, NewCorpus[0].size()); +} |