summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/fuzzer/tests/FuzzerUnittest.cpp
diff options
context:
space:
mode:
authorDan Liew <dan@su-root.co.uk>2018-04-24 06:31:09 +0000
committerDan Liew <dan@su-root.co.uk>2018-04-24 06:31:09 +0000
commitdfd5a90a995a306d314085e674ff7cfa62d2aa7c (patch)
tree0a7e862e9157c366ec05dc36ecc6d5260d1909b9 /compiler-rt/lib/fuzzer/tests/FuzzerUnittest.cpp
parent3326e785b29502363c36dd38182ac7a70b510864 (diff)
downloadbcm5719-llvm-dfd5a90a995a306d314085e674ff7cfa62d2aa7c.tar.gz
bcm5719-llvm-dfd5a90a995a306d314085e674ff7cfa62d2aa7c.zip
[LibFuzzer] Tweak `MutationDispatcher::Mutate_CopyPart` mutation.
It doesn't make sense to non-deterministically choose between `CopyPart(..)` and `InsertPart(..)` when it is known that `InsertPart(..)` will fail. This upstream's a change from JFS solver's fork of LibFuzzer. Differential Revision: https://reviews.llvm.org/D45693 llvm-svn: 330687
Diffstat (limited to 'compiler-rt/lib/fuzzer/tests/FuzzerUnittest.cpp')
-rw-r--r--compiler-rt/lib/fuzzer/tests/FuzzerUnittest.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/compiler-rt/lib/fuzzer/tests/FuzzerUnittest.cpp b/compiler-rt/lib/fuzzer/tests/FuzzerUnittest.cpp
index 3f57a5d60c2..c795eddc656 100644
--- a/compiler-rt/lib/fuzzer/tests/FuzzerUnittest.cpp
+++ b/compiler-rt/lib/fuzzer/tests/FuzzerUnittest.cpp
@@ -381,6 +381,21 @@ TEST(FuzzerMutate, CopyPart1) {
TEST(FuzzerMutate, CopyPart2) {
TestCopyPart(&MutationDispatcher::Mutate, 1 << 13);
}
+TEST(FuzzerMutate, CopyPartNoInsertAtMaxSize) {
+ // This (non exhaustively) tests if `Mutate_CopyPart` tries to perform an
+ // insert on an input of size `MaxSize`. Performing an insert in this case
+ // will lead to the mutation failing.
+ std::unique_ptr<ExternalFunctions> t(new ExternalFunctions());
+ fuzzer::EF = t.get();
+ Random Rand(0);
+ std::unique_ptr<MutationDispatcher> MD(new MutationDispatcher(Rand, {}));
+ uint8_t Data[8] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x00, 0x11, 0x22};
+ size_t MaxSize = sizeof(Data);
+ for (int count = 0; count < (1 << 18); ++count) {
+ size_t NewSize = MD->Mutate_CopyPart(Data, MaxSize, MaxSize);
+ ASSERT_EQ(NewSize, MaxSize);
+ }
+}
void TestAddWordFromDictionary(Mutator M, int NumIter) {
std::unique_ptr<ExternalFunctions> t(new ExternalFunctions());
OpenPOWER on IntegriCloud