Skip to content

Commit

Permalink
PSMX tests in static builds
Browse files Browse the repository at this point in the history
Signed-off-by: Erik Boasson <eb@ilities.com>
  • Loading branch information
eboasson committed Mar 6, 2024
1 parent 3175973 commit 560288e
Showing 1 changed file with 33 additions and 26 deletions.
59 changes: 33 additions & 26 deletions src/core/ddsc/tests/CMakeLists.txt
Expand Up @@ -101,9 +101,25 @@ set(ddsc_test_sources
"test_oneliner.h"
"cdrstream.c"
"serdata_keys.c"
"psmx.c"
)

# PSMX tests are tricky in a static build: we have a PSMX plugin that is based on Cyclone
# so we can test the interface even when Iceoryx is not available, but supporting that
# plugin is too complicated in a static build: it introduces a circular dependency and
# that's too hard for me in CMake.
#
# On most platforms (Linux, Windows, macOS) we could still load it dynamically but that
# fails to work because the shared library then includes its own copy of Cyclone DDS and
# then the access to the application readers that the plugin needs is no longer possible
# because they live in the other copy of the library.
#
# Fortunately, running them with Iceoryx doesn't suffer from this. If we simply skip
# these tests in a static build without Iceoryx and then we ensure the static build on CI
# uses Iceoryx, we should be good.
if(BUILD_SHARED_LIBS OR (ENABLE_ICEORYX AND NOT DEFINED ENV{COLCON}))
list(APPEND ddsc_test_sources "psmx.c")
endif()

if(ENABLE_LIFESPAN)
list(APPEND ddsc_test_sources "lifespan.c")
endif()
Expand Down Expand Up @@ -223,20 +239,6 @@ target_link_libraries(oneliner PRIVATE RoundTrip Space ddsc)


# PSMX implementation with Cyclone as transport, for testing
#
# This is one disabled in a static build. In a fully static build, the plugin should also
# be linked statically, but that introduces a circular dependency: this plugin requires
# the library in order to be built ... Of course it can be fixed with a multi-phase
# build, but this CMake, not good old make and so that's too hard.
#
# On most platforms (Linux, Windows, macOS) we can still dynamically load shared
# libraries, and so we can still build the plugin as a shared library. That however fails
# to work because the shared library then includes its own copy of Cyclone DDS, but this
# one needs to access the applications readers', which live in the other copy of the
# library.
#
# Fortunately, The Iceoryx doesn't suffer from this, so all it needs is some trickery to
# still get the Iceoryx tests to run.
if (BUILD_SHARED_LIBS)
idlc_generate(TARGET psmx_cdds_data FILES psmx_cdds_data.idl)
set(psmx_cdds_sources
Expand Down Expand Up @@ -301,18 +303,23 @@ kill -0 `cat ctest_fixture_iox_roudi.pid`")
set_tests_properties(stop_roudi PROPERTIES FIXTURES_CLEANUP iox)
set_tests_properties(start_roudi stop_roudi PROPERTIES RESOURCE_LOCK iox_lock)

# Construct Iceoryx-variants of all PSMX tests
# Construct Iceoryx-variants of all PSMX tests if building shared libraries, map them to
# Iceoryx in a static build (because I don't know how to delete tests!)
get_property(test_names DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY TESTS)
list(FILTER test_names INCLUDE REGEX "^CUnit_ddsc_psmx_[A-Za-z_0-9]+$")
foreach(fullname ${test_names})
string(REGEX REPLACE "^CUnit_ddsc_psmx_(.*)" "\\1" shortname "${fullname}")
add_test(NAME ${fullname}_iox COMMAND cunit_ddsc -s ddsc_psmx -t ${shortname})
set_tests_properties(${fullname}_iox PROPERTIES FIXTURES_REQUIRED iox)
set_tests_properties(${fullname}_iox PROPERTIES RESOURCE_LOCK iox_lock)
if(BUILD_SHARED_LIBS)
if(BUILD_SHARED_LIBS)
foreach(fullname ${test_names})
string(REGEX REPLACE "^CUnit_ddsc_psmx_(.*)" "\\1" shortname "${fullname}")
add_test(NAME ${fullname}_iox COMMAND cunit_ddsc -s ddsc_psmx -t ${shortname})
set_tests_properties(${fullname}_iox PROPERTIES FIXTURES_REQUIRED iox)
set_tests_properties(${fullname}_iox PROPERTIES RESOURCE_LOCK iox_lock)
set_tests_properties(${fullname}_iox PROPERTIES ENVIRONMENT "CDDS_PSMX_NAME=iox;LD_LIBRARY_PATH=$<TARGET_FILE_DIR:psmx_iox>:$ENV{LD_LIBRARY_PATH}")
else()
set_tests_properties(${fullname}_iox PROPERTIES ENVIRONMENT "CDDS_PSMX_NAME=iox")
endif()
endforeach()
endforeach()
else()
foreach(fullname ${test_names})
set_tests_properties(${fullname} PROPERTIES FIXTURES_REQUIRED iox)
set_tests_properties(${fullname} PROPERTIES RESOURCE_LOCK iox_lock)
set_tests_properties(${fullname} PROPERTIES ENVIRONMENT "CDDS_PSMX_NAME=iox")
endforeach()
endif()
endif()

0 comments on commit 560288e

Please sign in to comment.