Skip to content

Commit

Permalink
add dummy psmx interface
Browse files Browse the repository at this point in the history
Signed-off-by: Michel van den Hoek <[email protected]>
  • Loading branch information
mvandenhoek committed Apr 3, 2024
1 parent 9b44f23 commit 0627d86
Show file tree
Hide file tree
Showing 5 changed files with 499 additions and 7 deletions.
25 changes: 25 additions & 0 deletions src/core/ddsc/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,30 @@ if(ENABLE_TOPIC_DISCOVERY)
"topic_find_global.c")
endif()

# PSMX dummy implementation for interface testing

set(
psmx_dummy_sources
"psmx_dummy_impl.c"
"psmx_dummy_impl.h"
)
add_library(psmx_dummy SHARED ${psmx_dummy_sources})
generate_export_header(psmx_dummy BASE_NAME PSMX_DUMMY EXPORT_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/include/dds/psmx_dummy/export.h")
target_include_directories(
psmx_dummy PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src/core/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../ddsi/include>"
)
target_link_libraries(psmx_dummy PRIVATE ddsc)
install(
TARGETS psmx_dummy
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)


add_cunit_executable(cunit_ddsc ${ddsc_test_sources})
target_include_directories(
cunit_ddsc PRIVATE
Expand All @@ -175,6 +199,7 @@ target_link_libraries(cunit_ddsc PRIVATE
CdrStreamSkipDefault
CdrStreamDataTypeInfo
PsmxDataModels
psmx_dummy
DynamicData
Array100
CdrStreamKeySize
Expand Down
51 changes: 44 additions & 7 deletions src/core/ddsc/tests/psmx.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "config_env.h"
#include "test_common.h"
#include "psmx_dummy_public.h"
#include "Array100.h"
#include "DynamicData.h"
#include "PsmxDataModels.h"
Expand Down Expand Up @@ -1331,6 +1332,9 @@ CU_Test (ddsc_psmx, basic)
/// - Create some entities
/// - Check if shared memory is enabled.
/// - Expectation: Shared memory is enabled iff the psmx interface supports it (use queried value).
/// - Delete the domain
/// - Check the function call counts of the dummy psmx.
/// - Expectation: The counts match expectations. In particular, create counts must match their delete counterpart.
///
/// - Create a configuration with a psmx interface capable of shared memory and don't specify a locator.
/// - Create a domain using this configuration.
Expand All @@ -1340,12 +1344,19 @@ CU_Test (ddsc_psmx, basic)
/// - Create some entities
/// - Check if shared memory is enabled.
/// - Expectation: Shared memory is enabled iff the psmx interface supports it (use queried value).
/// - Delete the domain
/// - Check the function call counts of the dummy psmx.
/// - Expectation: The counts match expectations. In particular, create counts must match their delete counterpart.
///
/// - The above two cases (with and without locator) are repeated for a
/// psmx interface that supports shared memory, and a psmx interface that doesn't.
///
CU_Test(ddsc_psmx, shared_memory)
CU_Test(ddsc_psmxif, shared_memory)
{
const char* CDDS_PSMX_NAME = NULL;
ddsrt_getenv("CDDS_PSMX_NAME", &CDDS_PSMX_NAME);
ddsrt_setenv("CDDS_PSMX_NAME", "dummy"); // Make `create_participant()` use the dummy psmx.
dummy_mockstats_t dmock, dmock_expected;
char strbuf1[512];
char strbuf2[512];
size_t strbuf_size = sizeof(strbuf1);
{
// Check that the data types I'm planning to use are actually suitable for use with shared memory.
dds_data_type_properties_t props;
Expand Down Expand Up @@ -1383,10 +1394,12 @@ CU_Test(ddsc_psmx, shared_memory)
dds_domain* dom = NULL;
CU_ASSERT_FATAL(domain_pin(domain, &dom));
CU_ASSERT_FATAL(dom->psmx_instances.length == 1); // There shall be exactly one psmx instance.
dds_psmx_t* psmx_ptr = dom->psmx_instances.instances[0];
struct dummy_psmx* dpsmx = (struct dummy_psmx*)dom->psmx_instances.instances[0];
dpsmx->mockstats_get_ownership(&dmock);

// The psmx must have an instance_name that is not an empty string.
CU_ASSERT_FATAL(psmx_ptr->instance_name != NULL && strcmp(psmx_ptr->instance_name, "") != 0);
supports_shared_memory = ((psmx_ptr->ops.supported_features(psmx_ptr) & DDS_PSMX_FEATURE_SHARED_MEMORY) == DDS_PSMX_FEATURE_SHARED_MEMORY);
CU_ASSERT_FATAL(dpsmx->c.instance_name != NULL && strcmp(dpsmx->c.instance_name, "") != 0);
supports_shared_memory = ((dpsmx->c.ops.supported_features(&dpsmx->c) & DDS_PSMX_FEATURE_SHARED_MEMORY) == DDS_PSMX_FEATURE_SHARED_MEMORY);
domain_unpin(dom);
}
dds_entity_t writer1, reader1, writer2, reader2;
Expand Down Expand Up @@ -1415,6 +1428,7 @@ CU_Test(ddsc_psmx, shared_memory)
CU_ASSERT_FATAL(reader2 > 0);
dds_delete_qos(qos);
}

{
// Check that shared memory is enabled when it should, and not enabled when it shouldn't.
bool psmx_enabled;
Expand All @@ -1435,6 +1449,29 @@ CU_Test(ddsc_psmx, shared_memory)
CU_ASSERT_FATAL(dds_is_shared_memory_available(reader2) == supports_shared_memory);
}
dds_delete(domain);

// Check number of calls against expected counts.
memset(&dmock_expected, 0, sizeof(dummy_mockstats_t));
dmock_expected.cnt_type_qos_supported = 10;
dmock_expected.cnt_create_topic = 2;
dmock_expected.cnt_delete_topic = 2;
dmock_expected.cnt_deinit = 1;
dmock_expected.cnt_get_node_id = 1;
dmock_expected.cnt_supported_features = 5;
dmock_expected.cnt_create_endpoint = 4;
dmock_expected.cnt_delete_endpoint = 4;
dmock_expected.cnt_on_data_available = 2; // This is perhaps unexpected, see below.
/*
NOTE: The `on_data_available` is triggered in
`dds_create_reader_int()`, even if no samples have been received at all.
*/
uint32_t cmp = dummy_mockstats_cmp(&dmock, &dmock_expected);
if( cmp != 0 ){
dummy_mockstats_tostring(&dmock, strbuf1, strbuf_size);
dummy_mockstats_tostring(&dmock_expected, strbuf2, strbuf_size);
printf("actual calls:\n%s\nexpected calls:\n%s\n", strbuf1, strbuf2);
CU_ASSERT_FATAL(cmp == 0);
}
}
}

Expand Down
Loading

0 comments on commit 0627d86

Please sign in to comment.