diff options
author | Ivan Krasin <krasin@chromium.org> | 2016-01-22 22:28:27 +0000 |
---|---|---|
committer | Ivan Krasin <krasin@chromium.org> | 2016-01-22 22:28:27 +0000 |
commit | df91910bd4d4afa8339ba27cd7f354760171bb5a (patch) | |
tree | a205f251a9d87efc5e6873dcbe2c8f20538e6065 /llvm/lib/Fuzzer/test/FuzzerUnittest.cpp | |
parent | 13e7cb294c95eb0192728179f9eb0a97150f306a (diff) | |
download | bcm5719-llvm-df91910bd4d4afa8339ba27cd7f354760171bb5a.tar.gz bcm5719-llvm-df91910bd4d4afa8339ba27cd7f354760171bb5a.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: this is the second attempt (prev: r258473). Now, libc++ build is fixed.
Reviewers: aizatsky, kcc
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D16487
llvm-svn: 258571
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); + } +} |