]> granicus.if.org Git - llvm/commitdiff
[libFuzzer] one more test
authorKostya Serebryany <kcc@google.com>
Thu, 22 Sep 2016 00:57:29 +0000 (00:57 +0000)
committerKostya Serebryany <kcc@google.com>
Thu, 22 Sep 2016 00:57:29 +0000 (00:57 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282127 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Fuzzer/test/CMakeLists.txt
lib/Fuzzer/test/MinimizeCorpusTest.cpp [new file with mode: 0644]
lib/Fuzzer/test/trace-pc/CMakeLists.txt

index a1d6e024d552555f396ec12a80ea444aa49e2956..1406379b097c3be7c7048eb75554aafa7808fcfb 100644 (file)
@@ -80,6 +80,7 @@ set(Tests
   LeakTest
   LeakTimeoutTest
   LoadTest
+  MinimizeCorpusTest
   NullDerefTest
   NullDerefOnEmptyTest
   NthRunCrashTest
diff --git a/lib/Fuzzer/test/MinimizeCorpusTest.cpp b/lib/Fuzzer/test/MinimizeCorpusTest.cpp
new file mode 100644 (file)
index 0000000..02ef99f
--- /dev/null
@@ -0,0 +1,28 @@
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+
+// Test that we can find the minimal item in the corpus (3 bytes: "FUZ").
+#include <cstdint>
+#include <cstdlib>
+#include <cstddef>
+#include <cstring>
+#include <cstdio>
+
+static volatile int Sink;
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
+  int8_t Ids[256];
+  memset(Ids, -1, sizeof(Ids));
+  for (size_t i = 0; i < Size; i++)
+    if (Ids[Data[i]] == -1)
+      Ids[Data[i]] = i;
+  int F = Ids[(unsigned char)'F'];
+  int U = Ids[(unsigned char)'U'];
+  int Z = Ids[(unsigned char)'Z'];
+  if (F >= 0 && U > F && Z > U) {
+    Sink++;
+    // printf("IDS: %d %d %d\n", F, U, Z);
+  }
+  return 0;
+}
+
index 5b6f87acc6fbf13de9bed3c2d7dd81fcd9798963..ea160ccc502cc053932761e5d8a4076bfddc6d96 100644 (file)
@@ -8,6 +8,7 @@ set(TracePCTests
   CounterTest
   CallerCalleeTest
   NullDerefTest
+  MinimizeCorpusTest
   )
 
 foreach(Test ${TracePCTests})