1 #include "FuzzerInternal.h" 2 #include "gtest/gtest.h" 3 #include <set> 4 5 // For now, have TestOneInput just to make it link. 6 // Later we may want to make unittests that actually call TestOneInput. 7 extern "C" void TestOneInput(const uint8_t *Data, size_t Size) { 8 abort(); 9 } 10 11 TEST(Fuzzer, CrossOver) { 12 using namespace fuzzer; 13 Unit A({0, 1, 2}), B({5, 6, 7}); 14 Unit C; 15 Unit Expected[] = { 16 { 0 }, 17 { 0, 1 }, 18 { 0, 5 }, 19 { 0, 1, 2 }, 20 { 0, 1, 5 }, 21 { 0, 5, 1 }, 22 { 0, 5, 6 }, 23 { 0, 1, 2, 5 }, 24 { 0, 1, 5, 2 }, 25 { 0, 1, 5, 6 }, 26 { 0, 5, 1, 2 }, 27 { 0, 5, 1, 6 }, 28 { 0, 5, 6, 1 }, 29 { 0, 5, 6, 7 }, 30 { 0, 1, 2, 5, 6 }, 31 { 0, 1, 5, 2, 6 }, 32 { 0, 1, 5, 6, 2 }, 33 { 0, 1, 5, 6, 7 }, 34 { 0, 5, 1, 2, 6 }, 35 { 0, 5, 1, 6, 2 }, 36 { 0, 5, 1, 6, 7 }, 37 { 0, 5, 6, 1, 2 }, 38 { 0, 5, 6, 1, 7 }, 39 { 0, 5, 6, 7, 1 }, 40 { 0, 1, 2, 5, 6, 7 }, 41 { 0, 1, 5, 2, 6, 7 }, 42 { 0, 1, 5, 6, 2, 7 }, 43 { 0, 1, 5, 6, 7, 2 }, 44 { 0, 5, 1, 2, 6, 7 }, 45 { 0, 5, 1, 6, 2, 7 }, 46 { 0, 5, 1, 6, 7, 2 }, 47 { 0, 5, 6, 1, 2, 7 }, 48 { 0, 5, 6, 1, 7, 2 }, 49 { 0, 5, 6, 7, 1, 2 } 50 }; 51 for (size_t Len = 1; Len < 8; Len++) { 52 std::set<Unit> FoundUnits, ExpectedUnitsWitThisLength; 53 for (int Iter = 0; Iter < 3000; Iter++) { 54 CrossOver(A, B, &C, Len); 55 FoundUnits.insert(C); 56 } 57 for (const Unit &U : Expected) 58 if (U.size() <= Len) 59 ExpectedUnitsWitThisLength.insert(U); 60 EXPECT_EQ(ExpectedUnitsWitThisLength, FoundUnits); 61 } 62 } 63