diff options
author | Kostya Serebryany <kcc@google.com> | 2015-01-30 23:26:57 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2015-01-30 23:26:57 +0000 |
commit | 71672552dbe2f1ce80bc77987a6c762aa3c699b6 (patch) | |
tree | 142625a070618fd998d73851c61aec3fb0399b60 /llvm/lib/Fuzzer/test/FuzzerUnittest.cpp | |
parent | 7792e32b649d6399ffc9d4ebcc700a376a4936e8 (diff) | |
download | bcm5719-llvm-71672552dbe2f1ce80bc77987a6c762aa3c699b6.tar.gz bcm5719-llvm-71672552dbe2f1ce80bc77987a6c762aa3c699b6.zip |
[fuzzer] Add a gtest-style test
Summary: Add one gtest-style test.
Test Plan: run on bot
Reviewers: samsonov
Reviewed By: samsonov
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D7287
llvm-svn: 227639
Diffstat (limited to 'llvm/lib/Fuzzer/test/FuzzerUnittest.cpp')
-rw-r--r-- | llvm/lib/Fuzzer/test/FuzzerUnittest.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/llvm/lib/Fuzzer/test/FuzzerUnittest.cpp b/llvm/lib/Fuzzer/test/FuzzerUnittest.cpp new file mode 100644 index 00000000000..368a0f2bf00 --- /dev/null +++ b/llvm/lib/Fuzzer/test/FuzzerUnittest.cpp @@ -0,0 +1,62 @@ +#include "FuzzerInternal.h" +#include "gtest/gtest.h" +#include <set> + +// For now, have TestOneInput just to make it link. +// Later we may want to make unittests that actually call TestOneInput. +extern "C" void TestOneInput(const uint8_t *Data, size_t Size) { + abort(); +} + +TEST(Fuzzer, CrossOver) { + using namespace fuzzer; + Unit A({0, 1, 2}), B({5, 6, 7}); + Unit C; + Unit Expected[] = { + { 0 }, + { 0, 1 }, + { 0, 5 }, + { 0, 1, 2 }, + { 0, 1, 5 }, + { 0, 5, 1 }, + { 0, 5, 6 }, + { 0, 1, 2, 5 }, + { 0, 1, 5, 2 }, + { 0, 1, 5, 6 }, + { 0, 5, 1, 2 }, + { 0, 5, 1, 6 }, + { 0, 5, 6, 1 }, + { 0, 5, 6, 7 }, + { 0, 1, 2, 5, 6 }, + { 0, 1, 5, 2, 6 }, + { 0, 1, 5, 6, 2 }, + { 0, 1, 5, 6, 7 }, + { 0, 5, 1, 2, 6 }, + { 0, 5, 1, 6, 2 }, + { 0, 5, 1, 6, 7 }, + { 0, 5, 6, 1, 2 }, + { 0, 5, 6, 1, 7 }, + { 0, 5, 6, 7, 1 }, + { 0, 1, 2, 5, 6, 7 }, + { 0, 1, 5, 2, 6, 7 }, + { 0, 1, 5, 6, 2, 7 }, + { 0, 1, 5, 6, 7, 2 }, + { 0, 5, 1, 2, 6, 7 }, + { 0, 5, 1, 6, 2, 7 }, + { 0, 5, 1, 6, 7, 2 }, + { 0, 5, 6, 1, 2, 7 }, + { 0, 5, 6, 1, 7, 2 }, + { 0, 5, 6, 7, 1, 2 } + }; + for (size_t Len = 1; Len < 8; Len++) { + std::set<Unit> FoundUnits, ExpectedUnitsWitThisLength; + for (int Iter = 0; Iter < 3000; Iter++) { + CrossOver(A, B, &C, Len); + FoundUnits.insert(C); + } + for (const Unit &U : Expected) + if (U.size() <= Len) + ExpectedUnitsWitThisLength.insert(U); + EXPECT_EQ(ExpectedUnitsWitThisLength, FoundUnits); + } +} |