2012-09-30 20:21:18 +04:00
foreach ( _retval 0 1 )
2013-05-05 19:00:24 +04:00
configure_file ( "${CMAKE_CURRENT_SOURCE_DIR}/memtester.cxx.in" "${CMAKE_CURRENT_BINARY_DIR}/ret${_retval}.cxx" @ONLY )
2012-09-30 20:21:18 +04:00
endforeach ( )
2013-05-05 19:00:24 +04:00
include_directories ( ${ CMake_SOURCE_DIR } /Source ${ CMake_BINARY_DIR } /Source )
2012-09-30 20:21:18 +04:00
# create binaries that we will use as a pseudo memory checker
2013-05-05 19:00:24 +04:00
add_executable ( pseudo_valgrind "${CMAKE_CURRENT_BINARY_DIR}/ret0.cxx" )
2012-09-30 20:21:18 +04:00
set_target_properties ( pseudo_valgrind PROPERTIES OUTPUT_NAME valgrind )
2013-05-05 19:00:24 +04:00
target_link_libraries ( pseudo_valgrind CMakeLib )
2012-09-30 20:21:18 +04:00
# Xcode 2.x forgets to create the output directory before linking
# the individual architectures.
if ( CMAKE_OSX_ARCHITECTURES AND XCODE AND NOT "${XCODE_VERSION}" MATCHES "^[^12]" )
add_custom_command ( TARGET pseudo_valgrind
P R E _ B U I L D C O M M A N D $ { C M A K E _ C O M M A N D } - E m a k e _ d i r e c t o r y " $ { C M A K E _ C F G _ I N T D I R } "
)
endif ( )
2013-05-05 19:00:24 +04:00
add_executable ( pseudo_purify "${CMAKE_CURRENT_BINARY_DIR}/ret0.cxx" )
2012-09-30 20:21:18 +04:00
set_target_properties ( pseudo_purify PROPERTIES OUTPUT_NAME purify )
2013-05-05 19:00:24 +04:00
target_link_libraries ( pseudo_purify CMakeLib )
add_executable ( pseudo_BC "${CMAKE_CURRENT_BINARY_DIR}/ret0.cxx" )
2012-09-30 20:21:18 +04:00
set_target_properties ( pseudo_BC PROPERTIES OUTPUT_NAME BC )
2013-05-05 19:00:24 +04:00
target_link_libraries ( pseudo_BC CMakeLib )
2012-09-30 20:21:18 +04:00
# binary to be used as pre- and post-memcheck command that fails
2013-05-05 19:00:24 +04:00
add_executable ( memcheck_fail "${CMAKE_CURRENT_BINARY_DIR}/ret1.cxx" )
target_link_libraries ( memcheck_fail CMakeLib )
2013-05-06 15:09:22 +04:00
# Binaries that are used as memchecker that do not write the expected
# output file. Need to be in their own subdirectory as they have the
# same filenames.
add_subdirectory ( NoLogDummyChecker )
2013-05-23 08:31:47 +04:00
if ( APPLE )
2013-05-13 14:23:32 +04:00
# filter out additional messages by Guard Malloc integrated in Xcode
set ( GUARD_MALLOC_MSG "(ctest\([0-9]+\) malloc: [^\n]*\n)*" )
set ( NORMAL_CTEST_OUTPUT "\n1/1 MemCheck #1: RunCMake \\.+ Passed +[0-9]+\\.[0-9]+ sec\n${GUARD_MALLOC_MSG}\n${GUARD_MALLOC_MSG}100% tests passed, 0 tests failed out of 1\n.*\n-- Processing memory checking output: \n${GUARD_MALLOC_MSG}Memory checking results:\n${GUARD_MALLOC_MSG}" )
else ( )
set ( NORMAL_CTEST_OUTPUT "\n1/1 MemCheck #1: RunCMake \\.+ Passed +[0-9]+\\.[0-9]+ sec\n\n100% tests passed, 0 tests failed out of 1\n.*\n-- Processing memory checking output: \nMemory checking results:\n" )
endif ( )
2013-05-05 19:00:24 +04:00
set ( BULLSEYE_MSG "(BullseyeCoverage[^\n]*\n)?" )
2012-09-30 20:21:18 +04:00
2013-05-06 15:09:22 +04:00
function ( gen_mc_test_internal NAME CHECKER )
2013-05-05 22:44:07 +04:00
set ( SUBTEST_NAME "${NAME}" )
set ( CHECKER_COMMAND "${CHECKER}" )
foreach ( _file IN ITEMS CMakeLists.txt CTestConfig.cmake test.cmake )
configure_file ( "${CMAKE_CURRENT_SOURCE_DIR}/${_file}.in"
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { N A M E } / $ { _ f i l e } " @ O N L Y )
endforeach ( )
add_test ( NAME CTestTestMemcheck ${ NAME }
2012-09-30 20:21:18 +04:00
C O M M A N D $ { C M A K E _ C T E S T _ C O M M A N D }
2013-05-05 22:44:07 +04:00
- C $ < C O N F I G U R A T I O N >
- S " $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { N A M E } / t e s t . c m a k e " - V
- - o u t p u t - l o g " $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { N A M E } / t e s t O u t p u t . l o g "
2013-05-06 15:09:22 +04:00
$ { A R G N }
)
endfunction ( gen_mc_test_internal )
function ( gen_mc_test NAME CHECKER )
gen_mc_test_internal ( ${ NAME } "${CHECKER}"
2012-09-30 20:21:18 +04:00
- D P S E U D O _ B C = $ < T A R G E T _ F I L E : p s e u d o _ B C >
- D P S E U D O _ P U R I F Y = $ < T A R G E T _ F I L E : p s e u d o _ p u r i f y >
- D P S E U D O _ V A L G R I N D = $ < T A R G E T _ F I L E : p s e u d o _ v a l g r i n d >
- D E R R O R _ C O M M A N D = $ < T A R G E T _ F I L E : m e m c h e c k _ f a i l >
)
2013-05-05 22:44:07 +04:00
endfunction ( gen_mc_test )
2013-05-06 15:09:22 +04:00
function ( gen_mcnl_test NAME CHECKER )
gen_mc_test_internal ( ${ NAME } ${ CHECKER }
- D P S E U D O _ B C = $ < T A R G E T _ F I L E : p s e u d o n l _ B C >
- D P S E U D O _ P U R I F Y = $ < T A R G E T _ F I L E : p s e u d o n l _ p u r i f y >
- D P S E U D O _ V A L G R I N D = $ < T A R G E T _ F I L E : p s e u d o n l _ v a l g r i n d >
)
set_tests_properties ( CTestTestMemcheck ${ NAME }
P R O P E R T I E S
P A S S _ R E G U L A R _ E X P R E S S I O N " \ n C a n n o t f i n d m e m o r y t e s t e r o u t p u t f i l e : $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { N A M E } / T e s t i n g / T e m p o r a r y / M e m o r y C h e c k e r . l o g \ n ( .*\n ) ? E r r o r i n r e a d s c r i p t : $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { N A M E } / t e s t . c m a k e \ n " )
endfunction ( gen_mcnl_test )
2013-05-05 22:44:07 +04:00
unset ( CTEST_EXTRA_CONFIG )
unset ( CTEST_EXTRA_CODE )
unset ( CMAKELISTS_EXTRA_CODE )
gen_mc_test ( DummyPurify "\${PSEUDO_PURIFY}" )
gen_mc_test ( DummyValgrind "\${PSEUDO_VALGRIND}" )
gen_mc_test ( DummyBC "\${PSEUDO_BC}" )
2013-05-06 15:09:22 +04:00
gen_mcnl_test ( DummyPurifyNoLogfile "\${PSEUDO_PURIFY}" )
gen_mcnl_test ( DummyValgrindNoLogfile "\${PSEUDO_VALGRIND}" )
gen_mcnl_test ( DummyBCNoLogfile "\${PSEUDO_BC}" )
2013-05-05 22:44:07 +04:00
set ( CTEST_EXTRA_CODE "set(CTEST_CUSTOM_PRE_MEMCHECK \" \${CTEST_MEMORYCHECK_COMMAND}\")\nset(CTEST_CUSTOM_POST_MEMCHECK \"\${CTEST_MEMORYCHECK_COMMAND}\")")
gen_mc_test ( DummyValgrindPrePost "\${PSEUDO_VALGRIND}" )
set ( CTEST_EXTRA_CODE "set(CTEST_CUSTOM_POST_MEMCHECK \" \${ERROR_COMMAND}\")")
gen_mc_test ( DummyValgrindFailPost "\${PSEUDO_VALGRIND}" )
set ( CTEST_EXTRA_CODE "set(CTEST_CUSTOM_PRE_MEMCHECK \" \${ERROR_COMMAND}\")")
gen_mc_test ( DummyValgrindFailPre "\${PSEUDO_VALGRIND}" )
unset ( CTEST_EXTRA_CODE )
set ( CTEST_EXTRA_CONFIG "set(CTEST_CUSTOM_MEMCHECK_IGNORE RunCMakeAgain)\n" )
set ( CMAKELISTS_EXTRA_CODE "add_test(NAME RunCMakeAgain COMMAND \" \${CMAKE_COMMAND}\" --version ) " )
gen_mc_test ( DummyValgrindIgnoreMemcheck "\${PSEUDO_VALGRIND}" )
2013-05-07 02:03:16 +04:00
set ( CTEST_EXTRA_CONFIG "set(CTEST_MEMORYCHECK_SUPPRESSIONS_FILE \" \${CMAKE_CURRENT_BINARY_DIR}/does-not-exist\")")
2013-05-05 22:44:07 +04:00
unset ( CMAKELISTS_EXTRA_CODE )
2013-05-07 02:03:16 +04:00
gen_mc_test ( DummyValgrindInvalidSupFile "\${PSEUDO_VALGRIND}" )
2013-05-09 14:24:09 +04:00
# CTest will add the logfile option as last option. Tell the dummy memcheck
# to ignore that argument. This will cause the logfile to be missing, which
# will be the prove for us that the custom option is indeed used.
set ( CTEST_EXTRA_CONFIG "set(CTEST_MEMORYCHECK_COMMAND_OPTIONS \" --\ ")" )
gen_mc_test ( DummyValgrindCustomOptions "\${PSEUDO_VALGRIND}" )
2013-05-07 02:03:16 +04:00
unset ( CTEST_EXTRA_CONFIG )
2013-05-05 22:44:07 +04:00
gen_mc_test ( NotExist "\${CTEST_BINARY_DIRECTORY}/no-memcheck-exe" )
gen_mc_test ( Unknown "${CMAKE_COMMAND}" )
2012-09-30 20:21:18 +04:00
string ( REPLACE "\\" "\\\\" CMAKE_COMMAND_ESCAPED "${CMAKE_COMMAND}" )
string ( REPLACE "(" "\\(" CMAKE_COMMAND_ESCAPED "${CMAKE_COMMAND_ESCAPED}" )
string ( REPLACE ")" "\\)" CMAKE_COMMAND_ESCAPED "${CMAKE_COMMAND_ESCAPED}" )
string ( REPLACE "+" "\\+" CMAKE_COMMAND_ESCAPED "${CMAKE_COMMAND_ESCAPED}" )
2012-10-02 23:56:48 +04:00
2013-05-06 16:39:05 +04:00
set_tests_properties ( CTestTestMemcheckUnknown PROPERTIES
P A S S _ R E G U L A R _ E X P R E S S I O N " D o n o t u n d e r s t a n d m e m o r y c h e c k e r : $ { C M A K E _ C O M M A N D _ E S C A P E D } \ n ( .*\n ) ? E r r o r i n r e a d s c r i p t : $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / U n k n o w n / t e s t . c m a k e \ n " )
2012-09-30 20:21:18 +04:00
set_tests_properties ( CTestTestMemcheckNotExist PROPERTIES
P A S S _ R E G U L A R _ E X P R E S S I O N " M e m o r y c h e c k e r \ \ ( M e m o r y C h e c k C o m m a n d \ \ ) n o t s e t , o r c a n n o t f i n d t h e s p e c i f i e d p r o g r a m . " )
# It is a valid result if valgrind does not output any files (can e.g. happen
# if you have not compiled in debug mode), so these tests will not fail.
2013-05-05 19:00:24 +04:00
set_tests_properties ( CTestTestMemcheckDummyValgrind
C T e s t T e s t M e m c h e c k D u m m y V a l g r i n d P r e P o s t
C T e s t T e s t M e m c h e c k D u m m y P u r i f y
2012-09-30 20:21:18 +04:00
P R O P E R T I E S
2013-05-05 19:00:24 +04:00
P A S S _ R E G U L A R _ E X P R E S S I O N " $ { N O R M A L _ C T E S T _ O U T P U T } $ { B U L L S E Y E _ M S G } $ " )
2012-09-30 20:21:18 +04:00
foreach ( _pp Pre Post )
string ( TOLOWER ${ _pp } _pp_lower )
set_tests_properties ( CTestTestMemcheckDummyValgrindFail ${ _pp }
P R O P E R T I E S
P A S S _ R E G U L A R _ E X P R E S S I O N " \ n P r o b l e m r u n n i n g c o m m a n d : $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } [ ^ \ n ] * f a i l [ ^ \ n ] * \ n ( .*\n ) ? P r o b l e m e x e c u t i n g $ { _ p p _ l o w e r } - m e m c h e c k c o m m a n d \ \ ( s \ \ \ ) . \ n ( .*\n ) ? E r r o r i n r e a d s c r i p t : $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / D u m m y V a l g r i n d F a i l $ { _ p p } / t e s t . c m a k e \ n " )
endforeach ( )
2012-10-01 19:51:00 +04:00
set_tests_properties ( CTestTestMemcheckDummyValgrindIgnoreMemcheck
P R O P E R T I E S
2013-05-05 19:00:24 +04:00
P A S S _ R E G U L A R _ E X P R E S S I O N " \ n 2 / 2 T e s t #2: RunCMakeAgain .*${NORMAL_CTEST_OUTPUT}${BULLSEYE_MSG}$")
2012-09-30 20:21:18 +04:00
set_tests_properties ( CTestTestMemcheckDummyBC PROPERTIES
2013-05-05 19:00:24 +04:00
P A S S _ R E G U L A R _ E X P R E S S I O N " \ n 1 / 1 M e m C h e c k #1: RunCMake \\.+ Passed +[0-9]+.[0-9]+ sec\n\n100% tests passed, 0 tests failed out of 1\n(.*\n)?Error parsing XML in stream at line 1: no element found\n")
2013-05-07 02:03:16 +04:00
set_tests_properties ( CTestTestMemcheckDummyValgrindInvalidSupFile PROPERTIES
P A S S _ R E G U L A R _ E X P R E S S I O N " \ n C a n n o t f i n d m e m o r y c h e c k e r s u p p r e s s i o n f i l e : $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / d o e s - n o t - e x i s t \ n " )
2013-05-09 14:24:09 +04:00
set_tests_properties ( CTestTestMemcheckDummyValgrindCustomOptions PROPERTIES
P A S S _ R E G U L A R _ E X P R E S S I O N " \ n C a n n o t f i n d m e m o r y t e s t e r o u t p u t f i l e : $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / D u m m y V a l g r i n d C u s t o m O p t i o n s / T e s t i n g / T e m p o r a r y / M e m o r y C h e c k e r . l o g \ n ( .*\n ) ? E r r o r i n r e a d s c r i p t : $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / D u m m y V a l g r i n d C u s t o m O p t i o n s / t e s t . c m a k e \ n " )