Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing sanitizers #5

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ endif ()

option(SPROKIT_ENABLE_TESTING "Build tests" OFF)
if (SPROKIT_ENABLE_TESTING)
include("${sprokit_source_dir}/conf/sprokit-macro-tests.cmake")
include("${sprokit_source_dir}/cmake/support/test.cmake")
set(CTEST_NEW_FORMAT ON)

include(CTest)

add_subdirectory(tests)
Expand Down
6 changes: 6 additions & 0 deletions cmake/snippets/configuration.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
# "SPROKIT_CONFIGURATION=\"$<CONFIGURATION>\""
# "SPROKIT_CONFIGURATION_L=L\"$<CONFIGURATION>\"")

if (DEFINED CMAKE_BUILD_TYPE)
set_property(CACHE CMAKE_BUILD_TYPE
PROPERTY
STRINGS "Release;Debug;RelWithDebInfo;MinSizeRel")
endif ()

# XXX(cmake): 2.8.12
foreach (config IN LISTS CMAKE_CONFIGURATION_TYPES)
string(TOUPPER "${config}" upper_config)
Expand Down
24 changes: 18 additions & 6 deletions cmake/snippets/flags-gnu.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,28 @@ if (SPROKIT_ENABLE_WERROR)
sprokit_want_compiler_flag(-Werror)
endif ()

cmake_dependent_option(SPROKIT_ENABLE_CLANG_CATCH_UNDEFINED_BEHAVIOR "Use clang to flag undefined behavior" OFF
sprokit_using_clang OFF)
if (SPROKIT_ENABLE_CLANG_CATCH_UNDEFINED_BEHAVIOR)
option(SPROKIT_ENABLE_CATCH_UNDEFINED_BEHAVIOR "Flag undefined behavior" OFF)
if (SPROKIT_ENABLE_CATCH_UNDEFINED_BEHAVIOR)
sprokit_want_compiler_flag(-fcatch-undefined-behavior)
endif ()

option(SPROKIT_ENABLE_ASAN "Enable address sanitization" OFF)
cmake_dependent_option(SPROKIT_ENABLE_ASAN "Enable address sanitization" OFF
"NOT SPROKIT_ENABLE_TSAN" OFF)
cmake_dependent_option(SPROKIT_ENABLE_TSAN "Enable thread sanitization" OFF
"NOT SPROKIT_ENABLE_ASAN" OFF)
option(SPROKIT_ENABLE_UBSAN "Enable undefined behavior sanitization" OFF)

if (SPROKIT_ENABLE_ASAN)
sprokit_check_compiler_flag(sprokit_warnings -fsanitize=address)
sprokit_check_compiler_flag(sprokit_warnings -fno-omit-frame-pointer)
sprokit_want_compiler_flag(-fsanitize=address)
sprokit_want_compiler_flag(-fno-omit-frame-pointer)
endif ()

if (SPROKIT_ENABLE_TSAN)
sprokit_want_compiler_flag(-fsanitize=thread)
endif ()

if (SPROKIT_ENABLE_UBSAN)
sprokit_want_compiler_flag(-fsanitize=undefined)
endif ()

option(SPROKIT_ENABLE_COVERAGE "Build with coverage testing" OFF)
Expand Down
2 changes: 1 addition & 1 deletion cmake/snippets/flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function (sprokit_want_compiler_flag flag)

check_cxx_compiler_flag("${flag}" "have_compiler_flag-${safeflag}")

if ("have_compiler_flag-${safeflag}")
if (have_compiler_flag-${safeflag})
sprokit_add_flag("${flag}" ${ARGN})
endif ()
endfunction ()
Expand Down
23 changes: 23 additions & 0 deletions cmake/support/test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,29 @@ function (_sprokit_declare_tool_group tool)
${tool})
endfunction ()

foreach (sanitizer ASAN TSAN UBSAN)
set("SPROKIT_SANITIZER_OPTIONS_${sanitizer}" ""
CACHE STRING "Options to set for ${sanitizer}")
mark_as_advanced("SPROKIT_SANITIZER_OPTIONS_${sanitizer}")
endforeach ()

