2013-06-03 18:42:12 +04:00
REGEX_ESCAPE_STRING ( CTEST_ESCAPED_CMAKE_CURRENT_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}" )
2013-12-15 03:31:14 +04:00
get_filename_component ( CTEST_REALPATH_CMAKE_CURRENT_BINARY_DIR
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } " R E A L P A T H
)
REGEX_ESCAPE_STRING ( CTEST_ESCAPED_REALPATH_CMAKE_CURRENT_BINARY_DIR
" $ { C T E S T _ R E A L P A T H _ C M A K E _ C U R R E N T _ B I N A R Y _ D I R } "
)
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
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-08-16 19:19:08 +04:00
if ( APPLE )
# filter out additional messages by Guard Malloc integrated in Xcode
2013-09-13 22:46:15 +04:00
set ( guard_malloc_msg "ctest\\([0-9]+\\) malloc: " )
2013-08-16 19:19:08 +04:00
set ( guard_malloc_lines "(${guard_malloc_msg}[^\n]*\n)*" )
set ( guard_malloc_output "${guard_malloc_msg}|" )
else ( )
set ( guard_malloc_msg "" )
set ( guard_malloc_lines "" )
set ( guard_malloc_output "" )
endif ( )
# When this entire test runs under coverage or memcheck tools
# they may add output to the end, so match known cases:
# - Bullseye adds a "BullseyeCoverage..." line.
2013-08-16 17:39:52 +04:00
# - Valgrind memcheck may add extra "==..." lines.
set ( other_tool_output "((${guard_malloc_output}BullseyeCoverage|==)[^\n]*\n)*" )
2013-08-16 19:19:08 +04:00
string ( REPLACE "\r\n" "\n" ctest_and_tool_outputs "
1 / 1 M e m C h e c k #1: RunCMake \\.+ Passed +[0-9]+\\.[0-9]+ sec
$ { g u a r d _ m a l l o c _ l i n e s }
1 0 0 % t e s t s p a s s e d , 0 t e s t s f a i l e d o u t o f 1
. *
- - P r o c e s s i n g m e m o r y c h e c k i n g o u t p u t : ( )
$ { g u a r d _ m a l l o c _ l i n e s } M e m o r y c h e c k i n g r e s u l t s :
$ { o t h e r _ t o o l _ o u t p u t } " )
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-08-08 00:25:48 +04:00
$ { A R G N }
2012-09-30 20:21:18 +04:00
)
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 >
2013-08-08 00:25:48 +04:00
$ { A R G N }
2013-05-06 15:09:22 +04:00
)
set_tests_properties ( CTestTestMemcheck ${ NAME }
P R O P E R T I E S
2013-08-08 00:25:48 +04:00
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 " )
2013-05-06 15:09:22 +04:00
endfunction ( gen_mcnl_test )
2013-05-05 22:44:07 +04:00
unset ( CTEST_EXTRA_CONFIG )
unset ( CTEST_EXTRA_CODE )
unset ( CMAKELISTS_EXTRA_CODE )
2014-07-07 23:58:02 +04:00
# add ThreadSanitizer test
set ( CTEST_EXTRA_CODE
" set ( CTEST_MEMORYCHECK_COMMAND_OPTIONS \"report_bugs=1 history_size=5 exitcode=55\ " )
" )
set ( CMAKELISTS_EXTRA_CODE
" add_test ( NAME TestSan COMMAND \"${CMAKE_COMMAND}\"
- P \ " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / t e s t T h r e a d S a n i t i z e r . c m a k e \ " )
" )
gen_mc_test_internal ( DummyThreadSanitizer "" -DMEMCHECK_TYPE=ThreadSanitizer )
2014-07-15 01:01:47 +04:00
set_tests_properties ( CTestTestMemcheckDummyThreadSanitizer 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 i n g r e s u l t s : . * d a t a r a c e . * - 1 . * d a t a r a c e o n v p t r . c t o r / d t o r v s v i r t u a l c a l l . - 1 . * h e a p - u s e - a f t e r - f r e e - 1 . * t h r e a d l e a k - 1 . * d e s t r o y o f a l o c k e d m u t e x - 1 . * d o u b l e l o c k o f a m u t e x - 1 . * u n l o c k o f a n u n l o c k e d m u t e x . o r b y a w r o n g t h r e a d . - 1 . * r e a d l o c k o f a w r i t e l o c k e d m u t e x - 1 . * r e a d u n l o c k o f a w r i t e l o c k e d m u t e x - 1 . * s i g n a l - u n s a f e c a l l i n s i d e o f a s i g n a l - 1 . * s i g n a l h a n d l e r s p o i l s e r r n o - 1 . * l o c k - o r d e r - i n v e r s i o n . p o t e n t i a l d e a d l o c k . - 1 . * " )
2014-07-07 23:58:02 +04:00
set ( CMAKELISTS_EXTRA_CODE )
set ( CTEST_EXTRA_CODE )
2014-07-15 01:01:47 +04:00
# add LeakSanitizer test
set ( CTEST_EXTRA_CODE
" set ( CTEST_MEMORYCHECK_COMMAND_OPTIONS \"report_bugs=1 history_size=5 exitcode=55\ " )
" )
set ( CMAKELISTS_EXTRA_CODE
" add_test ( NAME TestSan COMMAND \"${CMAKE_COMMAND}\"
- P \ " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / t e s t L e a k S a n i t i z e r . c m a k e \ " )
" )
gen_mc_test_internal ( DummyLeakSanitizer "" -DMEMCHECK_TYPE=AddressSanitizer )
set ( CMAKELISTS_EXTRA_CODE )
set ( CTEST_EXTRA_CODE )
set_tests_properties ( CTestTestMemcheckDummyLeakSanitizer 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 i n g r e s u l t s : . * D i r e c t l e a k - 2 . * I n d i r e c t l e a k - 1 . * " )
# add AddressSanitizer test
set ( CTEST_EXTRA_CODE
" set ( CTEST_MEMORYCHECK_COMMAND_OPTIONS \"report_bugs=1 history_size=5 exitcode=55\ " )
" )
set ( CMAKELISTS_EXTRA_CODE
" add_test ( NAME TestSan COMMAND \"${CMAKE_COMMAND}\"
- P \ " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / t e s t A d d r e s s S a n i t i z e r . c m a k e \ " )
" )
gen_mc_test_internal ( DummyAddressSanitizer "" -DMEMCHECK_TYPE=AddressSanitizer )
set ( CMAKELISTS_EXTRA_CODE )
set ( CTEST_EXTRA_CODE )
set_tests_properties ( CTestTestMemcheckDummyAddressSanitizer 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 i n g r e s u l t s : . * h e a p - b u f f e r - o v e r f l o w - 1 . * " )
2013-05-05 22:44:07 +04:00
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
2013-07-27 23:40:25 +04:00
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 \")
" )
2013-05-05 22:44:07 +04:00
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-08-08 00:25:48 +04:00
unset ( CTEST_EXTRA_CONFIG )
gen_mc_test ( DummyValgrindTwoTargets "\${PSEUDO_VALGRIND}" "-VV" )
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-08-08 00:25:48 +04:00
# 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=\ ")" )
2013-05-09 14:24:09 +04:00
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
2013-06-03 21:42:18 +04:00
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 " )
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-08-16 19:19:08 +04:00
P A S S _ R E G U L A R _ E X P R E S S I O N " $ { c t e s t _ a n d _ t o o l _ o u t p u t s } $ " )
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
2013-06-03 18:42:12 +04:00
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 " )
2012-09-30 20:21:18 +04:00
endforeach ( )
2012-10-01 19:51:00 +04:00
set_tests_properties ( CTestTestMemcheckDummyValgrindIgnoreMemcheck
P R O P E R T I E S
2013-08-16 19:19:08 +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 .*${ctest_and_tool_outputs}$")
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
2013-12-15 03:31:14 +04:00
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 _ R E A L P A T H _ 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
2013-08-08 00:25:48 +04:00
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 " )
2014-03-26 23:07:32 +04:00
2014-07-07 23:58:02 +04:00
2014-03-26 23:07:32 +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]" )
foreach ( t
m e m c h e c k _ f a i l
p s e u d o _ B C
p s e u d o _ p u r i f y
p s e u d o _ v a l g r i n d
)
add_custom_command ( TARGET ${ t }
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 } "
)
endforeach ( )
endif ( )