summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Fuzzer/test/FuzzerUnittest.cpp
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2015-08-06 01:29:13 +0000
committerKostya Serebryany <kcc@google.com>2015-08-06 01:29:13 +0000
commitbf29ff2fa567d2e0aa15a14041fcb4f0f92bf5ec (patch)
tree19f0dc11dc26f934e30f50abb8af8bceff474f4b /llvm/lib/Fuzzer/test/FuzzerUnittest.cpp
parent3f84b7353b0efde731c4d2c9802122c1529e8e7a (diff)
downloadbcm5719-llvm-bf29ff2fa567d2e0aa15a14041fcb4f0f92bf5ec.tar.gz
bcm5719-llvm-bf29ff2fa567d2e0aa15a14041fcb4f0f92bf5ec.zip
[libFuzzer] add one more mutation strategy: byte shuffling
llvm-svn: 244188
Diffstat (limited to 'llvm/lib/Fuzzer/test/FuzzerUnittest.cpp')
-rw-r--r--llvm/lib/Fuzzer/test/FuzzerUnittest.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/llvm/lib/Fuzzer/test/FuzzerUnittest.cpp b/llvm/lib/Fuzzer/test/FuzzerUnittest.cpp
index a3e6a136b27..518cfab5d93 100644
--- a/llvm/lib/Fuzzer/test/FuzzerUnittest.cpp
+++ b/llvm/lib/Fuzzer/test/FuzzerUnittest.cpp
@@ -192,3 +192,26 @@ void TestChangeBit(Mutator M, int NumIter) {
TEST(FuzzerMutate, ChangeBit1) { TestChangeBit(Mutate_ChangeBit, 1 << 16); }
TEST(FuzzerMutate, ChangeBit2) { TestChangeBit(Mutate, 1 << 18); }
+
+void TestShuffleBytes(Mutator M, int NumIter) {
+ FuzzerRandomLibc Rand(0);
+ int FoundMask = 0;
+ uint8_t CH0[7] = {0x00, 0x22, 0x11, 0x33, 0x44, 0x55, 0x66};
+ uint8_t CH1[7] = {0x11, 0x00, 0x33, 0x22, 0x44, 0x55, 0x66};
+ uint8_t CH2[7] = {0x00, 0x33, 0x11, 0x22, 0x44, 0x55, 0x66};
+ uint8_t CH3[7] = {0x00, 0x11, 0x22, 0x44, 0x55, 0x66, 0x33};
+ uint8_t CH4[7] = {0x00, 0x11, 0x22, 0x33, 0x55, 0x44, 0x66};
+ for (int i = 0; i < NumIter; i++) {
+ uint8_t T[7] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66};
+ size_t NewSize = M(T, 7, 7, Rand);
+ if (NewSize == 7 && !memcmp(CH0, T, 7)) FoundMask |= 1 << 0;
+ if (NewSize == 7 && !memcmp(CH1, T, 7)) FoundMask |= 1 << 1;
+ if (NewSize == 7 && !memcmp(CH2, T, 7)) FoundMask |= 1 << 2;
+ if (NewSize == 7 && !memcmp(CH3, T, 7)) FoundMask |= 1 << 3;
+ if (NewSize == 7 && !memcmp(CH4, T, 7)) FoundMask |= 1 << 4;
+ }
+ EXPECT_EQ(FoundMask, 31);
+}
+
+TEST(FuzzerMutate, ShuffleBytes1) { TestShuffleBytes(Mutate_ShuffleBytes, 1 << 15); }
+TEST(FuzzerMutate, ShuffleBytes2) { TestShuffleBytes(Mutate, 1 << 16); }
OpenPOWER on IntegriCloud