[llvm] r270958 - [LibFuzzer] Refactor declaration of tests in CMake.
Dan Liew via llvm-commits
llvm-commits at lists.llvm.org
Thu May 26 20:14:40 PDT 2016
Author: delcypher
Date: Thu May 26 22:14:40 2016
New Revision: 270958
URL: http://llvm.org/viewvc/llvm-project?rev=270958&view=rev
Log:
[LibFuzzer] Refactor declaration of tests in CMake.
Add a new CMake function (``add_libfuzzer_test()``) to simplify
declaration of executables for testing LibFuzzer and use it to
reorganise how tests are declared.
Note that configuration of the lit configuration files has been moved
as late as possible because we are going to need to disable some tests
for some platforms and we will need to propagate this information into
the lit configuration.
Note the code for custom mains was removed because no tests are
currently written for this and Kostya seems happy to remove this.
Differential Revision: http://reviews.llvm.org/D20706
Modified:
llvm/trunk/lib/Fuzzer/test/CMakeLists.txt
llvm/trunk/lib/Fuzzer/test/dfsan/CMakeLists.txt
llvm/trunk/lib/Fuzzer/test/trace-bb/CMakeLists.txt
llvm/trunk/lib/Fuzzer/test/trace-pc/CMakeLists.txt
llvm/trunk/lib/Fuzzer/test/ubsan/CMakeLists.txt
llvm/trunk/lib/Fuzzer/test/uninstrumented/CMakeLists.txt
Modified: llvm/trunk/lib/Fuzzer/test/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/CMakeLists.txt?rev=270958&r1=270957&r2=270958&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/CMakeLists.txt (original)
+++ llvm/trunk/lib/Fuzzer/test/CMakeLists.txt Thu May 26 22:14:40 2016
@@ -27,13 +27,39 @@ endforeach()
# Enable the coverage instrumentation (it is disabled for the Fuzzer lib).
set(CMAKE_CXX_FLAGS "${LIBFUZZER_FLAGS_BASE} -fsanitize-coverage=edge,indirect-calls")
-set(DFSanTests
- MemcmpTest
- SimpleCmpTest
- StrcmpTest
- StrncmpTest
- SwitchTest
- )
+# add_libfuzzer_test(<name>
+# SOURCES source0.cpp [source1.cpp ...]
+# )
+#
+# Declares a LibFuzzer test executable with target name LLVMFuzzer-<name>.
+#
+# One or more source files to be compiled into the binary must be declared
+# after the SOURCES keyword.
+function(add_libfuzzer_test name)
+ set(multi_arg_options "SOURCES")
+ cmake_parse_arguments(
+ "add_libfuzzer_test" "" "" "${multi_arg_options}" ${ARGN})
+ if ("${add_libfuzzer_test_SOURCES}" STREQUAL "")
+ message(FATAL_ERROR "Source files must be specified")
+ endif()
+ add_executable(LLVMFuzzer-${name}
+ ${add_libfuzzer_test_SOURCES}
+ )
+ target_link_libraries(LLVMFuzzer-${name} LLVMFuzzer)
+ # Place binary where llvm-lit expects to find it
+ set_target_properties(LLVMFuzzer-${name}
+ PROPERTIES RUNTIME_OUTPUT_DIRECTORY
+ "${CMAKE_BINARY_DIR}/lib/Fuzzer/test"
+ )
+ set(TestBinaries ${TestBinaries} LLVMFuzzer-${name} PARENT_SCOPE)
+endfunction()
+
+# Variable to keep track of all test targets
+set(TestBinaries)
+
+###############################################################################
+# Basic tests
+###############################################################################
set(Tests
AccumulateAllocationsTest
@@ -67,107 +93,60 @@ set(Tests
TimeoutTest
)
-set(CustomMainTests
- )
-
-set(UninstrumentedTests
- UninstrumentedTest
- )
-
-set(TraceBBTests
- SimpleTest
- )
-
-set(TracePCTests
- FourIndependentBranchesTest
- FullCoverageSetTest
- )
-
-set(UbsanTests
- SignedIntOverflowTest
- )
-
-set(TestBinaries)
-
foreach(Test ${Tests})
- add_executable(LLVMFuzzer-${Test}
- ${Test}.cpp
- )
- target_link_libraries(LLVMFuzzer-${Test}
- LLVMFuzzer
- )
- set(TestBinaries ${TestBinaries} LLVMFuzzer-${Test})
-endforeach()
-
-foreach(Test ${CustomMainTests})
- add_executable(LLVMFuzzer-${Test}
- ${Test}.cpp
- )
- target_link_libraries(LLVMFuzzer-${Test}
- LLVMFuzzerNoMain
- )
- set(TestBinaries ${TestBinaries} LLVMFuzzer-${Test})
+ add_libfuzzer_test(${Test} SOURCES ${Test}.cpp)
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)
+###############################################################################
+# Unit tests
+###############################################################################
add_executable(LLVMFuzzer-Unittest
FuzzerUnittest.cpp
FuzzerFnAdapterUnittest.cpp
- $<TARGET_OBJECTS:LLVMFuzzerNoMainObjects>
)
target_link_libraries(LLVMFuzzer-Unittest
gtest
gtest_main
+ LLVMFuzzerNoMain
+ )
+
+target_include_directories(LLVMFuzzer-Unittest PRIVATE
+ "${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include"
)
set(TestBinaries ${TestBinaries} LLVMFuzzer-Unittest)
+set_target_properties(LLVMFuzzer-Unittest
+ PROPERTIES RUNTIME_OUTPUT_DIRECTORY
+ "${CMAKE_CURRENT_BINARY_DIR}"
+)
+###############################################################################
+# Additional tests
+###############################################################################
+include_directories(..)
add_subdirectory(dfsan)
-
-foreach(Test ${DFSanTests})
- set(TestBinaries ${TestBinaries} LLVMFuzzer-${Test}-DFSan)
-endforeach()
-
add_subdirectory(uninstrumented)
-
-foreach(Test ${UninstrumentedTests})
- set(TestBinaries ${TestBinaries} LLVMFuzzer-${Test}-Uninstrumented)
-endforeach()
-
add_subdirectory(ubsan)
-
-foreach(Test ${UbsanTests})
- set(TestBinaries ${TestBinaries} LLVMFuzzer-${Test}-Ubsan)
-endforeach()
-
add_subdirectory(trace-bb)
-
-foreach(Test ${TraceBBTests})
- set(TestBinaries ${TestBinaries} LLVMFuzzer-${Test}-TraceBB)
-endforeach()
-
add_subdirectory(trace-pc)
-foreach(Test ${TracePCTests})
- set(TestBinaries ${TestBinaries} LLVMFuzzer-${Test}-TracePC)
-endforeach()
+###############################################################################
+# Configure lit to run the tests
+#
+# Note this is done after declaring all tests so we can inform lit if any tests
+# need to be disabled.
+###############################################################################
-set_target_properties(${TestBinaries}
- PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+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
)
add_lit_testsuite(check-fuzzer "Running Fuzzer tests"
Modified: llvm/trunk/lib/Fuzzer/test/dfsan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/dfsan/CMakeLists.txt?rev=270958&r1=270957&r2=270958&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/dfsan/CMakeLists.txt (original)
+++ llvm/trunk/lib/Fuzzer/test/dfsan/CMakeLists.txt Thu May 26 22:14:40 2016
@@ -3,12 +3,17 @@
set(CMAKE_CXX_FLAGS
"${LIBFUZZER_FLAGS_BASE} -fno-sanitize=all -fsanitize=dataflow")
+set(DFSanTests
+ MemcmpTest
+ SimpleCmpTest
+ StrcmpTest
+ StrncmpTest
+ SwitchTest
+ )
+
foreach(Test ${DFSanTests})
- add_executable(LLVMFuzzer-${Test}-DFSan
- ../${Test}.cpp
- )
- target_link_libraries(LLVMFuzzer-${Test}-DFSan
- LLVMFuzzer
- )
+ add_libfuzzer_test(${Test}-DFSan SOURCES ../${Test}.cpp)
endforeach()
+# Propagate value into parent directory
+set(TestBinaries ${TestBinaries} PARENT_SCOPE)
Modified: llvm/trunk/lib/Fuzzer/test/trace-bb/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/trace-bb/CMakeLists.txt?rev=270958&r1=270957&r2=270958&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/trace-bb/CMakeLists.txt (original)
+++ llvm/trunk/lib/Fuzzer/test/trace-bb/CMakeLists.txt Thu May 26 22:14:40 2016
@@ -3,12 +3,13 @@
set(CMAKE_CXX_FLAGS
"${LIBFUZZER_FLAGS_BASE} -fsanitize-coverage=edge,trace-bb")
+set(TraceBBTests
+ SimpleTest
+ )
+
foreach(Test ${TraceBBTests})
- add_executable(LLVMFuzzer-${Test}-TraceBB
- ../${Test}.cpp
- )
- target_link_libraries(LLVMFuzzer-${Test}-TraceBB
- LLVMFuzzer
- )
+ add_libfuzzer_test(${Test}-TraceBB SOURCES ../${Test}.cpp)
endforeach()
+# Propagate value into parent directory
+set(TestBinaries ${TestBinaries} PARENT_SCOPE)
Modified: llvm/trunk/lib/Fuzzer/test/trace-pc/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/trace-pc/CMakeLists.txt?rev=270958&r1=270957&r2=270958&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/trace-pc/CMakeLists.txt (original)
+++ llvm/trunk/lib/Fuzzer/test/trace-pc/CMakeLists.txt Thu May 26 22:14:40 2016
@@ -3,12 +3,14 @@
set(CMAKE_CXX_FLAGS
"${LIBFUZZER_FLAGS_BASE} -fno-sanitize-coverage=8bit-counters -fsanitize-coverage=trace-pc")
+set(TracePCTests
+ FourIndependentBranchesTest
+ FullCoverageSetTest
+ )
+
foreach(Test ${TracePCTests})
- add_executable(LLVMFuzzer-${Test}-TracePC
- ../${Test}.cpp
- )
- target_link_libraries(LLVMFuzzer-${Test}-TracePC
- LLVMFuzzer
- )
+ add_libfuzzer_test(${Test}-TracePC SOURCES ../${Test}.cpp)
endforeach()
+# Propagate value into parent directory
+set(TestBinaries ${TestBinaries} PARENT_SCOPE)
Modified: llvm/trunk/lib/Fuzzer/test/ubsan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/ubsan/CMakeLists.txt?rev=270958&r1=270957&r2=270958&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/ubsan/CMakeLists.txt (original)
+++ llvm/trunk/lib/Fuzzer/test/ubsan/CMakeLists.txt Thu May 26 22:14:40 2016
@@ -3,12 +3,13 @@
set(CMAKE_CXX_FLAGS
"${LIBFUZZER_FLAGS_BASE} -fsanitize=undefined -fno-sanitize-recover=all")
+set(UbsanTests
+ SignedIntOverflowTest
+ )
+
foreach(Test ${UbsanTests})
- add_executable(LLVMFuzzer-${Test}-Ubsan
- ../${Test}.cpp
- )
- target_link_libraries(LLVMFuzzer-${Test}-Ubsan
- LLVMFuzzer
- )
+ add_libfuzzer_test(${Test}-Ubsan SOURCES ../${Test}.cpp)
endforeach()
+# Propagate value into parent directory
+set(TestBinaries ${TestBinaries} PARENT_SCOPE)
Modified: llvm/trunk/lib/Fuzzer/test/uninstrumented/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/uninstrumented/CMakeLists.txt?rev=270958&r1=270957&r2=270958&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/uninstrumented/CMakeLists.txt (original)
+++ llvm/trunk/lib/Fuzzer/test/uninstrumented/CMakeLists.txt Thu May 26 22:14:40 2016
@@ -3,12 +3,13 @@
set(CMAKE_CXX_FLAGS
"${LIBFUZZER_FLAGS_BASE} -fno-sanitize=all -fno-sanitize-coverage=edge,trace-cmp,indirect-calls,8bit-counters")
+set(UninstrumentedTests
+ UninstrumentedTest
+ )
+
foreach(Test ${UninstrumentedTests})
- add_executable(LLVMFuzzer-${Test}-Uninstrumented
- ../${Test}.cpp
- )
- target_link_libraries(LLVMFuzzer-${Test}-Uninstrumented
- LLVMFuzzer
- )
+ add_libfuzzer_test(${Test}-Uninstrumented SOURCES ../${Test}.cpp)
endforeach()
+# Propagate value into parent directory
+set(TestBinaries ${TestBinaries} PARENT_SCOPE)
More information about the llvm-commits
mailing list