diff options
Diffstat (limited to 'llvm/lib/Fuzzer/test')
-rw-r--r-- | llvm/lib/Fuzzer/test/ExactTest.cpp | 21 | ||||
-rw-r--r-- | llvm/lib/Fuzzer/test/InfiniteTest.cpp | 19 | ||||
-rw-r--r-- | llvm/lib/Fuzzer/test/NullDerefTest.cpp | 21 | ||||
-rw-r--r-- | llvm/lib/Fuzzer/test/SimpleTest.cpp | 20 | ||||
-rw-r--r-- | llvm/lib/Fuzzer/test/TestFuzzerCrossOver.cpp | 13 | ||||
-rw-r--r-- | llvm/lib/Fuzzer/test/TimeoutTest.cpp | 21 |
6 files changed, 115 insertions, 0 deletions
diff --git a/llvm/lib/Fuzzer/test/ExactTest.cpp b/llvm/lib/Fuzzer/test/ExactTest.cpp new file mode 100644 index 00000000000..662dd333eea --- /dev/null +++ b/llvm/lib/Fuzzer/test/ExactTest.cpp @@ -0,0 +1,21 @@ +// Simple test for a fuzzer. The fuzzer must find the string "FUZZER". +#include <cstdlib> +#include <cstddef> +#include <iostream> + +static volatile int Sink; + +extern "C" void TestOneInput(const uint8_t *Data, size_t Size) { + int bits = 0; + if (Size > 0 && Data[0] == 'F') bits |= 1; + if (Size > 1 && Data[1] == 'U') bits |= 2; + if (Size > 2 && Data[2] == 'Z') bits |= 4; + if (Size > 3 && Data[3] == 'Z') bits |= 8; + if (Size > 4 && Data[4] == 'E') bits |= 16; + if (Size > 5 && Data[5] == 'R') bits |= 32; + if (bits == 63) { + std::cerr << "BINGO!\n"; + abort(); + } +} + diff --git a/llvm/lib/Fuzzer/test/InfiniteTest.cpp b/llvm/lib/Fuzzer/test/InfiniteTest.cpp new file mode 100644 index 00000000000..9f4864abdd4 --- /dev/null +++ b/llvm/lib/Fuzzer/test/InfiniteTest.cpp @@ -0,0 +1,19 @@ +// Simple test for a fuzzer. The fuzzer must find the string "Hi!". +#include <cstdlib> +#include <cstddef> +#include <iostream> + +static volatile int Sink; + +extern "C" void TestOneInput(const uint8_t *Data, size_t Size) { + if (Size > 0 && Data[0] == 'H') { + Sink = 1; + if (Size > 1 && Data[1] == 'i') { + Sink = 2; + if (Size > 2 && Data[2] == '!') { + Size = 2; + } + } + } +} + diff --git a/llvm/lib/Fuzzer/test/NullDerefTest.cpp b/llvm/lib/Fuzzer/test/NullDerefTest.cpp new file mode 100644 index 00000000000..602276f3c81 --- /dev/null +++ b/llvm/lib/Fuzzer/test/NullDerefTest.cpp @@ -0,0 +1,21 @@ +// Simple test for a fuzzer. The fuzzer must find the string "Hi!". +#include <cstdlib> +#include <cstddef> +#include <iostream> + +static volatile int Sink; +static volatile int *Null = 0; + +extern "C" void TestOneInput(const uint8_t *Data, size_t Size) { + if (Size > 0 && Data[0] == 'H') { + Sink = 1; + if (Size > 1 && Data[1] == 'i') { + Sink = 2; + if (Size > 2 && Data[2] == '!') { + std::cout << "Found the target, dereferencing NULL\n"; + *Null = 1; + } + } + } +} + diff --git a/llvm/lib/Fuzzer/test/SimpleTest.cpp b/llvm/lib/Fuzzer/test/SimpleTest.cpp new file mode 100644 index 00000000000..9e20d8e6ac9 --- /dev/null +++ b/llvm/lib/Fuzzer/test/SimpleTest.cpp @@ -0,0 +1,20 @@ +// Simple test for a fuzzer. The fuzzer must find the string "Hi!". +#include <cstdlib> +#include <cstddef> +#include <iostream> + +static volatile int Sink; + +extern "C" void TestOneInput(const uint8_t *Data, size_t Size) { + if (Size > 0 && Data[0] == 'H') { + Sink = 1; + if (Size > 1 && Data[1] == 'i') { + Sink = 2; + if (Size > 2 && Data[2] == '!') { + std::cout << "Found the target, exiting\n"; + exit(0); + } + } + } +} + diff --git a/llvm/lib/Fuzzer/test/TestFuzzerCrossOver.cpp b/llvm/lib/Fuzzer/test/TestFuzzerCrossOver.cpp new file mode 100644 index 00000000000..7f7619618ec --- /dev/null +++ b/llvm/lib/Fuzzer/test/TestFuzzerCrossOver.cpp @@ -0,0 +1,13 @@ +#include "FuzzerInternal.h" + +int main() { + using namespace fuzzer; + Unit A({0, 1, 2, 3, 4}), B({5, 6, 7, 8, 9}); + Unit C; + for (size_t Len = 1; Len < 15; Len++) { + for (int Iter = 0; Iter < 1000; Iter++) { + CrossOver(A, B, &C, Len); + Print(C); + } + } +} diff --git a/llvm/lib/Fuzzer/test/TimeoutTest.cpp b/llvm/lib/Fuzzer/test/TimeoutTest.cpp new file mode 100644 index 00000000000..c5a8ac00579 --- /dev/null +++ b/llvm/lib/Fuzzer/test/TimeoutTest.cpp @@ -0,0 +1,21 @@ +// Simple test for a fuzzer. The fuzzer must find the string "Hi!". +#include <cstdlib> +#include <cstddef> +#include <iostream> + +static volatile int Sink; + +extern "C" void TestOneInput(const uint8_t *Data, size_t Size) { + if (Size > 0 && Data[0] == 'H') { + Sink = 1; + if (Size > 1 && Data[1] == 'i') { + Sink = 2; + if (Size > 2 && Data[2] == '!') { + Size = 2; + while (Sink) + ; + } + } + } +} + |