diff --git a/src/core/ddsc/tests/Array100.idl b/src/core/ddsc/tests/Array100.idl new file mode 100644 index 0000000000..23e67342b6 --- /dev/null +++ b/src/core/ddsc/tests/Array100.idl @@ -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 diff --git a/src/core/ddsc/tests/CMakeLists.txt b/src/core/ddsc/tests/CMakeLists.txt index 59aec41133..0aef635eff 100644 --- a/src/core/ddsc/tests/CMakeLists.txt +++ b/src/core/ddsc/tests/CMakeLists.txt @@ -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" @@ -155,7 +157,7 @@ if(iceoryx_binding_c_FOUND AND NOT WIN32) "$" "$>") - 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) @@ -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) diff --git a/src/core/ddsc/tests/iceoryx.c b/src/core/ddsc/tests/iceoryx.c index f7526a4564..b22fa03423 100644 --- a/src/core/ddsc/tests/iceoryx.c +++ b/src/core/ddsc/tests/iceoryx.c @@ -26,6 +26,7 @@ #include "dds__entity.h" #include "test_common.h" +#include "Array100.h" static const struct shm_locator { unsigned char a[16]; @@ -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); @@ -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; @@ -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++) @@ -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) @@ -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); +} +