Skip to content

Commit

Permalink
[libFuzzer] Update tests to use more general functions instead of pos…
Browse files Browse the repository at this point in the history
…ix specific.

Replace sleep() posix function by a more portable sleep_for() function
from std. Also, ignore memmem() and strcasestr() on Windows.

Differential Revision: https://reviews.llvm.org/D27729

llvm-svn: 289964
  • Loading branch information
Marcos Pividori committed Dec 16, 2016
1 parent 6c29367 commit 6a7e4c2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion llvm/lib/Fuzzer/test/OutOfMemoryTest.cpp
Expand Up @@ -8,6 +8,7 @@
#include <cstddef>
#include <cstring>
#include <iostream>
#include <thread>
#include <unistd.h>

static volatile char *SinkPtr;
Expand All @@ -21,7 +22,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
char *p = new char[kSize];
memset(p, 0, kSize);
SinkPtr = p;
sleep(1);
std::this_thread::sleep_for(std::chrono::seconds(1));
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions llvm/lib/Fuzzer/test/StrstrTest.cpp
Expand Up @@ -8,6 +8,12 @@
#include <cstdio>
#include <cstdlib>

// Windows does not have strcasestr and memmem, so we are not testing them.
#ifdef _WIN32
#define strcasestr strstr
#define memmem(a, b, c, d) true
#endif

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
if (Size < 4) return 0;
std::string s(reinterpret_cast<const char*>(Data), Size);
Expand Down

0 comments on commit 6a7e4c2

Please sign in to comment.