[llvm] r227639 - [fuzzer] Add a gtest-style test
Kostya Serebryany
kcc at google.com
Fri Jan 30 15:26:57 PST 2015
Author: kcc
Date: Fri Jan 30 17:26:57 2015
New Revision: 227639
URL: http://llvm.org/viewvc/llvm-project?rev=227639&view=rev
Log:
[fuzzer] Add a gtest-style test
Summary: Add one gtest-style test.
Test Plan: run on bot
Reviewers: samsonov
Reviewed By: samsonov
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D7287
Added:
llvm/trunk/lib/Fuzzer/test/FuzzerUnittest.cpp
- copied, changed from r227631, llvm/trunk/lib/Fuzzer/test/TestFuzzerCrossOver.cpp
llvm/trunk/lib/Fuzzer/test/unit/
llvm/trunk/lib/Fuzzer/test/unit/lit.cfg
llvm/trunk/lib/Fuzzer/test/unit/lit.site.cfg.in
Removed:
llvm/trunk/lib/Fuzzer/test/TestFuzzerCrossOver.cpp
Modified:
llvm/trunk/lib/Fuzzer/CMakeLists.txt
llvm/trunk/lib/Fuzzer/test/CMakeLists.txt
Modified: llvm/trunk/lib/Fuzzer/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/CMakeLists.txt?rev=227639&r1=227638&r2=227639&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/CMakeLists.txt (original)
+++ llvm/trunk/lib/Fuzzer/CMakeLists.txt Fri Jan 30 17:26:57 2015
@@ -1,15 +1,17 @@
# Disable the coverage instrumentation for the fuzzer itself.
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -fsanitize-coverage=0")
if( LLVM_USE_SANITIZE_COVERAGE )
- add_library(LLVMFuzzer STATIC
- EXCLUDE_FROM_ALL # Do not build if you are not building fuzzers.
+ add_library(LLVMFuzzerNoMain OBJECT
FuzzerCrossOver.cpp
FuzzerIO.cpp
FuzzerLoop.cpp
- FuzzerMain.cpp
FuzzerMutate.cpp
FuzzerUtil.cpp
)
+ add_library(LLVMFuzzer STATIC
+ FuzzerMain.cpp
+ $<TARGET_OBJECTS:LLVMFuzzerNoMain>
+ )
if( LLVM_INCLUDE_TESTS )
add_subdirectory(test)
Modified: llvm/trunk/lib/Fuzzer/test/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/CMakeLists.txt?rev=227639&r1=227638&r2=227639&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/CMakeLists.txt (original)
+++ llvm/trunk/lib/Fuzzer/test/CMakeLists.txt Fri Jan 30 17:26:57 2015
@@ -25,19 +25,36 @@ foreach(Test ${Tests})
set(TestBinaries ${TestBinaries} LLVMFuzzer-${Test})
endforeach()
+configure_lit_site_cfg(
+ ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
+ ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
+ )
+
+configure_lit_site_cfg(
+ ${CMAKE_CURRENT_SOURCE_DIR}/unit/lit.site.cfg.in
+ ${CMAKE_CURRENT_BINARY_DIR}/unit/lit.site.cfg
+ )
+
+include_directories(..)
+include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include)
+
+add_executable(LLVMFuzzer-Unittest
+ FuzzerUnittest.cpp
+ $<TARGET_OBJECTS:LLVMFuzzerNoMain>
+ )
+
+target_link_libraries(LLVMFuzzer-Unittest
+ gtest
+ gtest_main
+ )
+
+set(TestBinaries ${TestBinaries} LLVMFuzzer-Unittest)
+
set_target_properties(${TestBinaries}
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
-set(EXCLUDE_FROM_ALL TRUE)
add_lit_testsuite(check-fuzzer "Running Fuzzer tests"
${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${TestBinaries}
)
-set(EXCLUDE_FROM_ALL FALSE)
-
-configure_lit_site_cfg(
- ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
- ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
- )
-
Copied: llvm/trunk/lib/Fuzzer/test/FuzzerUnittest.cpp (from r227631, llvm/trunk/lib/Fuzzer/test/TestFuzzerCrossOver.cpp)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/FuzzerUnittest.cpp?p2=llvm/trunk/lib/Fuzzer/test/FuzzerUnittest.cpp&p1=llvm/trunk/lib/Fuzzer/test/TestFuzzerCrossOver.cpp&r1=227631&r2=227639&rev=227639&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/TestFuzzerCrossOver.cpp (original)
+++ llvm/trunk/lib/Fuzzer/test/FuzzerUnittest.cpp Fri Jan 30 17:26:57 2015
@@ -1,13 +1,62 @@
#include "FuzzerInternal.h"
+#include "gtest/gtest.h"
+#include <set>
-int main() {
+// For now, have TestOneInput just to make it link.
+// Later we may want to make unittests that actually call TestOneInput.
+extern "C" void TestOneInput(const uint8_t *Data, size_t Size) {
+ abort();
+}
+
+TEST(Fuzzer, CrossOver) {
using namespace fuzzer;
- Unit A({0, 1, 2, 3, 4}), B({5, 6, 7, 8, 9});
+ Unit A({0, 1, 2}), B({5, 6, 7});
Unit C;
- for (size_t Len = 1; Len < 15; Len++) {
- for (int Iter = 0; Iter < 1000; Iter++) {
+ Unit Expected[] = {
+ { 0 },
+ { 0, 1 },
+ { 0, 5 },
+ { 0, 1, 2 },
+ { 0, 1, 5 },
+ { 0, 5, 1 },
+ { 0, 5, 6 },
+ { 0, 1, 2, 5 },
+ { 0, 1, 5, 2 },
+ { 0, 1, 5, 6 },
+ { 0, 5, 1, 2 },
+ { 0, 5, 1, 6 },
+ { 0, 5, 6, 1 },
+ { 0, 5, 6, 7 },
+ { 0, 1, 2, 5, 6 },
+ { 0, 1, 5, 2, 6 },
+ { 0, 1, 5, 6, 2 },
+ { 0, 1, 5, 6, 7 },
+ { 0, 5, 1, 2, 6 },
+ { 0, 5, 1, 6, 2 },
+ { 0, 5, 1, 6, 7 },
+ { 0, 5, 6, 1, 2 },
+ { 0, 5, 6, 1, 7 },
+ { 0, 5, 6, 7, 1 },
+ { 0, 1, 2, 5, 6, 7 },
+ { 0, 1, 5, 2, 6, 7 },
+ { 0, 1, 5, 6, 2, 7 },
+ { 0, 1, 5, 6, 7, 2 },
+ { 0, 5, 1, 2, 6, 7 },
+ { 0, 5, 1, 6, 2, 7 },
+ { 0, 5, 1, 6, 7, 2 },
+ { 0, 5, 6, 1, 2, 7 },
+ { 0, 5, 6, 1, 7, 2 },
+ { 0, 5, 6, 7, 1, 2 }
+ };
+ for (size_t Len = 1; Len < 8; Len++) {
+ std::set<Unit> FoundUnits, ExpectedUnitsWitThisLength;
+ for (int Iter = 0; Iter < 3000; Iter++) {
CrossOver(A, B, &C, Len);
- Print(C);
+ FoundUnits.insert(C);
}
+ for (const Unit &U : Expected)
+ if (U.size() <= Len)
+ ExpectedUnitsWitThisLength.insert(U);
+ EXPECT_EQ(ExpectedUnitsWitThisLength, FoundUnits);
}
}
Removed: llvm/trunk/lib/Fuzzer/test/TestFuzzerCrossOver.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/TestFuzzerCrossOver.cpp?rev=227638&view=auto
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/TestFuzzerCrossOver.cpp (original)
+++ llvm/trunk/lib/Fuzzer/test/TestFuzzerCrossOver.cpp (removed)
@@ -1,13 +0,0 @@
-#include "FuzzerInternal.h"
-
-int main() {
- using namespace fuzzer;
- Unit A({0, 1, 2, 3, 4}), B({5, 6, 7, 8, 9});
- Unit C;
- for (size_t Len = 1; Len < 15; Len++) {
- for (int Iter = 0; Iter < 1000; Iter++) {
- CrossOver(A, B, &C, Len);
- Print(C);
- }
- }
-}
Added: llvm/trunk/lib/Fuzzer/test/unit/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/unit/lit.cfg?rev=227639&view=auto
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/unit/lit.cfg (added)
+++ llvm/trunk/lib/Fuzzer/test/unit/lit.cfg Fri Jan 30 17:26:57 2015
@@ -0,0 +1,7 @@
+import lit.formats
+
+config.name = "LLVMFuzzer-Unittest"
+print config.test_exec_root
+config.test_format = lit.formats.GoogleTest(".", "Unittest")
+config.suffixes = []
+config.test_source_root = config.test_exec_root
Added: llvm/trunk/lib/Fuzzer/test/unit/lit.site.cfg.in
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/unit/lit.site.cfg.in?rev=227639&view=auto
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/unit/lit.site.cfg.in (added)
+++ llvm/trunk/lib/Fuzzer/test/unit/lit.site.cfg.in Fri Jan 30 17:26:57 2015
@@ -0,0 +1,2 @@
+config.test_exec_root = "@CMAKE_CURRENT_BINARY_DIR@"
+lit_config.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/unit/lit.cfg")
More information about the llvm-commits
mailing list