Skip to content

Commit

Permalink
Minimal Test for dds_return_loan
Browse files Browse the repository at this point in the history
Signed-off-by: Erik Boasson <[email protected]>
  • Loading branch information
eboasson committed Jul 22, 2021
1 parent 9665842 commit f879dc0
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 6 deletions.
15 changes: 15 additions & 0 deletions src/core/ddsc/tests/Array100.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright(c) 2021 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
struct Array100 {
octet data[100];
};
#pragma keylist Array100
6 changes: 5 additions & 1 deletion src/core/ddsc/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ target_link_libraries(oneliner PRIVATE RoundTrip Space ddsc)
# better not be part of the tests. That also saves us from
# having to figure out now how to start/stop RouDi on Windows.
if(iceoryx_binding_c_FOUND AND NOT WIN32)
idlc_generate(TARGET Array100 FILES Array100.idl)

add_cunit_executable(cunit_ddsc_iox
"iceoryx.c"
"test_util.c"
Expand All @@ -155,7 +157,7 @@ if(iceoryx_binding_c_FOUND AND NOT WIN32)
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../ddsi/include>"
"$<BUILD_INTERFACE:$<TARGET_PROPERTY:iceoryx_binding_c::iceoryx_binding_c,INTERFACE_INCLUDE_DIRECTORIES>>")

target_link_libraries(cunit_ddsc_iox PRIVATE RoundTrip Space ddsc)
target_link_libraries(cunit_ddsc_iox PRIVATE RoundTrip Space Array100 ddsc)

# We need to start RouDi, so we need to find it
find_program(ICEORYX_ROUDI iox-roudi REQUIRED)
Expand Down Expand Up @@ -195,10 +197,12 @@ kill -0 `cat ctest_fixture_iox_roudi.pid`")
add_test(NAME stop_roudi COMMAND bash -c "kill `cat ctest_fixture_iox_roudi.pid` ; cat ctest_fixture_iox_roudi.output")

set_tests_properties(CUnit_ddsc_iceoryx_one_writer PROPERTIES FIXTURES_REQUIRED iox)
set_tests_properties(CUnit_ddsc_iceoryx_return_loan PROPERTIES FIXTURES_REQUIRED iox)
set_tests_properties(start_roudi PROPERTIES FIXTURES_SETUP iox)
set_tests_properties(stop_roudi PROPERTIES FIXTURES_CLEANUP iox)
set_tests_properties(
CUnit_ddsc_iceoryx_one_writer
CUnit_ddsc_iceoryx_return_loan
start_roudi
stop_roudi
PROPERTIES RESOURCE_LOCK iox_lock)
Expand Down
45 changes: 40 additions & 5 deletions src/core/ddsc/tests/iceoryx.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "dds__entity.h"

#include "test_common.h"
#include "Array100.h"

static const struct shm_locator {
unsigned char a[16];
Expand Down Expand Up @@ -288,7 +289,7 @@ static bool allmatched (dds_entity_t ws, dds_entity_t wr, int nrds, const dds_en
while (dds_time () < abstimeout)
{
(void) dds_waitset_wait_until (ws, NULL, 0, abstimeout);

dds_instance_handle_t ms[MAX_DOMAINS * MAX_READERS_PER_DOMAIN];
int32_t nms = dds_get_matched_subscriptions (wr, ms, sizeof (ms) / sizeof (ms[0]));
CU_ASSERT_FATAL (nms >= 0);
Expand All @@ -307,13 +308,13 @@ static bool allmatched (dds_entity_t ws, dds_entity_t wr, int nrds, const dds_en
qsort (mguids, (size_t) nms, sizeof (mguids[0]), compare_guid);
if (memcmp (mguids, rdguids, (size_t) nms * sizeof (*mguids)) != 0)
continue;

int mc = 0;
for (int i = 0; i < nrds; i++)
mc += get_current_match_count (rds[i]);
if (mc != nrds)
continue;

return true;
}
return false;
Expand Down Expand Up @@ -384,7 +385,7 @@ static bool alldataseen (struct tracebuf *tb, int nrds, const dds_entity_t rds[n
if (dataseen[i] == 0)
alldataseen = false;
} while (!alldataseen && dds_time () < abstimeout);

if (!alldataseen)
{
for (int i = 0; i < nrds; i++)
Expand Down Expand Up @@ -478,7 +479,7 @@ static void dotest (void)
if (i > 0 && dom > (i - 1) / MAX_READERS_PER_DOMAIN)
print (&tb, " |");
print (&tb, " %s", (rdmode[i] == 2) ? "iox" : "dds");

rds[i] = create_reader (tp[dom], rdmode[i] == 2);
const uint32_t port = reader_unicast_port (rds[i]);
if (dom == 0)
Expand Down Expand Up @@ -601,3 +602,37 @@ CU_Test(ddsc_iceoryx, one_writer, .timeout = 30)
dotest ();
CU_ASSERT (!failed);
}

CU_Test(ddsc_iceoryx, return_loan)
{
dds_return_t rc;
const dds_entity_t pp = create_participant (0, true);
char topicname[100];
create_unique_topic_name ("test_iceoryx", topicname, sizeof (topicname));
const dds_entity_t tp = dds_create_topic (pp, &Array100_desc, topicname, NULL, NULL);
CU_ASSERT_FATAL (tp > 0);
const dds_entity_t wr = create_writer (tp, true);

// RouDI config says 10000 * 256 bytes
// there's some overhead involved, 100 bytes should be ok
// try 1 .. 3 outstanding loans, and try it so often that there is virtually
// no chance of it working unless dds_return_loan really does return all loans
for (int n = 1; n <= 3; n++)
{
for (int i = 0; i < 20000; i += n)
{
void *sample[3];
for (int j = 0; j < n; j++)
{
rc = dds_loan_sample (wr, &sample[j]);
CU_ASSERT_FATAL (rc == 0);
}
rc = dds_return_loan (wr, sample, n);
CU_ASSERT_FATAL (rc == 0);
}
}

rc = dds_delete (DDS_CYCLONEDDS_HANDLE);
CU_ASSERT_FATAL (rc == 0);
}

0 comments on commit f879dc0

Please sign in to comment.