Skip to content

Commit

Permalink
Disable CDDS-based plugin
Browse files Browse the repository at this point in the history
Can't work as a shared library in an otherwise static build, but
linking it in statically causes nasty circular dependencies.  So disable
it altogether and rely on the Iceoryx plugin working fine.
  • Loading branch information
eboasson committed Oct 26, 2023
1 parent 2e99dc6 commit c658dde
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 18 deletions.
41 changes: 28 additions & 13 deletions src/core/ddsc/tests/CMakeLists.txt
Expand Up @@ -216,23 +216,38 @@ 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 OR NOT DEFINED BUILD_SHARED_LIBS)
idlc_generate(TARGET psmx_cdds_data FILES psmx_cdds_data.idl)
set(psmx_cdds_sources
"psmx_cdds_impl.c"
"psmx_cdds_impl.h")
add_library(psmx_cdds SHARED ${psmx_cdds_sources})
target_include_directories(
psmx_cdds PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../ddsi/include>")
target_link_libraries(psmx_cdds PRIVATE ddsc psmx_cdds_data)

idlc_generate(TARGET psmx_cdds_data FILES psmx_cdds_data.idl)
set(psmx_cdds_sources
"psmx_cdds_impl.c"
"psmx_cdds_impl.h")
add_library(psmx_cdds SHARED ${psmx_cdds_sources})
target_include_directories(
psmx_cdds PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../ddsi/include>")
target_link_libraries(psmx_cdds PRIVATE ddsc psmx_cdds_data)

generate_export_header(psmx_cdds BASE_NAME PSMX_CDDS EXPORT_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/include/dds/psmx_cdds/export.h")
generate_export_header(psmx_cdds BASE_NAME PSMX_CDDS EXPORT_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/include/dds/psmx_cdds/export.h")

install(TARGETS psmx_cdds
install(TARGETS psmx_cdds
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()

# If Iceoryx is available, then also run all PSMX tests using Iceoryx. Colcon complicates
# things too much and it doesn't affect Cyclone's CI run anyway.
Expand Down
33 changes: 32 additions & 1 deletion src/core/ddsc/tests/psmx.c
Expand Up @@ -63,6 +63,16 @@ static void fail_too_much_data (void) { fail (); }

static dds_entity_t create_participant (dds_domainid_t int_dom)
{
const char *psmx_plugin = "cdds";
(void) ddsrt_getenv ("CDDS_PSMX_NAME", &psmx_plugin);
#ifdef DDS_IS_STATIC_LIBRARY
// Circular dependencies (solvable, but with risk of brain-damage because of CMake)
// with fully static builds and multiple copies of Cyclone if the plugin is built as
// a shared library while the core is a static library make this too hard a case.
if (strcmp (psmx_plugin, "cdds") == 0)
return 0;
#endif

assert (int_dom < MAX_DOMAINS);
const unsigned char *l = psmx_locators[int_dom].a;
char *configstr;
Expand All @@ -71,7 +81,7 @@ static dds_entity_t create_participant (dds_domainid_t int_dom)
<General>\
<AllowMulticast>spdp</AllowMulticast>\
<Interfaces>\
<PubSubMessageExchange name=\"${CDDS_PSMX_NAME:-cdds}\" library=\"psmx_${CDDS_PSMX_NAME:-cdds}\" priority=\"1000000\" config=\"LOCATOR=%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x;SERVICE_NAME=psmx%d;KEYED_TOPICS=true;\" />\
<PubSubMessageExchange name=\"%s\" library=\"psmx_%s\" priority=\"1000000\" config=\"LOCATOR=%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x;SERVICE_NAME=psmx%d;KEYED_TOPICS=true;\" />\
</Interfaces>\
</General>\
<Discovery>\
Expand All @@ -83,6 +93,7 @@ static dds_entity_t create_participant (dds_domainid_t int_dom)
<OutputFile>cdds.log.%d</OutputFile>\
</Tracing>\
",
psmx_plugin, psmx_plugin,
l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8], l[9], l[10], l[11], l[12], l[13], l[14], l[15],
(int) l[0], // This prevents Iceoryx and Cyclone-based plugins from forwarding across the "network"
(int) int_dom // log file name
Expand Down Expand Up @@ -606,6 +617,10 @@ static void dotest (const dds_topic_descriptor_t *tpdesc, const void *sample, bo
for (int i = 0; i < MAX_DOMAINS; i++)
{
pp[i] = create_participant ((dds_domainid_t) i); // FIXME: vary shm_enable for i > 0
if (pp[i] == 0) {
CU_PASS ("skipped because of static build and cdds-based plugin");
return;
}
tp[i] = dds_create_topic (pp[i], tpdesc, topicname, NULL, NULL);
CU_ASSERT_FATAL (tp[i] > 0);
gvs[i] = get_domaingv (pp[i]);
Expand Down Expand Up @@ -1054,6 +1069,10 @@ CU_Test(ddsc_psmx, return_loan)
{
dds_return_t rc;
const dds_entity_t pp = create_participant (0);
if (pp == 0) {
CU_PASS ("skipped because of static build and cdds-based plugin");
return;
}
char topicname[100];
create_unique_topic_name ("test_psmx", topicname, sizeof (topicname));
const dds_entity_t tp = dds_create_topic (pp, &Array100_desc, topicname, NULL, NULL);
Expand All @@ -1079,6 +1098,10 @@ CU_Test(ddsc_psmx, partition_xtalk)
{
dds_return_t rc;
const dds_entity_t pp = create_participant (0);
if (pp == 0) {
CU_PASS ("skipped because of static build and cdds-based plugin");
return;
}
char topicname[100];
create_unique_topic_name ("test_psmx", topicname, sizeof (topicname));
const dds_entity_t tp = dds_create_topic (pp, &PsmxType1_desc, topicname, NULL, NULL);
Expand Down Expand Up @@ -1184,6 +1207,10 @@ CU_Test (ddsc_psmx, basic)
bool psmx_enabled;

participant = create_participant (0);
if (participant == 0) {
CU_PASS ("skipped because of static build and cdds-based plugin");
return;
}
CU_ASSERT_FATAL (participant > 0);

char topicname[100];
Expand Down Expand Up @@ -1243,6 +1270,10 @@ CU_Test (ddsc_psmx, zero_copy)
dds_return_t rc;

const dds_entity_t pp = create_participant (0);
if (pp == 0) {
CU_PASS ("skipped because of static build and cdds-based plugin");
return;
}
CU_ASSERT_FATAL (pp > 0);
for (size_t k = 0; k < sizeof (cases) / sizeof (cases[0]); k++)
{
Expand Down
5 changes: 5 additions & 0 deletions src/ddsrt/CMakeLists.txt
Expand Up @@ -319,6 +319,11 @@ if(BUILD_TESTING)
set(DDS_ALLOW_NESTED_DOMAIN 1)
endif()

if (BUILD_SHARED_LIBS OR NOT DEFINED BUILD_SHARED_LIBS)
else()
set(DDS_IS_STATIC_LIBRARY 1)
endif()

configure_file(include/dds/config.h.in include/dds/config.h)
configure_file(include/dds/features.h.in include/dds/features.h)
configure_file(include/dds/version.h.in include/dds/version.h)
Expand Down
3 changes: 3 additions & 0 deletions src/ddsrt/include/dds/features.h.in
Expand Up @@ -41,4 +41,7 @@
/* Not for general use, specificly for testing psmx Cyclone DDS plugin */
#cmakedefine DDS_ALLOW_NESTED_DOMAIN 1

/* Not intended for general use, whether building a static library, specifically testing psmx and security */
#cmakedefine DDS_IS_STATIC_LIBRARY 1

#endif
10 changes: 6 additions & 4 deletions src/security/core/tests/common/config_env.h.in
Expand Up @@ -12,18 +12,20 @@
#ifndef CONFIG_ENV_H
#define CONFIG_ENV_H

#include "dds/features.h"

#define FILE_PATH_SEP "/"
#define COMMON_ETC_DIR "@common_etc_dir@"
#define PLUGIN_WRAPPER_LIB_DIR "@plugin_wrapper_lib_dir@"
#define PLUGIN_WRAPPER_LIB_PREFIX "@CMAKE_SHARED_LIBRARY_PREFIX@"
#define PLUGIN_WRAPPER_LIB_SUFFIX "@CMAKE_SHARED_LIBRARY_SUFFIX@"

#if 0 // shared library:
// Statically linked plugins don't do path names
#ifdef DDS_IS_STATIC_LIBRARY
#define WRAPPERLIB_PATH(name) name
#else
#define WRAPPERLIB_PATH(name) \
PLUGIN_WRAPPER_LIB_DIR FILE_PATH_SEP PLUGIN_WRAPPER_LIB_PREFIX name PLUGIN_WRAPPER_LIB_SUFFIX
#else // static library mode:
#define WRAPPERLIB_PATH(name) \
name
#endif

#define COMMON_ETC_PATH(name) \
Expand Down

0 comments on commit c658dde

Please sign in to comment.