diff options
author | Andreas Schneider <asn@cryptomilk.org> | 2018-09-25 11:55:45 +0200 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2018-09-25 12:42:12 +0200 |
commit | 7d45035dd511c1175601317a6b470077322e35d8 (patch) | |
tree | b57fdc5c7b79ba0ab033038754a29b1739112c25 | |
parent | 5a4072c35f70ab1849415f71865a0821d2ec885d (diff) | |
download | cmocka-7d45035dd511c1175601317a6b470077322e35d8.tar.gz cmocka-7d45035dd511c1175601317a6b470077322e35d8.tar.xz cmocka-7d45035dd511c1175601317a6b470077322e35d8.zip |
cmake: Add -DCMAKE_BUILD_TYPE=UndefinedSanitizer
-rw-r--r-- | cmake/Modules/DefineCompilerFlags.cmake | 12 | ||||
-rw-r--r-- | tests/CMakeLists.txt | 41 |
2 files changed, 38 insertions, 15 deletions
diff --git a/cmake/Modules/DefineCompilerFlags.cmake b/cmake/Modules/DefineCompilerFlags.cmake index 98109dc..3277b99 100644 --- a/cmake/Modules/DefineCompilerFlags.cmake +++ b/cmake/Modules/DefineCompilerFlags.cmake @@ -22,4 +22,16 @@ if (UNIX AND NOT WIN32) CACHE STRING "Flags used by the linker during the creation of shared libraries during ADDRESSSANITIZER builds.") set(CMAKE_EXEC_LINKER_FLAGS_ADDRESSSANITIZER "-fsanitize=address" CACHE STRING "Flags used by the linker during ADDRESSSANITIZER builds.") + + # Activate with: -DCMAKE_BUILD_TYPE=UndefinedSanitizer + set(CMAKE_C_FLAGS_UNDEFINEDSANITIZER "-g -O1 -fsanitize=undefined -fsanitize=null -fsanitize=alignment -fno-sanitize-recover" + CACHE STRING "Flags used by the C compiler during UNDEFINEDSANITIZER builds.") + set(CMAKE_CXX_FLAGS_UNDEFINEDSANITIZER "-g -O1 -fsanitize=undefined -fsanitize=null -fsanitize=alignment -fno-sanitize-recover" + CACHE STRING "Flags used by the CXX compiler during UNDEFINEDSANITIZER builds.") + set(CMAKE_SHARED_LINKER_FLAGS_UNDEFINEDSANITIZER "-fsanitize=undefined" + CACHE STRING "Flags used by the linker during the creation of shared libraries during UNDEFINEDSANITIZER builds.") + set(CMAKE_MODULE_LINKER_FLAGS_UNDEFINEDSANITIZER "-fsanitize=undefined" + CACHE STRING "Flags used by the linker during the creation of shared libraries during UNDEFINEDSANITIZER builds.") + set(CMAKE_EXEC_LINKER_FLAGS_UNDEFINEDSANITIZER "-fsanitize=undefined" + CACHE STRING "Flags used by the linker during UNDEFINEDSANITIZER builds.") endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 33d2578..5d8b280 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,5 +1,14 @@ project(tests C) +set(TEST_EXCEPTION_HANDLER TRUE) +if (CMAKE_BUILD_TYPE) + message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") + string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER) + if (CMAKE_BUILD_TYPE_LOWER STREQUAL "undefinedsanitizer") + set(TEST_EXCEPTION_HANDLER FALSE) + endif() +endif() + set(CMOCKA_TESTS test_alloc test_group_setup_assert @@ -9,7 +18,6 @@ set(CMOCKA_TESTS test_groups test_assert_macros test_assert_macros_fail - test_exception_handler test_basics test_skip test_strmatch @@ -20,6 +28,10 @@ set(CMOCKA_TESTS test_returns_fail test_wildcard) +if (TEST_EXCEPTION_HANDLER) + list(APPEND CMOCKA_TESTS test_exception_handler) +endif() + foreach(_CMOCKA_TEST ${CMOCKA_TESTS}) add_cmocka_test(${_CMOCKA_TEST} ${_CMOCKA_TEST}.c ${CMOCKA_STATIC_LIBRARY}) target_include_directories(${_CMOCKA_TEST} PRIVATE ${cmocka_BINARY_DIR}) @@ -73,20 +85,19 @@ set_tests_properties( ) # test_exception_handler -if (WIN32) - set_tests_properties( - test_exception_handler - PROPERTIES - PASS_REGULAR_EXPRESSION - "EXCEPTION_ACCESS_VIOLATION occurred at") -else() - set_tests_properties( - test_exception_handler - PROPERTIES - PASS_REGULAR_EXPRESSION - "Test failed with exception: (Segmentation fault|Segmentation Fault|11|Illegal instruction)" - ) -endif (WIN32) +if (TEST_EXCEPTION_HANDLER) + if (WIN32) + set_tests_properties(test_exception_handler + PROPERTIES + PASS_REGULAR_EXPRESSION + "EXCEPTION_ACCESS_VIOLATION occurred at") + else() + set_tests_properties(test_exception_handler + PROPERTIES + PASS_REGULAR_EXPRESSION + "Test failed with exception: (Segmentation fault|Segmentation Fault|11|Illegal instruction)") + endif (WIN32) +endif (TEST_EXCEPTION_HANDLER) set_tests_properties( test_setup_fail |