[lib/Fuzzer] build tests that work well with dfsan also w/o dfsan
authorKostya Serebryany <kcc@google.com>
Fri, 8 May 2015 21:45:19 +0000 (21:45 +0000)
committerKostya Serebryany <kcc@google.com>
Fri, 8 May 2015 21:45:19 +0000 (21:45 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@236909 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Fuzzer/test/CMakeLists.txt
lib/Fuzzer/test/DFSanMemcmpTest.cpp [new file with mode: 0644]
lib/Fuzzer/test/DFSanSimpleCmpTest.cpp [new file with mode: 0644]
lib/Fuzzer/test/dfsan/CMakeLists.txt
lib/Fuzzer/test/dfsan/DFSanMemcmpTest.cpp [deleted file]
lib/Fuzzer/test/dfsan/DFSanSimpleCmpTest.cpp [deleted file]
lib/Fuzzer/test/fuzzer.test

index 1080b30ec39b04b483584f7f4f32658fcbedc403..fc663883ea19b0776adffdd4906c0879303d0348 100644 (file)
@@ -4,6 +4,11 @@
 # for the Fuzzer lib)
 set(CMAKE_CXX_FLAGS_RELEASE "${LIBFUZZER_FLAGS_BASE} -O0 -fsanitize-coverage=edge,indirect-calls")
 
+set(DFSanTests
+  DFSanMemcmpTest
+  DFSanSimpleCmpTest
+  )
+
 set(Tests
   CounterTest
   CxxTokensTest
@@ -13,12 +18,9 @@ set(Tests
   NullDerefTest
   SimpleTest
   TimeoutTest
+  ${DFSanTests}
   )
 
-set(DFSanTests
-  DFSanMemcmpTest
-  DFSanSimpleCmpTest
-  )
 
 set(TestBinaries)
 
@@ -60,7 +62,7 @@ set(TestBinaries ${TestBinaries} LLVMFuzzer-Unittest)
 add_subdirectory(dfsan)
 
 foreach(Test ${DFSanTests})
-  set(TestBinaries ${TestBinaries} LLVMFuzzer-${Test})
+  set(TestBinaries ${TestBinaries} LLVMFuzzer-${Test}-DFSan)
 endforeach()
 
 
diff --git a/lib/Fuzzer/test/DFSanMemcmpTest.cpp b/lib/Fuzzer/test/DFSanMemcmpTest.cpp
new file mode 100644 (file)
index 0000000..510a243
--- /dev/null
@@ -0,0 +1,12 @@
+// Simple test for a fuzzer. The fuzzer must find a particular string.
+#include <cstring>
+#include <cstdint>
+#include <cstdio>
+#include <cstdlib>
+
+extern "C" void LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
+  if (Size >= 8 && memcmp(Data, "01234567", 8) == 0) {
+    fprintf(stderr, "BINGO\n");
+    exit(1);
+  }
+}
diff --git a/lib/Fuzzer/test/DFSanSimpleCmpTest.cpp b/lib/Fuzzer/test/DFSanSimpleCmpTest.cpp
new file mode 100644 (file)
index 0000000..ee37814
--- /dev/null
@@ -0,0 +1,30 @@
+// Simple test for a fuzzer. The fuzzer must find several narrow ranges.
+#include <cstdint>
+#include <cstdlib>
+#include <cstring>
+#include <cstdio>
+
+extern "C" void LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
+  if (Size < 14) return;
+  uint64_t x = 0;
+  int64_t  y = 0;
+  int z = 0;
+  unsigned short a = 0;
+  memcpy(&x, Data, 8);
+  memcpy(&y, Data + Size - 8, 8);
+  memcpy(&z, Data + Size / 2, sizeof(z));
+  memcpy(&a, Data + Size / 2 + 4, sizeof(a));
+
+  if (x > 1234567890 &&
+      x < 1234567895 &&
+      y >= 987654321 &&
+      y <= 987654325 &&
+      z < -10000 &&
+      z >= -10005 &&
+      z != -10003 &&
+      a == 4242) {
+    fprintf(stderr, "BINGO; Found the target: size %zd (%zd, %zd, %d, %d), exiting.\n",
+            Size, x, y, z, a);
+    exit(1);
+  }
+}
index d1a140d6b50b54d1a06839284766a7af2f45ff40..2b49831fcdb85208f2fb8fc6b831b5b81b449f51 100644 (file)
@@ -4,10 +4,10 @@ set(CMAKE_CXX_FLAGS_RELEASE
   "${LIBFUZZER_FLAGS_BASE} -O0 -fno-sanitize=all -fsanitize=dataflow")
 
 foreach(Test ${DFSanTests})
