summaryrefslogtreecommitdiffstats
path: root/compiler-rt/test/fuzzer
diff options
context:
space:
mode:
Diffstat (limited to 'compiler-rt/test/fuzzer')
-rw-r--r--compiler-rt/test/fuzzer/CMakeLists.txt67
-rw-r--r--compiler-rt/test/fuzzer/lit.cfg11
-rw-r--r--compiler-rt/test/fuzzer/lit.site.cfg.in2
3 files changed, 59 insertions, 21 deletions
diff --git a/compiler-rt/test/fuzzer/CMakeLists.txt b/compiler-rt/test/fuzzer/CMakeLists.txt
index bd511123255..5577b0051c5 100644
--- a/compiler-rt/test/fuzzer/CMakeLists.txt
+++ b/compiler-rt/test/fuzzer/CMakeLists.txt
@@ -8,36 +8,65 @@ if(COMPILER_RT_INCLUDE_TESTS)
list(APPEND LIBFUZZER_TEST_DEPS FuzzerUnitTests)
endif()
-set(LIBFUZZER_TESTSUITES)
+set(EXCLUDE_FROM_ALL ON)
+add_custom_target(check-fuzzer)
if(COMPILER_RT_INCLUDE_TESTS)
# libFuzzer unit tests.
configure_lit_site_cfg(
${CMAKE_CURRENT_SOURCE_DIR}/unit/lit.site.cfg.in
${CMAKE_CURRENT_BINARY_DIR}/unit/lit.site.cfg)
- list(APPEND LIBFUZZER_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/unit)
+ add_lit_testsuite(check-fuzzer-unit "Running Fuzzer unit tests"
+ ${CMAKE_CURRENT_BINARY_DIR}/unit
+ DEPENDS ${LIBFUZZER_TEST_DEPS})
+ set_target_properties(check-fuzzer-unit PROPERTIES FOLDER "Compiler-RT Tests")
+ add_dependencies(check-fuzzer check-fuzzer-unit)
endif()
-foreach(arch ${FUZZER_SUPPORTED_ARCH})
- set(LIBFUZZER_TEST_COMPILER ${COMPILER_RT_TEST_COMPILER})
- get_test_cc_for_arch(${arch} LIBFUZZER_TEST_COMPILER LIBFUZZER_TEST_FLAGS)
+macro(test_fuzzer stdlib)
+ cmake_parse_arguments(TEST "" "" "DEPS" ${ARGN})
+ string(REPLACE "+" "x" stdlib_name ${stdlib})
+ string(REPLACE "-" ";" stdlib_list ${stdlib_name})
+ set(STDLIB_CAPITALIZED "")
+ foreach(part IN LISTS stdlib_list)
+ string(SUBSTRING ${part} 0 1 first_letter)
+ string(TOUPPER ${first_letter} first_letter)
+ string(REGEX REPLACE "^.(.*)" "${first_letter}\\1" part "${part}")
+ set(STDLIB_CAPITALIZED "${STDLIB_CAPITALIZED}${part}")
+ endforeach()
+ foreach(arch ${FUZZER_SUPPORTED_ARCH})
+ set(LIBFUZZER_TEST_COMPILER ${COMPILER_RT_TEST_COMPILER})
+ get_test_cc_for_arch(${arch} LIBFUZZER_TEST_COMPILER LIBFUZZER_TEST_FLAGS)
- string(TOUPPER ${arch} ARCH_UPPER_CASE)
- set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}Config)
+ set(LIBFUZZER_TEST_STDLIB ${stdlib})
- # LIT-based libFuzzer tests.
- configure_lit_site_cfg(
- ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
- ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg
- )
- list(APPEND LIBFUZZER_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
+ string(TOUPPER ${arch} ARCH_UPPER_CASE)
+ set(CONFIG_NAME ${ARCH_UPPER_CASE}${STDLIB_CAPITALIZED}${OS_NAME}Config)
-endforeach()
+ # LIT-based libFuzzer tests.
+ configure_lit_site_cfg(
+ ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
+ ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg
+ )
-set(EXCLUDE_FROM_ALL ON)
+ add_lit_testsuite(check-fuzzer-${stdlib_name} "Running Fuzzer ${stdlib} tests"
+ ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}
+ DEPENDS ${LIBFUZZER_TEST_DEPS})
+ if(TEST_DEPS)
+ add_dependencies(check-fuzzer-${stdlib_name} ${TEST_DEPS})
+ endif()
+ set_target_properties(check-fuzzer-${stdlib_name} PROPERTIES FOLDER "Compiler-RT Tests")
+ add_dependencies(check-fuzzer check-fuzzer-${stdlib_name})
+ endforeach()
+endmacro()
-add_lit_testsuite(check-fuzzer "Running Fuzzer tests"
- ${LIBFUZZER_TESTSUITES}
- DEPENDS ${LIBFUZZER_TEST_DEPS})
-set_target_properties(check-fuzzer PROPERTIES FOLDER "Compiler-RT Tests")
+test_fuzzer("default")
+if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
+ if(TARGET cxx_shared)
+ test_fuzzer("libc++" DEPS cxx_shared)
+ endif()
+ if(TARGET cxx_static)
+ test_fuzzer("static-libc++" DEPS cxx_static)
+ endif()
+endif()
diff --git a/compiler-rt/test/fuzzer/lit.cfg b/compiler-rt/test/fuzzer/lit.cfg
index 19be31d1ace..8a1d3eeb928 100644
--- a/compiler-rt/test/fuzzer/lit.cfg
+++ b/compiler-rt/test/fuzzer/lit.cfg
@@ -7,6 +7,8 @@ config.test_format = lit.formats.ShTest(True)
config.suffixes = ['.test']
config.test_source_root = os.path.dirname(__file__)
+config.environment['LD_LIBRARY_PATH'] = config.llvm_library_dir
+
# Choose between lit's internal shell pipeline runner and a real shell. If
# LIT_USE_INTERNAL_SHELL is in the environment, we use that as an override.
use_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL")
@@ -51,8 +53,13 @@ config.substitutions.append(('%libfuzzer_src', libfuzzer_src_root))
def generate_compiler_cmd(is_cpp=True, fuzzer_enabled=True):
compiler_cmd = config.c_compiler
- link_cmd = '-lc++' if any(x in config.target_triple for x in ('darwin', 'freebsd')) else '-lstdc++'
- std_cmd = '-std=c++11' if is_cpp else ''
+ if config.clang and config.stdlib == 'libc++':
+ link_cmd = '-stdlib=libc++'
+ elif config.clang and config.stdlib == 'static-libc++':
+ link_cmd = '-stdlib=libc++ -lc++abi -static-libstdc++'
+ else:
+ link_cmd = '-lc++' if any(x in config.target_triple for x in ('darwin', 'freebsd')) else '-lstdc++'
+ std_cmd = '--driver-mode=g++ -std=c++11' if is_cpp else ''
sanitizers = ['address']
if fuzzer_enabled:
sanitizers.append('fuzzer')
diff --git a/compiler-rt/test/fuzzer/lit.site.cfg.in b/compiler-rt/test/fuzzer/lit.site.cfg.in
index 7f70c8f67d6..41f14666621 100644
--- a/compiler-rt/test/fuzzer/lit.site.cfg.in
+++ b/compiler-rt/test/fuzzer/lit.site.cfg.in
@@ -5,9 +5,11 @@ config.test_exec_root = "@CMAKE_CURRENT_BINARY_DIR@"
config.cpp_compiler = "@LIBFUZZER_TEST_COMPILER@"
config.target_flags = "@LIBFUZZER_TEST_FLAGS@"
config.c_compiler = "@LIBFUZZER_TEST_COMPILER@"
+config.stdlib = "@LIBFUZZER_TEST_STDLIB@"
config.osx_sysroot_flag = "@OSX_SYSROOT_FLAG@"
config.cmake_binary_dir = "@CMAKE_BINARY_DIR@"
+config.llvm_library_dir = "@LLVM_LIBRARY_DIR@"
config.target_triple = "@TARGET_TRIPLE@"
# Load common config for all compiler-rt lit tests.
OpenPOWER on IntegriCloud