[llvm] r270755 - [libfuzzer] replacing unittest for truncate_units with functional test.
Mike Aizatsky via llvm-commits
llvm-commits at lists.llvm.org
Wed May 25 14:00:18 PDT 2016
Author: aizatsky
Date: Wed May 25 16:00:17 2016
New Revision: 270755
URL: http://llvm.org/viewvc/llvm-project?rev=270755&view=rev
Log:
[libfuzzer] replacing unittest for truncate_units with functional test.
Differential Revision: http://reviews.llvm.org/D20641
Added:
llvm/trunk/lib/Fuzzer/test/EmptyTest.cpp
llvm/trunk/lib/Fuzzer/test/fuzzer-trunc.test
Modified:
llvm/trunk/lib/Fuzzer/test/CMakeLists.txt
llvm/trunk/lib/Fuzzer/test/FuzzerUnittest.cpp
Modified: llvm/trunk/lib/Fuzzer/test/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/CMakeLists.txt?rev=270755&r1=270754&r2=270755&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/CMakeLists.txt (original)
+++ llvm/trunk/lib/Fuzzer/test/CMakeLists.txt Wed May 25 16:00:17 2016
@@ -18,6 +18,7 @@ set(Tests
CallerCalleeTest
CounterTest
CustomMutatorTest
+ EmptyTest
FourIndependentBranchesTest
FullCoverageSetTest
InitializeTest
Added: llvm/trunk/lib/Fuzzer/test/EmptyTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/EmptyTest.cpp?rev=270755&view=auto
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/EmptyTest.cpp (added)
+++ llvm/trunk/lib/Fuzzer/test/EmptyTest.cpp Wed May 25 16:00:17 2016
@@ -0,0 +1,11 @@
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+// A fuzzer with empty target function.
+
+#include <cstdint>
+#include <cstdlib>
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
+ return 0;
+}
Modified: llvm/trunk/lib/Fuzzer/test/FuzzerUnittest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/FuzzerUnittest.cpp?rev=270755&r1=270754&r2=270755&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/FuzzerUnittest.cpp (original)
+++ llvm/trunk/lib/Fuzzer/test/FuzzerUnittest.cpp Wed May 25 16:00:17 2016
@@ -13,10 +13,6 @@ extern "C" int LLVMFuzzerTestOneInput(co
abort();
}
-static int EmptyLLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
- return 0;
-}
-
TEST(Fuzzer, CrossOver) {
Random Rand(0);
MutationDispatcher MD(Rand);
@@ -427,21 +423,3 @@ TEST(Corpus, Distribution) {
EXPECT_GT(Hist[i], TriesPerUnit / N / 3);
}
}
-
-TEST(Corpus, TruncateUnits) {
- Random Rand(0);
- MutationDispatcher MD(Rand);
- Fuzzer::FuzzingOptions Options;
- Options.OutputCorpus = ""; // stops from writing new units.
- Fuzzer Fuzz(EmptyLLVMFuzzerTestOneInput, MD, Options);
-
- Fuzz.AddToCorpus(Unit(1024, static_cast<uint8_t>(1)));
- Fuzz.ResetCoverage();
-
- std::vector<Unit> NewCorpus;
- Fuzz.TruncateUnits(&NewCorpus);
-
- // New corpus should have a shorter unit.
- EXPECT_EQ(1ul, NewCorpus.size());
- EXPECT_EQ(1ul, NewCorpus[0].size());
-}
Added: llvm/trunk/lib/Fuzzer/test/fuzzer-trunc.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/fuzzer-trunc.test?rev=270755&view=auto
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/fuzzer-trunc.test (added)
+++ llvm/trunk/lib/Fuzzer/test/fuzzer-trunc.test Wed May 25 16:00:17 2016
@@ -0,0 +1,10 @@
+# Test truncate_units option.
+RUN: rm -rf FuzzerTruncateTestCORPUS
+RUN: mkdir FuzzerTruncateTestCORPUS
+RUN: echo "01234567890123456789012345678901234567890" > FuzzerTruncateTestCORPUS/unit1
+# Simply running a fuzzer won't produce new results
+RUN: LLVMFuzzer-EmptyTest -seed=1 -runs=100 -truncate_units=0 ./FuzzerTruncateTestCORPUS
+# Truncating would create a new unit of length 1.
+RUN: LLVMFuzzer-EmptyTest -seed=1 -runs=0 -truncate_units=1 ./FuzzerTruncateTestCORPUS
+RUN: find FuzzerTruncateTestCORPUS/b6589fc6ab0dc82cf12099d1c2d40ab994e8410c
+RUN: rm -rf FuzzerTruncateTestCORPUS
More information about the llvm-commits
mailing list