tests: add a test for ctest_memcheck UndefinedBehaviorSanitizer

This commit is contained in:
Ben Boeckel 2014-10-06 14:13:37 -04:00 committed by Brad King
parent 816c100ae2
commit 9ba8bf123c
2 changed files with 38 additions and 0 deletions

View File

@ -151,6 +151,23 @@ set_tests_properties(CTestTestMemcheckDummyAddressSanitizer PROPERTIES
PASS_REGULAR_EXPRESSION
".*Memory checking results:.*heap-buffer-overflow - 1.*")
#-----------------------------------------------------------------------------
# add UndefinedBehaviorSanitizer test
set(CTEST_EXTRA_CODE
"set(CTEST_MEMORYCHECK_SANITIZER_OPTIONS \"simulate_sanitizer=1\")
")
set(CMAKELISTS_EXTRA_CODE
"add_test(NAME TestSan COMMAND \"${CMAKE_COMMAND}\"
-P \"${CMAKE_CURRENT_SOURCE_DIR}/testUndefinedBehaviorSanitizer.cmake\")
")
gen_mc_test_internal(DummyUndefinedBehaviorSanitizer "" -DMEMCHECK_TYPE=UndefinedBehaviorSanitizer)
set(CMAKELISTS_EXTRA_CODE )
set(CTEST_EXTRA_CODE)
set_tests_properties(CTestTestMemcheckDummyUndefinedBehaviorSanitizer PROPERTIES
PASS_REGULAR_EXPRESSION
".*Memory checking results:.*left shift of negative value -256 - 1.*")
#-----------------------------------------------------------------------------
gen_mc_test(DummyPurify "\${PSEUDO_PURIFY}")

View File

@ -0,0 +1,21 @@
# this file simulates a program that has been built with undefined behavior
# sanitizer options
message("UBSAN_OPTIONS = [$ENV{UBSAN_OPTIONS}]")
string(REGEX REPLACE ".*log_path=\"([^\"]*)\".*" "\\1" LOG_FILE "$ENV{UBSAN_OPTIONS}")
message("LOG_FILE=[${LOG_FILE}]")
# if we are not asked to simulate address sanitizer don't do it
if(NOT "$ENV{UBSAN_OPTIONS}]" MATCHES "simulate_sanitizer.1")
return()
endif()
# clear the log file
file(REMOVE "${LOG_FILE}.2343")
# create an error like undefined behavior santizer creates;
# these names come from ubsan_diag.cc and ubsan_handlers.cc
# in llvm
file(APPEND "${LOG_FILE}.2343"
"<unknown>: runtime error: left shift of negative value -256
")