👷 added flags for Valgrind and Clang sanitizer

This commit is contained in:
Niels Lohmann 2017-08-25 20:12:21 +02:00
parent c87b080cc5
commit 05b97c473a
No known key found for this signature in database
GPG key ID: 7F3CEA63AE251B69
2 changed files with 29 additions and 10 deletions

View file

@ -29,34 +29,28 @@ matrix:
include: include:
# Valgrind # Valgrind
- os: linux - os: linux
compiler: gcc compiler: gcc
env: env:
- COMPILER=g++-4.9 - COMPILER=g++-4.9
- SPECIAL=valgrind - CMAKE_OPTIONS=-DJSON_Valgrind=ON
addons: addons:
apt: apt:
sources: ['ubuntu-toolchain-r-test'] sources: ['ubuntu-toolchain-r-test']
packages: [g++-4.9, valgrind] packages: [g++-4.9, valgrind]
after_success:
- make check TEST_PREFIX="valgrind --error-exitcode=1 --leak-check=full " TEST_PATTERN=""
# clang sanitizer # clang sanitizer
- os: linux - os: linux
compiler: clang compiler: clang
env: env:
- COMPILER=clang++-5.0 - COMPILER=clang++-5.0
- SPECIAL=sanitizer - CMAKE_OPTIONS=-DJSON_Sanitizer=ON
addons: addons:
apt: apt:
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-5.0'] sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-5.0']
packages: ['g++-6', 'clang-5.0'] packages: ['g++-6', 'clang-5.0']
after_success:
- make clang_sanitize -j4
# cppcheck # cppcheck
- os: linux - os: linux
compiler: gcc compiler: gcc
env: env:
@ -289,7 +283,7 @@ script:
# compile and execute unit tests # compile and execute unit tests
- mkdir -p build && cd build - mkdir -p build && cd build
- cmake .. && cmake --build . --config Release -- -j4 - cmake .. ${CMAKE_OPTIONS} && cmake --build . --config Release -- -j4
- ctest -C Release -V - ctest -C Release -V
- cd .. - cd ..

View file

@ -1,3 +1,19 @@
option(JSON_Sanitizer "Build with Clang Sanitizer" OFF)
option(JSON_Valgrind "Execute tests with Valgrind" OFF)
if(JSON_Sanitizer)
if(NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O2 -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer")
endif()
endif()
if(JSON_Valgrind)
find_program(CMAKE_MEMORYCHECK_COMMAND valgrind)
set(MEMORYCHECK_COMMAND_OPTIONS "--error-exitcode=1 --leak-check=full")
set(memcheck_command "${CMAKE_MEMORYCHECK_COMMAND} ${CMAKE_MEMORYCHECK_COMMAND_OPTIONS}")
separate_arguments(memcheck_command)
endif()
############################################################################# #############################################################################
# Catch library with the main function to speed up build # Catch library with the main function to speed up build
############################################################################# #############################################################################
@ -35,7 +51,7 @@ foreach(file ${files})
target_link_libraries(${testcase} ${JSON_TARGET_NAME}) target_link_libraries(${testcase} ${JSON_TARGET_NAME})
if(NOT MSVC) if(NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated -Wno-float-equal") set_target_properties(${testcase} PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated -Wno-float-equal")
endif() endif()
include(cotire OPTIONAL) include(cotire OPTIONAL)
@ -54,4 +70,13 @@ foreach(file ${files})
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
) )
set_tests_properties("${testcase}_all" PROPERTIES LABELS "all") set_tests_properties("${testcase}_all" PROPERTIES LABELS "all")
if(JSON_Valgrind)
add_test(NAME "${testcase}_valgrind"
COMMAND ${memcheck_command} ${CMAKE_CURRENT_BINARY_DIR}/${testcase}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
set_tests_properties("${testcase}_valgrind" PROPERTIES LABELS "valgrind")
endif()
endforeach() endforeach()