diff --git a/.gitignore b/.gitignore index a97cb7a..b5ba30d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .vscode build -.ioc* \ No newline at end of file +.ioc* +Testing \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index e9c1d29..b8c64e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,60 +57,63 @@ target_sources(m_epics_ca INTERFACE ) target_include_directories(m_epics_ca INTERFACE - ${CMAKE_CURRENT_SOURCE_DIR}/bus + $ ) ################################################################################ ## Test executable ################################################################################ -add_executable( - m_epics_ca_test - test/m_epics_ca_test.cxx -) +option(BUILD_TESTS "Build tests" ON) -set_property( - TARGET +if(BUILD_TESTS) + + enable_testing() + + add_executable( m_epics_ca_test - PROPERTY - CXX_STANDARD 17 -) + test/m_epics_ca_test.cxx + ) -target_include_directories( - m_epics_ca_test - PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE + set_property( + TARGET + m_epics_ca_test + PROPERTY + CXX_STANDARD 17 + ) + + target_include_directories( + m_epics_ca_test + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE + m_epics_ca + $ENV{MIDASSYS}/drivers + $ENV{MIDASSYS}/include + # This is redundant if MIDASSYS =/ Midas repo, but needed if MIDAS has been + # installed in the repo directory, since the CMake file of MIDAS doesn't + # copy the headers into $ENV{MIDASSYS}/include in the latter case. + $ENV{MIDASSYS}/include/mscb + ${EPICSSYS}/include + ${EPICSSYS}/include/os/Linux + ${EPICSSYS}/include/os/Darwin + ${EPICSSYS}/include/compiler/gcc + ${EPICSSYS}/include/compiler/clang + ) + + target_link_libraries( + m_epics_ca_test m_epics_ca - $ENV{MIDASSYS}/drivers - $ENV{MIDASSYS}/include - # This is redundant if MIDASSYS =/ Midas repo, but needed if MIDAS has been - # installed in the repo directory, since the CMake file of MIDAS doesn't - # copy the headers into $ENV{MIDASSYS}/include in the latter case. - $ENV{MIDASSYS}/include/mscb - ${EPICSSYS}/include - ${EPICSSYS}/include/os/Linux - ${EPICSSYS}/include/os/Darwin - ${EPICSSYS}/include/compiler/gcc - ${EPICSSYS}/include/compiler/clang -) + ${LIBS} + ) -target_link_libraries( - m_epics_ca_test - m_epics_ca - ${LIBS} -) + add_test(NAME m_epics_ca_test + COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/run_test.sh + $ + ) -# Custom target to run the test immediately after building -add_custom_command(TARGET m_epics_ca_test - POST_BUILD - COMMAND m_epics_ca_test - COMMENT "Running m_epics_ca_test after build..." -) - -add_custom_target(run_m_epics_ca_test - COMMAND m_epics_ca_test - DEPENDS m_epics_ca_test - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - COMMENT "Running m_epics_ca_test..." -) \ No newline at end of file + set_tests_properties(m_epics_ca_test PROPERTIES + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + RUN_SERIAL TRUE + ) +endif() \ No newline at end of file diff --git a/run_test.sh b/run_test.sh new file mode 100755 index 0000000..2ba3527 --- /dev/null +++ b/run_test.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# This wrapper script is necessary to actually run the test with ctest because +# EPICS apparently calls grep and then terminates it with SIGTERM. When running +# the binary directly as a ctest target, the entire process group gets killed, +# meaning that the test gets terminated prematurly. With setsid, the test runs +# in its own process group, which means that SIGTERM does not propagate to ctest. +exec setsid -w "$1" \ No newline at end of file