-  add_executable(LLVMFuzzer-${Test}
-    ${Test}.cpp
+  add_executable(LLVMFuzzer-${Test}-DFSan
+    ../${Test}.cpp
     )
-  target_link_libraries(LLVMFuzzer-${Test}
+  target_link_libraries(LLVMFuzzer-${Test}-DFSan
     LLVMFuzzer
     )
 endforeach()
diff --git a/lib/Fuzzer/test/dfsan/DFSanMemcmpTest.cpp b/lib/Fuzzer/test/dfsan/DFSanMemcmpTest.cpp
deleted file mode 100644 (file)
index 510a243..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-// Simple test for a fuzzer. The fuzzer must find a particular string.
-#include <cstring>
-#include <cstdint>
-#include <cstdio>
-#include <cstdlib>
-
-extern "C" void LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
-  if (Size >= 8 && memcmp(Data, "01234567", 8) == 0) {
-    fprintf(stderr, "BINGO\n");
-    exit(1);
-  }
-}
diff --git a/lib/Fuzzer/test/dfsan/DFSanSimpleCmpTest.cpp b/lib/Fuzzer/test/dfsan/DFSanSimpleCmpTest.cpp
deleted file mode 100644 (file)
index ee37814..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-// Simple test for a fuzzer. The fuzzer must find several narrow ranges.
-#include <cstdint>
-#include <cstdlib>
-#include <cstring>
-#include <cstdio>
-
-extern "C" void LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
-  if (Size < 14) return;
-  uint64_t x = 0;
-  int64_t  y = 0;
-  int z = 0;
-  unsigned short a = 0;
-  memcpy(&x, Data, 8);
-  memcpy(&y, Data + Size - 8, 8);
-  memcpy(&z, Data + Size / 2, sizeof(z));
-  memcpy(&a, Data + Size / 2 + 4, sizeof(a));
-
-  if (x > 1234567890 &&
-      x < 1234567895 &&
-      y >= 987654321 &&
-      y <= 987654325 &&
-      z < -10000 &&
-      z >= -10005 &&
-      z != -10003 &&
-      a == 4242) {
-    fprintf(stderr, "BINGO; Found the target: size %zd (%zd, %zd, %d, %d), exiting.\n",
-            Size, x, y, z, a);
-    exit(1);
-  }
-}
index 9006c4a706d5e1a7fdd160d64902647fe0ec281f..7d1908f61798867fcb296f8373984309d14dd0c9 100644 (file)
@@ -19,9 +19,9 @@ RUN: not ./LLVMFuzzer-FourIndependentBranchesTest -timeout=15 -seed=1 -use_cover
 
 RUN: not ./LLVMFuzzer-CounterTest -use_counters=1 -max_len=6 -seed=1 -timeout=15 2>&1 | FileCheck %s
 
-RUN: not ./LLVMFuzzer-DFSanSimpleCmpTest -seed=1 -runs=1000000 -timeout=5 2>&1 | FileCheck %s
+RUN: not ./LLVMFuzzer-DFSanSimpleCmpTest-DFSan -seed=1 -runs=1000000 -timeout=5 2>&1 | FileCheck %s
 
-RUN: not ./LLVMFuzzer-DFSanMemcmpTest -seed=1 -runs=100 -timeout=5 2>&1 | FileCheck %s
+RUN: not ./LLVMFuzzer-DFSanMemcmpTest-DFSan -seed=1 -runs=100 -timeout=5 2>&1 | FileCheck %s
 
 RUN: not ./LLVMFuzzer-CxxTokensTest -seed=1 -timeout=15 -tokens=%S/../cxx_fuzzer_tokens.txt 2>&1 | FileCheck %s