diff options
author | Dan Liew <dan@su-root.co.uk> | 2016-06-07 23:32:50 +0000 |
---|---|---|
committer | Dan Liew <dan@su-root.co.uk> | 2016-06-07 23:32:50 +0000 |
commit | 1873a496e20a391633fc29665d6620c1ca3191f7 (patch) | |
tree | abb6a28df749fed5b9e653269cdcd941af9d7bb1 /llvm/lib/Fuzzer/test/FuzzerUnittest.cpp | |
parent | 32c940de377ec87a072e3d7c3f3200beec6fe90e (diff) | |
download | bcm5719-llvm-1873a496e20a391633fc29665d6620c1ca3191f7.tar.gz bcm5719-llvm-1873a496e20a391633fc29665d6620c1ca3191f7.zip |
[LibFuzzer] Declare and use sanitizer functions in ``fuzzer::ExternalFunctions``
This fixes linking problems on OSX.
Unfortunately it turns out we need to use an instance of the
``fuzzer::ExternalFunctions`` object in several places so this
commit also replaces all instances with a single global instance.
It also turns out initializing a global ``fuzzer::ExternalFunctions``
before main is entered (i.e. letting the object be initialised by the
global initializers) is not safe (on OSX the call to ``Printf()`` in the
CTOR crashes if it is called from a global initializer) so we instead
have a global ``fuzzer::ExternalFunctions*`` and initialize it inside
``FuzzerDriver()``.
Multiple unit tests depend also depend on the
``fuzzer::ExternalFunctions*`` global so a ``main()`` function has been
added that initializes it before running any tests.
Differential Revision: http://reviews.llvm.org/D20943
llvm-svn: 272072
Diffstat (limited to 'llvm/lib/Fuzzer/test/FuzzerUnittest.cpp')
-rw-r--r-- | llvm/lib/Fuzzer/test/FuzzerUnittest.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/llvm/lib/Fuzzer/test/FuzzerUnittest.cpp b/llvm/lib/Fuzzer/test/FuzzerUnittest.cpp index 7b49f2f08e4..91ac9a73c17 100644 --- a/llvm/lib/Fuzzer/test/FuzzerUnittest.cpp +++ b/llvm/lib/Fuzzer/test/FuzzerUnittest.cpp @@ -3,6 +3,7 @@ #include "FuzzerInternal.h" #include "gtest/gtest.h" +#include <memory> #include <set> using namespace fuzzer; @@ -14,6 +15,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { } TEST(Fuzzer, CrossOver) { + std::unique_ptr<ExternalFunctions> t(new ExternalFunctions()); + fuzzer::EF = t.get(); Random Rand(0); MutationDispatcher MD(Rand); Unit A({0, 1, 2}), B({5, 6, 7}); @@ -82,6 +85,8 @@ typedef size_t (MutationDispatcher::*Mutator)(uint8_t *Data, size_t Size, size_t MaxSize); void TestEraseByte(Mutator M, int NumIter) { + std::unique_ptr<ExternalFunctions> t(new ExternalFunctions()); + fuzzer::EF = t.get(); uint8_t REM0[8] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77}; uint8_t REM1[8] = {0x00, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77}; uint8_t REM2[8] = {0x00, 0x11, 0x33, 0x44, 0x55, 0x66, 0x77}; @@ -116,6 +121,8 @@ TEST(FuzzerMutate, EraseByte2) { } void TestInsertByte(Mutator M, int NumIter) { + std::unique_ptr<ExternalFunctions> t(new ExternalFunctions()); + fuzzer::EF = t.get(); Random Rand(0); MutationDispatcher MD(Rand); int FoundMask = 0; @@ -150,6 +157,8 @@ TEST(FuzzerMutate, InsertByte2) { } void TestChangeByte(Mutator M, int NumIter) { + std::unique_ptr<ExternalFunctions> t(new ExternalFunctions()); + fuzzer::EF = t.get(); Random Rand(0); MutationDispatcher MD(Rand); int FoundMask = 0; @@ -184,6 +193,8 @@ TEST(FuzzerMutate, ChangeByte2) { } void TestChangeBit(Mutator M, int NumIter) { + std::unique_ptr<ExternalFunctions> t(new ExternalFunctions()); + fuzzer::EF = t.get(); Random Rand(0); MutationDispatcher MD(Rand); int FoundMask = 0; @@ -218,6 +229,8 @@ TEST(FuzzerMutate, ChangeBit2) { } void TestShuffleBytes(Mutator M, int NumIter) { + std::unique_ptr<ExternalFunctions> t(new ExternalFunctions()); + fuzzer::EF = t.get(); Random Rand(0); MutationDispatcher MD(Rand); int FoundMask = 0; @@ -246,6 +259,8 @@ TEST(FuzzerMutate, ShuffleBytes2) { } void TestAddWordFromDictionary(Mutator M, int NumIter) { + std::unique_ptr<ExternalFunctions> t(new ExternalFunctions()); + fuzzer::EF = t.get(); Random Rand(0); MutationDispatcher MD(Rand); uint8_t Word1[4] = {0xAA, 0xBB, 0xCC, 0xDD}; @@ -286,6 +301,8 @@ TEST(FuzzerMutate, AddWordFromDictionary2) { } void TestAddWordFromDictionaryWithHint(Mutator M, int NumIter) { + std::unique_ptr<ExternalFunctions> t(new ExternalFunctions()); + fuzzer::EF = t.get(); Random Rand(0); MutationDispatcher MD(Rand); uint8_t W[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xFF, 0xEE, 0xEF}; @@ -313,6 +330,8 @@ TEST(FuzzerMutate, AddWordFromDictionaryWithHint2) { } void TestChangeASCIIInteger(Mutator M, int NumIter) { + std::unique_ptr<ExternalFunctions> t(new ExternalFunctions()); + fuzzer::EF = t.get(); Random Rand(0); MutationDispatcher MD(Rand); @@ -405,6 +424,8 @@ TEST(FuzzerUtil, Base64) { } TEST(Corpus, Distribution) { + std::unique_ptr<ExternalFunctions> t(new ExternalFunctions()); + fuzzer::EF = t.get(); Random Rand(0); MutationDispatcher MD(Rand); Fuzzer::FuzzingOptions Options; |