Index: llvm/trunk/lib/Fuzzer/test/CMakeLists.txt =================================================================== --- llvm/trunk/lib/Fuzzer/test/CMakeLists.txt +++ llvm/trunk/lib/Fuzzer/test/CMakeLists.txt @@ -18,6 +18,7 @@ CallerCalleeTest CounterTest CustomMutatorTest + EmptyTest FourIndependentBranchesTest FullCoverageSetTest InitializeTest Index: llvm/trunk/lib/Fuzzer/test/EmptyTest.cpp =================================================================== --- llvm/trunk/lib/Fuzzer/test/EmptyTest.cpp +++ llvm/trunk/lib/Fuzzer/test/EmptyTest.cpp @@ -0,0 +1,11 @@ +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +// A fuzzer with empty target function. + +#include +#include + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { + return 0; +} Index: llvm/trunk/lib/Fuzzer/test/FuzzerUnittest.cpp =================================================================== --- llvm/trunk/lib/Fuzzer/test/FuzzerUnittest.cpp +++ llvm/trunk/lib/Fuzzer/test/FuzzerUnittest.cpp @@ -13,10 +13,6 @@ abort(); } -static int EmptyLLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { - return 0; -} - TEST(Fuzzer, CrossOver) { Random Rand(0); MutationDispatcher MD(Rand); @@ -427,21 +423,3 @@ 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(1))); - Fuzz.ResetCoverage(); - - std::vector NewCorpus; - Fuzz.TruncateUnits(&NewCorpus); - - // New corpus should have a shorter unit. - EXPECT_EQ(1ul, NewCorpus.size()); - EXPECT_EQ(1ul, NewCorpus[0].size()); -} Index: llvm/trunk/lib/Fuzzer/test/fuzzer-trunc.test =================================================================== --- llvm/trunk/lib/Fuzzer/test/fuzzer-trunc.test +++ llvm/trunk/lib/Fuzzer/test/fuzzer-trunc.test @@ -0,0 +1,10 @@ +# Test truncate_units option. +RUN: rm -rf FuzzerTruncateTestCORPUS +RUN: mkdir FuzzerTruncateTestCORPUS +RUN: echo "01234567890123456789012345678901234567890" > FuzzerTruncateTestCORPUS/unit1 +# Simply running a fuzzer won't produce new results +RUN: LLVMFuzzer-EmptyTest -seed=1 -runs=100 -truncate_units=0 ./FuzzerTruncateTestCORPUS +# Truncating would create a new unit of length 1. +RUN: LLVMFuzzer-EmptyTest -seed=1 -runs=0 -truncate_units=1 ./FuzzerTruncateTestCORPUS +RUN: find FuzzerTruncateTestCORPUS/b6589fc6ab0dc82cf12099d1c2d40ab994e8410c +RUN: rm -rf FuzzerTruncateTestCORPUS