Tests now run using ctest

This commit is contained in:
2026-04-23 08:46:42 +02:00
parent 4434b20c48
commit d9c1f369b0
3 changed files with 58 additions and 46 deletions
+2 -1
View File
@@ -1,3 +1,4 @@
.vscode
build
.ioc*
.ioc*
Testing
+48 -45
View File
@@ -57,60 +57,63 @@ target_sources(m_epics_ca INTERFACE
)
target_include_directories(m_epics_ca INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/bus
$<BUILD_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
$<TARGET_FILE:m_epics_ca_test>
)
# 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..."
)
set_tests_properties(m_epics_ca_test PROPERTIES
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RUN_SERIAL TRUE
)
endif()
Executable
+8
View File
@@ -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"