diff options
author | Ivan Krasin <krasin@chromium.org> | 2016-01-22 01:32:34 +0000 |
---|---|---|
committer | Ivan Krasin <krasin@chromium.org> | 2016-01-22 01:32:34 +0000 |
commit | b008fd4d895591013dad05bdeb2276085689b774 (patch) | |
tree | e7b50a74f9ec2fea0a7a4cb24872f138abbc3a22 /llvm/lib/Fuzzer/test/FuzzerUnittest.cpp | |
parent | 1423921a24866af65dd7ffaf69bca20babe72786 (diff) | |
download | bcm5719-llvm-b008fd4d895591013dad05bdeb2276085689b774.tar.gz bcm5719-llvm-b008fd4d895591013dad05bdeb2276085689b774.zip |
Use std::piecewise_constant_distribution instead of ad-hoc binary search.
Summary:
Fix the issue with the most recently discovered unit receiving much less attention.
Note: I had to change the seed for one test to make it pass. Alternatively,
the number of runs could be increased. I believe that the average time of
'foo' discovery is not increased, just seed=1 was particularly convenient
for the previous PRNG scheme used.
Reviewers: aizatsky, kcc
Subscribers: llvm-commits, kcc
Differential Revision: http://reviews.llvm.org/D16419
llvm-svn: 258473
Diffstat (limited to 'llvm/lib/Fuzzer/test/FuzzerUnittest.cpp')
-rw-r--r-- | llvm/lib/Fuzzer/test/FuzzerUnittest.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/llvm/lib/Fuzzer/test/FuzzerUnittest.cpp b/llvm/lib/Fuzzer/test/FuzzerUnittest.cpp index 9512e167ab9..e0cca7d396c 100644 --- a/llvm/lib/Fuzzer/test/FuzzerUnittest.cpp +++ b/llvm/lib/Fuzzer/test/FuzzerUnittest.cpp @@ -6,7 +6,7 @@ using namespace fuzzer; // For now, have LLVMFuzzerTestOneInput just to make it link. // Later we may want to make unittests that actually call LLVMFuzzerTestOneInput. -extern "C" void LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { abort(); } @@ -400,3 +400,23 @@ TEST(FuzzerUtil, Base64) { EXPECT_EQ("YWJjeHk=", Base64({'a', 'b', 'c', 'x', 'y'})); EXPECT_EQ("YWJjeHl6", Base64({'a', 'b', 'c', 'x', 'y', 'z'})); } + +TEST(Corpus, Distribution) { + FuzzerRandomLibc Rand(0); + SimpleUserSuppliedFuzzer USF(&Rand, LLVMFuzzerTestOneInput); + Fuzzer::FuzzingOptions Options; + Fuzzer Fuzz(USF, Options); + size_t N = 10; + size_t TriesPerUnit = 1<<20; + for (size_t i = 0; i < N; i++) { + Fuzz.AddToCorpus(Unit{ static_cast<uint8_t>(i) }); + } + std::vector<size_t> Hist(N); + for (size_t i = 0; i < N * TriesPerUnit; i++) { + Hist[Fuzz.ChooseUnitIdxToMutate()]++; + } + for (size_t i = 0; i < N; i++) { + // A weak sanity check that every unit gets invoked. + EXPECT_GT(Hist[i], TriesPerUnit / N / 3); + } +} |