REGEX_ESCAPE_STRING ( CTEST_ESCAPED_CMAKE_CURRENT_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}" )
foreach ( _retval 0 1 )
configure_file ( "${CMAKE_CURRENT_SOURCE_DIR}/memtester.cxx.in" "${CMAKE_CURRENT_BINARY_DIR}/ret${_retval}.cxx" @ONLY )
endforeach ( )
include_directories ( ${ CMake_SOURCE_DIR } /Source ${ CMake_BINARY_DIR } /Source )
# create binaries that we will use as a pseudo memory checker
add_executable ( pseudo_valgrind "${CMAKE_CURRENT_BINARY_DIR}/ret0.cxx" )
set_target_properties ( pseudo_valgrind PROPERTIES OUTPUT_NAME valgrind )
target_link_libraries ( pseudo_valgrind CMakeLib )
# 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 ( )
add_executable ( pseudo_purify "${CMAKE_CURRENT_BINARY_DIR}/ret0.cxx" )
set_target_properties ( pseudo_purify PROPERTIES OUTPUT_NAME purify )
target_link_libraries ( pseudo_purify CMakeLib )
add_executable ( pseudo_BC "${CMAKE_CURRENT_BINARY_DIR}/ret0.cxx" )
set_target_properties ( pseudo_BC PROPERTIES OUTPUT_NAME BC )
target_link_libraries ( pseudo_BC CMakeLib )
# binary to be used as pre- and post-memcheck command that fails
add_executable ( memcheck_fail "${CMAKE_CURRENT_BINARY_DIR}/ret1.cxx" )
target_link_libraries ( memcheck_fail CMakeLib )
# 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 )
if ( APPLE )
# 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 ( )
set ( BULLSEYE_MSG "(BullseyeCoverage[^\n]*\n)?" )
function ( gen_mc_test_internal NAME CHECKER )
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 }
C O M M A N D $ { C M A K E _ C T E S T _ C O M M A N D }
- 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 "
$ { A R G N }
)
endfunction ( gen_mc_test_internal )
function ( gen_mc_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 _ 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 >
$ { A R G N }
)
endfunction ( gen_mc_test )
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 >
$ { A R G N }
)
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 T E S T _ E S C A P E D _ 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 . 1 . l o g \ n ( .*\n ) ? E r r o r i n r e a d s c r i p t : $ { C T E S T _ E S C A P E D _ 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 )
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}" )
gen_mcnl_test ( DummyPurifyNoLogfile "\${PSEUDO_PURIFY}" )
gen_mcnl_test ( DummyValgrindNoLogfile "\${PSEUDO_VALGRIND}" )
gen_mcnl_test ( DummyBCNoLogfile "\${PSEUDO_BC}" )
set ( CTEST_EXTRA_CODE "string(REPLACE \" \" \"\\\\ \" PRE_POST_COMMAND \"\${CTEST_MEMORYCHECK_COMMAND}\")
set ( CTEST_CUSTOM_PRE_MEMCHECK \"\${PRE_POST_COMMAND} pre command\ " )
set ( CTEST_CUSTOM_POST_MEMCHECK \"\${PRE_POST_COMMAND} post 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}" )
unset ( CTEST_EXTRA_CONFIG )
gen_mc_test ( DummyValgrindTwoTargets "\${PSEUDO_VALGRIND}" "-VV" )
set ( CTEST_EXTRA_CONFIG "set(CTEST_MEMORYCHECK_SUPPRESSIONS_FILE \" \${CMAKE_CURRENT_BINARY_DIR}/does-not-exist\")")
unset ( CMAKELISTS_EXTRA_CODE )
gen_mc_test ( DummyValgrindInvalidSupFile "\${PSEUDO_VALGRIND}" )
# CTest will add the logfile option before any custom options. Set the logfile
# again, this time to an empty string. 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 \" --log-file=\ ")" )
gen_mc_test ( DummyValgrindCustomOptions "\${PSEUDO_VALGRIND}" )
unset ( CTEST_EXTRA_CONFIG )
gen_mc_test ( NotExist "\${CTEST_BINARY_DIRECTORY}/no-memcheck-exe" )
gen_mc_test ( Unknown "${CMAKE_COMMAND}" )
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}" )
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 T E S T _ E S C A P E D _ 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 " )
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.
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
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 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 } $ " )
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 T E S T _ E S C A P E 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 T E S T _ E S C A P E D _ 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 ( )
set_tests_properties ( CTestTestMemcheckDummyValgrindIgnoreMemcheck
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 2 / 2 T e s t #2: RunCMakeAgain .*${NORMAL_CTEST_OUTPUT}${BULLSEYE_MSG}$")
set_tests_properties ( CTestTestMemcheckDummyBC PROPERTIES
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")
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 T E S T _ E S C A P E D _ 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 " )
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 T E S T _ E S C A P E D _ 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 . 1 . 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 " )
set_tests_properties ( CTestTestMemcheckDummyValgrindTwoTargets PROPERTIES
P A S S _ R E G U L A R _ E X P R E S S I O N
" \ n M e m o r y c h e c k p r o j e c t $ { C T E S T _ E S C A P E D _ 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 T w o T a r g e t s \ n . * \ n * S t a r t 1 : R u n C M a k e \ n ( .*\n ) ? M e m o r y c h e c k c o m m a n d : . * \ " - - l o g - f i l e = $ { C T E S T _ E S C A P E D _ 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 T w o T a r g e t 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 . 1 . l o g \ " \ " - q \ " . * \ n * S t a r t 2 : R u n C M a k e A g a i n \ n ( .*\n ) ? M e m o r y c h e c k c o m m a n d : . * \ " - - l o g - f i l e = $ { C T E S T _ E S C A P E D _ 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 T w o T a r g e t 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 . 2 . l o g \ " \ " - q \ " . * \ n " )