Add fuzz corpus and blackbox tests

This commit is contained in:
2024-05-20 15:12:05 -07:00
parent 89c6aae53a
commit 49a1ec0ab7
145 changed files with 63 additions and 5 deletions

View File

@@ -129,6 +129,30 @@ if(BUILD_TREE_VIS)
endif()
if(BUILD_TESTING)
# corpus tests, which are tests curated by libfuzzer. The goal is to get broad
# coverage with a small number of tests.
file(GLOB CORPUS_TESTS ${CMAKE_SOURCE_DIR}/corpus/*)
if(NOT APPLE)
# libfuzzer target, to generate/manage corpus
set(FUZZ_FLAGS "-fsanitize=fuzzer-no-link,address,undefined")
include(CheckCXXCompilerFlag)
cmake_push_check_state()
set(CMAKE_REQUIRED_LINK_OPTIONS -fsanitize=fuzzer-no-link)
check_cxx_compiler_flag(-fsanitize=fuzzer-no-link HAS_LIB_FUZZER)
cmake_pop_check_state()
if(HAS_LIB_FUZZER)
add_executable(facade_fuzz FacadeFuzz.cpp)
target_link_libraries(facade_fuzz PRIVATE ${PROJECT_NAME})
target_compile_options(facade_fuzz PRIVATE ${FUZZ_FLAGS} ${TEST_FLAGS})
target_link_options(facade_fuzz PRIVATE ${FUZZ_FLAGS} -fsanitize=fuzzer)
endif()
endif()
add_executable(rootset_test RootSet.cpp)
target_compile_definitions(rootset_test PRIVATE ENABLE_ROOTSET_TESTS)
target_compile_options(rootset_test PRIVATE -fsanitize=address,undefined
@@ -156,11 +180,14 @@ if(BUILD_TESTING)
${TEST_FLAGS})
target_link_options(facade_test PRIVATE -fsanitize=address,undefined)
add_executable(facade_fuzz FacadeFuzz.cpp)
target_link_libraries(facade_fuzz PRIVATE ${PROJECT_NAME})
target_compile_options(facade_fuzz PRIVATE -fsanitize=address,undefined,fuzzer
${TEST_FLAGS})
target_link_options(facade_fuzz PRIVATE -fsanitize=address,undefined,fuzzer)
# blackbox tests
add_executable(driver TestDriver.cpp FacadeFuzz.cpp)
target_compile_options(driver PRIVATE ${TEST_FLAGS})
target_link_libraries(driver PRIVATE ${PROJECT_NAME})
foreach(TEST ${CORPUS_TESTS})
get_filename_component(hash ${TEST} NAME)
add_test(NAME versioned_map_blackbox_${hash} COMMAND driver ${TEST})
endforeach()
# symbol visibility tests
if(NOT CMAKE_BUILD_TYPE STREQUAL Debug)