set(memcheck_type "Valgrind")
set(sanitizer_options "")
if (SPROKIT_ENABLE_ASAN)
set(memcheck_type "AddressSanitizer")
set(sanitizer_options "${SPROKIT_SANITIZER_OPTIONS_ASAN}")
elseif (SPROKIT_ENABLE_TSAN)
set(memcheck_type "ThreadSanitizer")
set(sanitizer_options "${SPROKIT_SANITIZER_OPTIONS_TSAN}")
elseif (SPROKIT_ENABLE_UBSAN)
set(memcheck_type "UndefinedBehaviorSanitizer")
set(sanitizer_options "${SPROKIT_SANITIZER_OPTIONS_UBSAN}")
endif ()
set(MEMORYCHECK_TYPE "${memcheck_type}"
CACHE INTERNAL "Memory tool expected to be used")
set(MEMORYCHECK_SANITIZER_OPTIONS "${sanitizer_options}"
CACHE INTERNAL "Options for the enabled sanitizer")

if (VALGRIND_EXECUTABLE)
set(sprokit_valgrind_arguments)

Expand Down
43 changes: 24 additions & 19 deletions conf/dashboard.ctest.in
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ set(CTEST_BUILD_NAME_BASE "@CDASH_BUILD_NAME@")
set(SPROKIT_ENABLE_COVERAGE "@SPROKIT_ENABLE_COVERAGE@")

set(CTEST_COVERAGE_COMMAND "@GCOV_EXECUTABLE@")
set(CTEST_MEMORYCHECK_COMMAND "@VALGRIND_EXECUTABLE@")
set(CTEST_MEMORYCHECK_TYPE "@MEMORYCHECK_TYPE@")
set(CTEST_MEMORYCHECK_SANITIZER_OPTIONS "@MEMORYCHECK_SANITIZER_OPTIONS@")
set(CTEST_VALGRIND_COMMAND "@VALGRIND_EXECUTABLE@")

###############################################################################

Expand Down Expand Up @@ -178,28 +180,31 @@ ctest_configure()
ctest_build()
ctest_test()

if (WITH_MEMCHECK AND CTEST_MEMORYCHECK_COMMAND)
set(valgrind_arguments)
if (WITH_MEMCHECK)
if (CTEST_MEMORYCHECK_TYPE STREQUAL "Valgrind" AND CTEST_VALGRIND_COMMAND)
set(valgrind_arguments)

list(APPEND valgrind_arguments
"--quiet")
list(APPEND valgrind_arguments
"--leak-check=yes")
list(APPEND valgrind_arguments
"--show-reachable=yes")
list(APPEND valgrind_arguments
"--num-callers=50")
list(APPEND valgrind_arguments
"--quiet")
list(APPEND valgrind_arguments
"--leak-check=yes")
list(APPEND valgrind_arguments
"--show-reachable=yes")
list(APPEND valgrind_arguments
"--num-callers=50")

file(GLOB valgrind_suppressions
"${CTEST_SOURCE_DIRECTORY}/tests/data/valgrind/*.supp")
file(GLOB valgrind_suppressions
"${CTEST_SOURCE_DIRECTORY}/tests/data/valgrind/*.supp")

foreach (valgrind_suppression IN LISTS valgrind_suppressions)
list(APPEND valgrind_arguments
"--suppressions=${valgrind_suppression}")
endforeach ()
foreach (valgrind_suppression IN LISTS valgrind_suppressions)
list(APPEND valgrind_arguments
"--suppressions=${valgrind_suppression}")
endforeach ()

set(CTEST_MEMORYCHECK_COMMAND_OPTIONS
"${valgrind_arguments}")
set(CTEST_MEMORYCHECK_COMMAND "${CTEST_VALGRIND_COMMAND}")
set(CTEST_MEMORYCHECK_COMMAND_OPTIONS
"${valgrind_arguments}")
endif ()

ctest_memcheck()
endif ()
Expand Down
3 changes: 0 additions & 3 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ else ()
"${sprokit_binary_dir}/tests")
endif ()

include("${sprokit_source_dir}/conf/sprokit-macro-tests.cmake")
include("${sprokit_source_dir}/cmake/support/test.cmake")

set(sprokit_test_data_directory
"${CMAKE_CURRENT_SOURCE_DIR}/data")

Expand Down