Skip to content

Instantly share code, notes, and snippets.

@scivision
Last active November 5, 2023 17:51
Show Gist options
  • Save scivision/c180c393f7b86d4071a8a1ceda8bfe54 to your computer and use it in GitHub Desktop.
Save scivision/c180c393f7b86d4071a8a1ceda8bfe54 to your computer and use it in GitHub Desktop.
CTest WILL_FAIL wrapper script for segfault, abort,etc.
cmake_minimum_required(VERSION 3.15)
project(buggy LANGUAGES C)
enable_testing()
include(CheckIncludeFile)
check_include_file("signal.h" HAVE_SIGNAL)
if(HAVE_SIGNAL)
file(GENERATE OUTPUT abrt.c CONTENT "#include <signal.h>
int main(void){ raise(SIGABRT); return 0; }")
add_executable(abrt ${CMAKE_CURRENT_BINARY_DIR}/abrt.c)
add_test(NAME sigabrt COMMAND ${CMAKE_COMMAND} -E env $<TARGET_FILE:abrt>)
set_property(TEST sigabrt PROPERTY WILL_FAIL TRUE)
endif()
file(GENERATE OUTPUT segv.c CONTENT "int main(void){*((char*)0) = 0; return 0;}")
add_executable(segv ${CMAKE_CURRENT_BINARY_DIR}/segv.c)
add_test(NAME sigsegv COMMAND ${CMAKE_COMMAND} -E env $<TARGET_FILE:segv>)
set_property(TEST sigsegv PROPERTY WILL_FAIL TRUE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment