2015-01-30 00:01:07 +01:00
|
|
|
# Build all these tests with -O0, otherwise optimizations may merge some
|
|
|
|
# basic blocks and we'll fail to discover the targets.
|
2016-05-26 22:55:05 +02:00
|
|
|
# We change the flags for every build type because we might be doing
|
|
|
|
# a multi-configuration build (e.g. Xcode) where CMAKE_BUILD_TYPE doesn't
|
|
|
|
# mean anything.
|
|
|
|
set(variables_to_filter
|
|
|
|
CMAKE_CXX_FLAGS_RELEASE
|
|
|
|
CMAKE_CXX_FLAGS_DEBUG
|
|
|
|
CMAKE_CXX_FLAGS_RELWITHDEBINFO
|
|
|
|
CMAKE_CXX_FLAGS_MINSIZEREL
|
|
|
|
LIBFUZZER_FLAGS_BASE
|
|
|
|
)
|
|
|
|
foreach (VARNAME ${variables_to_filter})
|
|
|
|
string(REPLACE " " ";" BUILD_FLAGS_AS_LIST "${${VARNAME}}")
|
|
|
|
set(new_flags "")
|
|
|
|
foreach (flag ${BUILD_FLAGS_AS_LIST})
|
|
|
|
# NOTE: Use of XX here is to avoid a CMake warning due to CMP0054
|
|
|
|
if (NOT ("XX${flag}" MATCHES "XX-O[0123s]"))
|
|
|
|
set(new_flags "${new_flags} ${flag}")
|
|
|
|
else()
|
|
|
|
set(new_flags "${new_flags} -O0")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
set(${VARNAME} "${new_flags}")
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
# Enable the coverage instrumentation (it is disabled for the Fuzzer lib).
|
|
|
|
set(CMAKE_CXX_FLAGS "${LIBFUZZER_FLAGS_BASE} -fsanitize-coverage=edge,indirect-calls")
|
2015-01-30 00:01:07 +01:00
|
|
|
|
2016-05-27 05:14:40 +02:00
|
|
|
# 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
|
|
|
|
###############################################################################
|
2015-05-08 23:45:19 +02:00
|
|
|
|
2015-01-29 17:58:29 +01:00
|
|
|
set(Tests
|
2016-04-27 21:52:34 +02:00
|
|
|
AccumulateAllocationsTest
|
2016-01-14 00:02:30 +01:00
|
|
|
BufferOverflowOnInput
|
2015-10-23 01:55:39 +02:00
|
|
|
CallerCalleeTest
|
[sanitizer/coverage] Add AFL-style coverage counters (search heuristic for fuzzing).
Introduce -mllvm -sanitizer-coverage-8bit-counters=1
which adds imprecise thread-unfriendly 8-bit coverage counters.
The run-time library maps these 8-bit counters to 8-bit bitsets in the same way
AFL (http://lcamtuf.coredump.cx/afl/technical_details.txt) does:
counter values are divided into 8 ranges and based on the counter
value one of the bits in the bitset is set.
The AFL ranges are used here: 1, 2, 3, 4-7, 8-15, 16-31, 32-127, 128+.
These counters provide a search heuristic for single-threaded
coverage-guided fuzzers, we do not expect them to be useful for other purposes.
Depending on the value of -fsanitize-coverage=[123] flag,
these counters will be added to the function entry blocks (=1),
every basic block (=2), or every edge (=3).
Use these counters as an optional search heuristic in the Fuzzer library.
Add a test where this heuristic is critical.
llvm-svn: 231166
2015-03-04 00:27:02 +01:00
|
|
|
CounterTest
|
2016-06-07 22:22:15 +02:00
|
|
|
CustomCrossOverTest
|
2016-02-13 03:29:38 +01:00
|
|
|
CustomMutatorTest
|
2016-05-25 23:00:17 +02:00
|
|
|
EmptyTest
|
2015-02-20 04:02:37 +01:00
|
|
|
FourIndependentBranchesTest
|
2015-01-30 00:01:07 +01:00
|
|
|
FullCoverageSetTest
|
2016-01-16 02:23:12 +01:00
|
|
|
InitializeTest
|
2015-07-30 03:34:58 +02:00
|
|
|
MemcmpTest
|
2016-02-04 01:02:17 +01:00
|
|
|
LeakTest
|
2016-03-24 02:32:08 +01:00
|
|
|
LeakTimeoutTest
|
2015-01-29 17:58:29 +01:00
|
|
|
NullDerefTest
|
2016-05-25 02:15:36 +02:00
|
|
|
NullDerefOnEmptyTest
|
2016-02-12 03:32:03 +01:00
|
|
|
NthRunCrashTest
|
2016-05-07 01:38:07 +02:00
|
|
|
OutOfMemoryTest
|
2016-01-14 03:36:44 +01:00
|
|
|
RepeatedMemcmp
|
2015-07-22 00:51:49 +02:00
|
|
|
SimpleCmpTest
|
2015-09-04 02:12:11 +02:00
|
|
|
SimpleDictionaryTest
|
2016-03-04 00:45:29 +01:00
|
|
|
SimpleFnAdapterTest
|
2015-09-08 23:22:52 +02:00
|
|
|
SimpleHashTest
|
2015-01-29 17:58:29 +01:00
|
|
|
SimpleTest
|
2016-05-27 00:17:32 +02:00
|
|
|
SimpleThreadedTest
|
2016-03-18 21:58:29 +01:00
|
|
|
SpamyTest
|
2015-08-05 20:23:01 +02:00
|
|
|
StrcmpTest
|
2015-07-30 04:33:45 +02:00
|
|
|
StrncmpTest
|
2015-07-31 03:33:06 +02:00
|
|
|
SwitchTest
|
2016-01-06 01:03:35 +01:00
|
|
|
ThreadedTest
|
2015-01-29 17:58:29 +01:00
|
|
|
TimeoutTest
|
|
|
|
)
|
|
|
|
|
2016-06-07 06:44:39 +02:00
|
|
|
if(APPLE)
|
|
|
|
# LeakSanitizer is not supported on OSX right now
|
|
|
|
set(HAS_LSAN 0)
|
|
|
|
message(WARNING "LeakSanitizer is not supported on Apple platforms."
|
|
|
|
" Building and running LibFuzzer LeakSanitizer tests is disabled."
|
|
|
|
)
|
|
|
|
else()
|
|
|
|
set(HAS_LSAN 1)
|
|
|
|
endif()
|
|
|
|
|
2015-01-29 17:58:29 +01:00
|
|
|
foreach(Test ${Tests})
|
2016-05-27 05:14:40 +02:00
|
|
|
add_libfuzzer_test(${Test} SOURCES ${Test}.cpp)
|
2015-05-23 00:35:31 +02:00
|
|
|
endforeach()
|
|
|
|
|
2016-05-27 05:14:40 +02:00
|
|
|
###############################################################################
|
|
|
|
# Unit tests
|
|
|
|
###############################################################################
|
2015-01-31 00:26:57 +01:00
|
|
|
|
|
|
|
add_executable(LLVMFuzzer-Unittest
|
|
|
|
FuzzerUnittest.cpp
|
2016-03-04 00:45:29 +01:00
|
|
|
FuzzerFnAdapterUnittest.cpp
|
2015-01-31 00:26:57 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
target_link_libraries(LLVMFuzzer-Unittest
|
|
|
|
gtest
|
|
|
|
gtest_main
|
2016-05-27 05:14:40 +02:00
|
|
|
LLVMFuzzerNoMain
|
|
|
|
)
|
|
|
|
|
|
|
|
target_include_directories(LLVMFuzzer-Unittest PRIVATE
|
|
|
|
"${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include"
|
2015-01-31 00:26:57 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
set(TestBinaries ${TestBinaries} LLVMFuzzer-Unittest)
|
2016-05-27 05:14:40 +02:00
|
|
|
set_target_properties(LLVMFuzzer-Unittest
|
|
|
|
PROPERTIES RUNTIME_OUTPUT_DIRECTORY
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}"
|
|
|
|
)
|
|
|
|
###############################################################################
|
|
|
|
# Additional tests
|
|
|
|
###############################################################################
|
2015-01-31 00:26:57 +01:00
|
|
|
|
2016-05-27 05:14:40 +02:00
|
|
|
include_directories(..)
|
2016-06-02 07:48:09 +02:00
|
|
|
|
|
|
|
if(APPLE)
|
2016-06-07 06:44:49 +02:00
|
|
|
message(WARNING "DataflowSanitizer is not supported on Apple platforms."
|
|
|
|
" Building and running LibFuzzer DataflowSanitizer tests is disabled."
|
2016-06-02 07:48:09 +02:00
|
|
|
)
|
|
|
|
set(HAS_DFSAN 0)
|
|
|
|
else()
|
|
|
|
set(HAS_DFSAN 1)
|
|
|
|
add_subdirectory(dfsan)
|
|
|
|
endif()
|
|
|
|
|
2015-11-10 00:17:45 +01:00
|
|
|
add_subdirectory(uninstrumented)
|
2016-05-09 23:02:36 +02:00
|
|
|
add_subdirectory(ubsan)
|
2015-12-02 03:49:37 +01:00
|
|
|
add_subdirectory(trace-bb)
|
2016-02-26 22:33:56 +01:00
|
|
|
add_subdirectory(trace-pc)
|
|
|
|
|
2016-05-27 05:14:40 +02:00
|
|
|
###############################################################################
|
|
|
|
# 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.
|
|
|
|
###############################################################################
|
2016-02-26 22:33:56 +01:00
|
|
|
|
2016-05-27 05:14:40 +02:00
|
|
|
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
|
2015-01-29 17:58:29 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
add_lit_testsuite(check-fuzzer "Running Fuzzer tests"
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}
|
2015-02-03 22:57:32 +01:00
|
|
|
DEPENDS ${TestBinaries} FileCheck not
|
2015-01-29 17:58:29 +01:00
|
|
|
)
|