From ceb8d6c050aade1cef9456958c241ec35440041c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dietrich=20Kr=C3=B6nke?= Date: Wed, 22 Sep 2021 16:03:35 +0200 Subject: [PATCH 1/2] iox-#932 Add CI jobs for latest gcc and clang MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Dietrich Krönke --- .github/workflows/build-test.yml | 30 +++++++++++++--- tools/ci/build-test-ubuntu-with-sanitizers.sh | 24 ++++++++++--- tools/ci/build-test-ubuntu.sh | 2 +- ... => build-ubuntu-with-latest-clang-gcc.sh} | 36 ++++++++++--------- 4 files changed, 67 insertions(+), 25 deletions(-) rename tools/ci/{build-test-ubuntu-with-latest-clang.sh => build-ubuntu-with-latest-clang-gcc.sh} (63%) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index b6f3da8b42..f89e6e2427 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -56,12 +56,23 @@ jobs: - uses: actions/checkout@v2 - run: ./tools/ci/run-integration-test.sh - build-test-ubuntu-with-sanitizers: + build-test-ubuntu-with-sanitizers-gcc: + runs-on: ubuntu-20.04 + needs: pre-flight-check + steps: + - uses: egor-tensin/setup-gcc@v1 + with: + version: latest + platform: x64 + - uses: actions/checkout@v2 + - run: ./tools/ci/build-test-ubuntu-with-sanitizers.sh gcc + + build-test-ubuntu-with-sanitizers-clang: runs-on: ubuntu-20.04 needs: pre-flight-check steps: - uses: actions/checkout@v2 - - run: ./tools/ci/build-test-ubuntu-with-sanitizers.sh + - run: ./tools/ci/build-test-ubuntu-with-sanitizers.sh clang build-test-macos-with-sanitizers: runs-on: macos-latest @@ -72,12 +83,23 @@ jobs: - uses: actions/checkout@v2 - run: ./tools/ci/build-test-macos-with-sanitizers.sh - build-test-ubuntu-with-latest-clang: + build-ubuntu-with-latest-clang-release: runs-on: ubuntu-latest needs: pre-flight-check steps: - uses: actions/checkout@v2 - - run: ./tools/ci/build-test-ubuntu-with-latest-clang.sh + - run: ./tools/ci/build-ubuntu-with-latest-clang-gcc.sh clang + + build-ubuntu-with-latest-gcc-release: + runs-on: ubuntu-latest + needs: pre-flight-check + steps: + - uses: egor-tensin/setup-gcc@v1 + with: + version: latest + platform: x64 + - uses: actions/checkout@v2 + - run: ./tools/ci/build-ubuntu-with-latest-clang-gcc.sh gcc # gcc 5.4 is compiler used in QNX 7.0 build-test-ubuntu-with-gcc54: diff --git a/tools/ci/build-test-ubuntu-with-sanitizers.sh b/tools/ci/build-test-ubuntu-with-sanitizers.sh index c10c59ca2e..d2a93f2734 100755 --- a/tools/ci/build-test-ubuntu-with-sanitizers.sh +++ b/tools/ci/build-test-ubuntu-with-sanitizers.sh @@ -19,6 +19,8 @@ set -e +COMPILER=${1:-gcc} + msg() { printf "\033[1;32m%s: %s\033[0m\n" ${FUNCNAME[1]} "$1" } @@ -29,15 +31,29 @@ cd ${WORKSPACE} msg "installing build dependencies" sudo apt-get update && sudo apt-get install -y libacl1-dev libncurses5-dev +if [ "$COMPILER" == "clang" ]; then + msg "installing latest stable clang" + wget https://apt.llvm.org/llvm.sh -O /tmp/llvm.sh + chmod +x /tmp/llvm.sh + # set LLVM_VERSION + eval $(cat /tmp/llvm.sh | grep LLVM_VERSION= -m 1) + sudo /tmp/llvm.sh ${LLVM_VERSION} +fi + msg "creating local test users and groups for testing access control" sudo ./tools/add_test_users.sh -msg "compiler versions: -$(gcc --version) -$(clang --version)" msg "building sources" -./tools/iceoryx_build_test.sh clean build-strict build-strict build-all clang sanitize test-add-user +if [ "$COMPILER" == "gcc" ]; then + ./tools/iceoryx_build_test.sh clean build-strict build-strict build-all debug sanitize test-add-user +fi + +if [ "$COMPILER" == "clang" ]; then + export CC=clang-${LLVM_VERSION} + export CXX=clang++-${LLVM_VERSION} + ./tools/iceoryx_build_test.sh clean build-strict build-strict build-all clang debug sanitize test-add-user +fi msg "running all tests" cd ./build diff --git a/tools/ci/build-test-ubuntu.sh b/tools/ci/build-test-ubuntu.sh index 0b61428bcd..e34fa6941a 100755 --- a/tools/ci/build-test-ubuntu.sh +++ b/tools/ci/build-test-ubuntu.sh @@ -48,4 +48,4 @@ cd ./build cd - msg "building roudi examples without toml support" -./tools/iceoryx_build_test.sh out-of-tree examples toml-config-off clean +./tools/iceoryx_build_test.sh relwithdebinfo out-of-tree examples toml-config-off clean diff --git a/tools/ci/build-test-ubuntu-with-latest-clang.sh b/tools/ci/build-ubuntu-with-latest-clang-gcc.sh similarity index 63% rename from tools/ci/build-test-ubuntu-with-latest-clang.sh rename to tools/ci/build-ubuntu-with-latest-clang-gcc.sh index 4106008a3b..73ebd5c1b1 100755 --- a/tools/ci/build-test-ubuntu-with-latest-clang.sh +++ b/tools/ci/build-ubuntu-with-latest-clang-gcc.sh @@ -19,6 +19,8 @@ set -e +COMPILER=${1:-gcc} + msg() { printf "\033[1;32m%s: %s\033[0m\n" ${FUNCNAME[1]} "$1" } @@ -29,25 +31,27 @@ cd ${WORKSPACE} msg "installing build dependencies" sudo apt-get update && sudo apt-get install -y libacl1-dev libncurses5-dev -msg "installing latest stable clang" -wget https://apt.llvm.org/llvm.sh -O /tmp/llvm.sh -chmod +x /tmp/llvm.sh -# set LLVM_VERSION -eval $(cat /tmp/llvm.sh | grep LLVM_VERSION= -m 1) -sudo /tmp/llvm.sh ${LLVM_VERSION} +if [ "$COMPILER" == "clang" ]; then + msg "installing latest stable clang" + wget https://apt.llvm.org/llvm.sh -O /tmp/llvm.sh + chmod +x /tmp/llvm.sh + # set LLVM_VERSION + eval $(cat /tmp/llvm.sh | grep LLVM_VERSION= -m 1) + sudo /tmp/llvm.sh ${LLVM_VERSION} +fi msg "creating local test users and groups for testing access control" sudo ./tools/add_test_users.sh -msg "compiler versions: -$(clang-${LLVM_VERSION} --version)" msg "building sources" -export CC=clang-${LLVM_VERSION} -export CXX=clang++-${LLVM_VERSION} -./tools/iceoryx_build_test.sh clean build-all out-of-tree build-shared test-add-user - -msg "running all tests" -cd ./build -./tools/run_tests.sh all -cd - + +if [ "$COMPILER" == "gcc" ]; then + ./tools/iceoryx_build_test.sh clean release build-all out-of-tree build-shared test-add-user +fi + +if [ "$COMPILER" == "clang" ]; then + export CC=clang-${LLVM_VERSION} + export CXX=clang++-${LLVM_VERSION} + ./tools/iceoryx_build_test.sh clean clang release build-all out-of-tree build-shared test-add-user +fi From c4cbffc35f330bbdb6d1378a78420d2cbdec7b8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dietrich=20Kr=C3=B6nke?= Date: Fri, 1 Oct 2021 09:32:33 +0200 Subject: [PATCH 2/2] iox-#932 Support nullptr callback function in waitset MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Dietrich Krönke --- CHANGELOG.md | 1 + iceoryx_binding_c/source/c_wait_set.cpp | 8 +- .../moduletests/test_notification_info.cpp | 13 +- .../test/moduletests/test_subscriber.cpp | 10 +- .../test/moduletests/test_user_trigger.cpp | 10 +- .../test/moduletests/test_wait_set.cpp | 118 +++++++++++++----- 6 files changed, 109 insertions(+), 51 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d9a4be783f..981ea2680c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ **Refactoring:** +- Handle nullptr callbacks in waitset and listener[\#932](https://github.com/eclipse-iceoryx/iceoryx/issues/932) - Add clang-tidy rules for iceoryx_hoofs[\#889](https://github.com/eclipse-iceoryx/iceoryx/issues/889) - Move all tests into an anonymous namespace[\#563](https://github.com/eclipse-iceoryx/iceoryx/issues/563) - Refactor smart_c to use contract by design and expected[\#418](https://github.com/eclipse-iceoryx/iceoryx/issues/418) diff --git a/iceoryx_binding_c/source/c_wait_set.cpp b/iceoryx_binding_c/source/c_wait_set.cpp index 71e6f56f11..eb89b7ba52 100644 --- a/iceoryx_binding_c/source/c_wait_set.cpp +++ b/iceoryx_binding_c/source/c_wait_set.cpp @@ -114,8 +114,7 @@ iox_WaitSetResult iox_ws_attach_subscriber_state(iox_ws_t const self, const uint64_t eventId, void (*callback)(iox_sub_t)) { - auto result = self->attachState( - *subscriber, c2cpp::subscriberState(subscriberState), eventId, createNotificationCallback(*callback)); + auto result = self->attachState(*subscriber, c2cpp::subscriberState(subscriberState), eventId, {callback, nullptr}); return (result.has_error()) ? cpp2c::waitSetResult(result.get_error()) : iox_WaitSetResult::WaitSetResult_SUCCESS; } @@ -141,8 +140,7 @@ iox_WaitSetResult iox_ws_attach_subscriber_event(iox_ws_t const self, const uint64_t eventId, void (*callback)(iox_sub_t)) { - auto result = self->attachEvent( - *subscriber, c2cpp::subscriberEvent(subscriberEvent), eventId, createNotificationCallback(*callback)); + auto result = self->attachEvent(*subscriber, c2cpp::subscriberEvent(subscriberEvent), eventId, {callback, nullptr}); return (result.has_error()) ? cpp2c::waitSetResult(result.get_error()) : iox_WaitSetResult::WaitSetResult_SUCCESS; } @@ -167,7 +165,7 @@ iox_WaitSetResult iox_ws_attach_user_trigger_event(iox_ws_t const self, const uint64_t eventId, void (*callback)(iox_user_trigger_t)) { - auto result = self->attachEvent(*userTrigger, eventId, createNotificationCallback(*callback)); + auto result = self->attachEvent(*userTrigger, eventId, {callback, nullptr}); return (result.has_error()) ? cpp2c::waitSetResult(result.get_error()) : iox_WaitSetResult::WaitSetResult_SUCCESS; } diff --git a/iceoryx_binding_c/test/moduletests/test_notification_info.cpp b/iceoryx_binding_c/test/moduletests/test_notification_info.cpp index 5a1404c9b1..3febe8af1a 100644 --- a/iceoryx_binding_c/test/moduletests/test_notification_info.cpp +++ b/iceoryx_binding_c/test/moduletests/test_notification_info.cpp @@ -91,6 +91,9 @@ class iox_notification_info_test : public Test return m_memoryManager.getChunk(chunkSettings); } + static void triggerCallback(iox_sub_t sub IOX_MAYBE_UNUSED) + { + } static UserTrigger* m_lastNotificationCallbackArgument; ConditionVariableData m_condVar{"myApp"}; @@ -142,7 +145,7 @@ TEST_F(iox_notification_info_test, notificationOriginIsUserTriggerPointerWhenIts TEST_F(iox_notification_info_test, notificationOriginIsSubscriberPointerWhenItsOriginatingFromThemStateBased) { - iox_ws_attach_subscriber_state(&m_waitSet, m_subscriberHandle, SubscriberState_HAS_DATA, 587U, NULL); + iox_ws_attach_subscriber_state(&m_waitSet, m_subscriberHandle, SubscriberState_HAS_DATA, 587U, triggerCallback); this->Subscribe(&m_portPtr); m_chunkPusher.push(getChunkFromMemoryManager()); @@ -154,7 +157,8 @@ TEST_F(iox_notification_info_test, notificationOriginIsSubscriberPointerWhenItsO TEST_F(iox_notification_info_test, notificationOriginIsSubscriberPointerWhenItsOriginatingFromThemEventBased) { - iox_ws_attach_subscriber_event(&m_waitSet, m_subscriberHandle, SubscriberEvent_DATA_RECEIVED, 587U, NULL); + iox_ws_attach_subscriber_event( + &m_waitSet, m_subscriberHandle, SubscriberEvent_DATA_RECEIVED, 587U, triggerCallback); this->Subscribe(&m_portPtr); m_chunkPusher.push(getChunkFromMemoryManager()); @@ -178,7 +182,7 @@ TEST_F(iox_notification_info_test, getOriginReturnsPointerToUserTriggerWhenOrigi TEST_F(iox_notification_info_test, getOriginReturnsPointerToSubscriberWhenOriginatingFromThemStateBased) { - iox_ws_attach_subscriber_state(&m_waitSet, m_subscriberHandle, SubscriberState_HAS_DATA, 587U, NULL); + iox_ws_attach_subscriber_state(&m_waitSet, m_subscriberHandle, SubscriberState_HAS_DATA, 587U, triggerCallback); this->Subscribe(&m_portPtr); m_chunkPusher.push(getChunkFromMemoryManager()); @@ -190,7 +194,8 @@ TEST_F(iox_notification_info_test, getOriginReturnsPointerToSubscriberWhenOrigin TEST_F(iox_notification_info_test, getOriginReturnsPointerToSubscriberWhenOriginatingFromThemEventBased) { - iox_ws_attach_subscriber_event(&m_waitSet, m_subscriberHandle, SubscriberEvent_DATA_RECEIVED, 587U, NULL); + iox_ws_attach_subscriber_event( + &m_waitSet, m_subscriberHandle, SubscriberEvent_DATA_RECEIVED, 587U, triggerCallback); this->Subscribe(&m_portPtr); m_chunkPusher.push(getChunkFromMemoryManager()); diff --git a/iceoryx_binding_c/test/moduletests/test_subscriber.cpp b/iceoryx_binding_c/test/moduletests/test_subscriber.cpp index 57d5e6ee61..ddfea654f6 100644 --- a/iceoryx_binding_c/test/moduletests/test_subscriber.cpp +++ b/iceoryx_binding_c/test/moduletests/test_subscriber.cpp @@ -327,7 +327,7 @@ TEST_F(iox_sub_test, sendingTooMuchLeadsToOverflow) TEST_F(iox_sub_test, attachingToWaitSetWorks) { - EXPECT_EQ(iox_ws_attach_subscriber_state(m_waitSet.get(), m_sut, SubscriberState_HAS_DATA, 0U, NULL), + EXPECT_EQ(iox_ws_attach_subscriber_state(m_waitSet.get(), m_sut, SubscriberState_HAS_DATA, 0U, triggerCallback), WaitSetResult_SUCCESS); EXPECT_EQ(m_waitSet->size(), 1U); } @@ -335,9 +335,9 @@ TEST_F(iox_sub_test, attachingToWaitSetWorks) TEST_F(iox_sub_test, attachingToAnotherWaitsetCleansupAtOriginalWaitset) { WaitSetMock m_waitSet2{m_condVar}; - iox_ws_attach_subscriber_state(m_waitSet.get(), m_sut, SubscriberState_HAS_DATA, 0U, NULL); + iox_ws_attach_subscriber_state(m_waitSet.get(), m_sut, SubscriberState_HAS_DATA, 0U, triggerCallback); - EXPECT_EQ(iox_ws_attach_subscriber_state(&m_waitSet2, m_sut, SubscriberState_HAS_DATA, 0U, NULL), + EXPECT_EQ(iox_ws_attach_subscriber_state(&m_waitSet2, m_sut, SubscriberState_HAS_DATA, 0U, triggerCallback), WaitSetResult_SUCCESS); EXPECT_EQ(m_waitSet->size(), 0U); EXPECT_EQ(m_waitSet2.size(), 1U); @@ -345,14 +345,14 @@ TEST_F(iox_sub_test, attachingToAnotherWaitsetCleansupAtOriginalWaitset) TEST_F(iox_sub_test, detachingFromWaitSetWorks) { - iox_ws_attach_subscriber_state(m_waitSet.get(), m_sut, SubscriberState_HAS_DATA, 0U, NULL); + iox_ws_attach_subscriber_state(m_waitSet.get(), m_sut, SubscriberState_HAS_DATA, 0U, triggerCallback); iox_ws_detach_subscriber_state(m_waitSet.get(), m_sut, SubscriberState_HAS_DATA); EXPECT_EQ(m_waitSet->size(), 0U); } TEST_F(iox_sub_test, hasDataTriggersWaitSetWithCorrectNotificationId) { - iox_ws_attach_subscriber_state(m_waitSet.get(), m_sut, SubscriberState_HAS_DATA, 587U, NULL); + iox_ws_attach_subscriber_state(m_waitSet.get(), m_sut, SubscriberState_HAS_DATA, 587U, triggerCallback); this->Subscribe(&m_portPtr); m_chunkPusher.push(getChunkFromMemoryManager()); diff --git a/iceoryx_binding_c/test/moduletests/test_user_trigger.cpp b/iceoryx_binding_c/test/moduletests/test_user_trigger.cpp index d16548b3a2..a80cb3227b 100644 --- a/iceoryx_binding_c/test/moduletests/test_user_trigger.cpp +++ b/iceoryx_binding_c/test/moduletests/test_user_trigger.cpp @@ -79,14 +79,14 @@ TEST_F(iox_user_trigger_test, cannotBeTriggeredWhenNotAttached) TEST_F(iox_user_trigger_test, canBeTriggeredWhenAttached) { - iox_ws_attach_user_trigger_event(&m_waitSet, m_sut, 0U, NULL); + iox_ws_attach_user_trigger_event(&m_waitSet, m_sut, 0U, triggerCallback); iox_user_trigger_trigger(m_sut); EXPECT_TRUE(iox_user_trigger_has_triggered(m_sut)); } TEST_F(iox_user_trigger_test, triggeringWaitSetResultsInCorrectNotificationId) { - iox_ws_attach_user_trigger_event(&m_waitSet, m_sut, 88191U, NULL); + iox_ws_attach_user_trigger_event(&m_waitSet, m_sut, 88191U, triggerCallback); iox_user_trigger_trigger(m_sut); auto eventVector = m_waitSet.wait(); @@ -111,9 +111,9 @@ TEST_F(iox_user_trigger_test, triggeringWaitSetResultsInCorrectCallback) TEST_F(iox_user_trigger_test, attachingToAnotherWaitSetCleansupFirstWaitset) { WaitSetMock m_waitSet2{m_condVar}; - iox_ws_attach_user_trigger_event(&m_waitSet, m_sut, 0U, NULL); + iox_ws_attach_user_trigger_event(&m_waitSet, m_sut, 0U, triggerCallback); - iox_ws_attach_user_trigger_event(&m_waitSet2, m_sut, 0U, NULL); + iox_ws_attach_user_trigger_event(&m_waitSet2, m_sut, 0U, triggerCallback); EXPECT_EQ(m_waitSet.size(), 0U); EXPECT_EQ(m_waitSet2.size(), 1U); @@ -122,7 +122,7 @@ TEST_F(iox_user_trigger_test, attachingToAnotherWaitSetCleansupFirstWaitset) TEST_F(iox_user_trigger_test, disable_trigger_eventingItFromWaitsetCleansup) { WaitSetMock m_waitSet2{m_condVar}; - iox_ws_attach_user_trigger_event(&m_waitSet, m_sut, 0U, NULL); + iox_ws_attach_user_trigger_event(&m_waitSet, m_sut, 0U, triggerCallback); iox_ws_detach_user_trigger_event(&m_waitSet, m_sut); diff --git a/iceoryx_binding_c/test/moduletests/test_wait_set.cpp b/iceoryx_binding_c/test/moduletests/test_wait_set.cpp index f5d74adaa0..cb1f82e562 100644 --- a/iceoryx_binding_c/test/moduletests/test_wait_set.cpp +++ b/iceoryx_binding_c/test/moduletests/test_wait_set.cpp @@ -142,12 +142,28 @@ TEST_F(iox_ws_test, SizeIsZeroWhenConstructed) TEST_F(iox_ws_test, SizeIsOneWhenOneUserTriggerIsAttached) { - EXPECT_EQ(iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[0U], 0U, NULL), + EXPECT_EQ(iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[0U], 0U, userTriggerCallback), iox_WaitSetResult::WaitSetResult_SUCCESS); EXPECT_EQ(iox_ws_size(m_sut), 1U); } TEST_F(iox_ws_test, SizeIsOneWhenOneSubscriberStateIsAttached) +{ + constexpr uint64_t customId = 123U; + EXPECT_EQ(iox_ws_attach_subscriber_state( + m_sut, &m_subscriberVector[0U], SubscriberState_HAS_DATA, customId, subscriberCallback), + iox_WaitSetResult::WaitSetResult_SUCCESS); + EXPECT_EQ(iox_ws_size(m_sut), 1U); +} + +TEST_F(iox_ws_test, SizeIsOneWhenOneUserTriggerWithNullptrCallBackIsAttached) +{ + EXPECT_EQ(iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[0U], 0U, NULL), + iox_WaitSetResult::WaitSetResult_SUCCESS); + EXPECT_EQ(iox_ws_size(m_sut), 1U); +} + +TEST_F(iox_ws_test, SizeIsOneWhenOneSubscriberStateWithNullptrCallBackIsAttached) { constexpr uint64_t customId = 123U; EXPECT_EQ(iox_ws_attach_subscriber_state(m_sut, &m_subscriberVector[0U], SubscriberState_HAS_DATA, customId, NULL), @@ -156,6 +172,15 @@ TEST_F(iox_ws_test, SizeIsOneWhenOneSubscriberStateIsAttached) } TEST_F(iox_ws_test, SizeIsOneWhenOneSubscriberEventIsAttached) +{ + constexpr uint64_t customId = 123U; + EXPECT_EQ(iox_ws_attach_subscriber_event( + m_sut, &m_subscriberVector[0U], SubscriberEvent_DATA_RECEIVED, customId, subscriberCallback), + iox_WaitSetResult::WaitSetResult_SUCCESS); + EXPECT_EQ(iox_ws_size(m_sut), 1U); +} + +TEST_F(iox_ws_test, SizeIsOneWhenOneSubscriberEventWithNullptrCallBackIsAttached) { constexpr uint64_t customId = 123U; EXPECT_EQ( @@ -168,11 +193,12 @@ TEST_F(iox_ws_test, AttachingMoreUserTriggerThanCapacityAvailableFails) { for (uint64_t i = 0U; i < MAX_NUMBER_OF_ATTACHMENTS_PER_WAITSET; ++i) { - EXPECT_EQ(iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[i], 0U, NULL), + EXPECT_EQ(iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[i], 0U, userTriggerCallback), iox_WaitSetResult::WaitSetResult_SUCCESS); EXPECT_EQ(iox_ws_size(m_sut), i + 1U); } - EXPECT_EQ(iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[MAX_NUMBER_OF_ATTACHMENTS_PER_WAITSET], 0U, NULL), + EXPECT_EQ(iox_ws_attach_user_trigger_event( + m_sut, m_userTrigger[MAX_NUMBER_OF_ATTACHMENTS_PER_WAITSET], 0U, userTriggerCallback), iox_WaitSetResult::WaitSetResult_WAIT_SET_FULL); } @@ -181,16 +207,16 @@ TEST_F(iox_ws_test, AttachingMoreSubscriberStatesThanCapacityAvailableFails) constexpr uint64_t customId = 123U; for (uint64_t i = 0U; i < MAX_NUMBER_OF_ATTACHMENTS_PER_WAITSET; ++i) { - EXPECT_EQ( - iox_ws_attach_subscriber_state(m_sut, &m_subscriberVector[i], SubscriberState_HAS_DATA, customId, NULL), - iox_WaitSetResult::WaitSetResult_SUCCESS); + EXPECT_EQ(iox_ws_attach_subscriber_state( + m_sut, &m_subscriberVector[i], SubscriberState_HAS_DATA, customId, subscriberCallback), + iox_WaitSetResult::WaitSetResult_SUCCESS); EXPECT_EQ(iox_ws_size(m_sut), i + 1U); } EXPECT_EQ(iox_ws_attach_subscriber_state(m_sut, &m_subscriberVector[MAX_NUMBER_OF_ATTACHMENTS_PER_WAITSET], SubscriberState_HAS_DATA, customId, - NULL), + subscriberCallback), iox_WaitSetResult::WaitSetResult_WAIT_SET_FULL); } @@ -200,7 +226,7 @@ TEST_F(iox_ws_test, AttachingMoreSubscriberEventsThanCapacityAvailableFails) for (uint64_t i = 0U; i < MAX_NUMBER_OF_ATTACHMENTS_PER_WAITSET; ++i) { EXPECT_EQ(iox_ws_attach_subscriber_event( - m_sut, &m_subscriberVector[i], SubscriberEvent_DATA_RECEIVED, customId, NULL), + m_sut, &m_subscriberVector[i], SubscriberEvent_DATA_RECEIVED, customId, subscriberCallback), iox_WaitSetResult::WaitSetResult_SUCCESS); EXPECT_EQ(iox_ws_size(m_sut), i + 1U); } @@ -208,13 +234,13 @@ TEST_F(iox_ws_test, AttachingMoreSubscriberEventsThanCapacityAvailableFails) &m_subscriberVector[MAX_NUMBER_OF_ATTACHMENTS_PER_WAITSET], SubscriberEvent_DATA_RECEIVED, customId, - NULL), + subscriberCallback), iox_WaitSetResult::WaitSetResult_WAIT_SET_FULL); } TEST_F(iox_ws_test, SizeDecreasesWhenAttachedUserTriggerIsDeinitialized) { - iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[0U], 0U, NULL); + iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[0U], 0U, userTriggerCallback); iox_ws_detach_user_trigger_event(m_sut, m_userTrigger[0U]); EXPECT_EQ(iox_ws_size(m_sut), 0U); } @@ -222,7 +248,8 @@ TEST_F(iox_ws_test, SizeDecreasesWhenAttachedUserTriggerIsDeinitialized) TEST_F(iox_ws_test, SizeDecreasesWhenAttachedSubscriberStateIsDeinitialized) { constexpr uint64_t customId = 123U; - EXPECT_EQ(iox_ws_attach_subscriber_state(m_sut, &m_subscriberVector[0U], SubscriberState_HAS_DATA, customId, NULL), + EXPECT_EQ(iox_ws_attach_subscriber_state( + m_sut, &m_subscriberVector[0U], SubscriberState_HAS_DATA, customId, subscriberCallback), iox_WaitSetResult::WaitSetResult_SUCCESS); iox_ws_detach_subscriber_state(m_sut, &m_subscriberVector[0U], SubscriberState_HAS_DATA); EXPECT_EQ(iox_ws_size(m_sut), 0U); @@ -231,16 +258,16 @@ TEST_F(iox_ws_test, SizeDecreasesWhenAttachedSubscriberStateIsDeinitialized) TEST_F(iox_ws_test, SizeDecreasesWhenAttachedSubscriberEventIsDeinitialized) { constexpr uint64_t customId = 123U; - EXPECT_EQ( - iox_ws_attach_subscriber_event(m_sut, &m_subscriberVector[0U], SubscriberEvent_DATA_RECEIVED, customId, NULL), - iox_WaitSetResult::WaitSetResult_SUCCESS); + EXPECT_EQ(iox_ws_attach_subscriber_event( + m_sut, &m_subscriberVector[0U], SubscriberEvent_DATA_RECEIVED, customId, subscriberCallback), + iox_WaitSetResult::WaitSetResult_SUCCESS); iox_ws_detach_subscriber_event(m_sut, &m_subscriberVector[0U], SubscriberEvent_DATA_RECEIVED); EXPECT_EQ(iox_ws_size(m_sut), 0U); } TEST_F(iox_ws_test, NumberOfTriggeredConditionsIsOneWhenOneWasTriggered) { - iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[0U], 0U, NULL); + iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[0U], 0U, userTriggerCallback); iox_user_trigger_trigger(m_userTrigger[0U]); EXPECT_EQ(iox_ws_wait(m_sut, m_eventInfoStorage, MAX_NUMBER_OF_ATTACHMENTS_PER_WAITSET, &m_missedElements), 1U); @@ -250,7 +277,7 @@ TEST_F(iox_ws_test, NumberOfTriggeredConditionsIsCorrectWhenMultipleWereTriggere { for (uint64_t i = 0U; i < 10U; ++i) { - iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[i], 0U, NULL); + iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[i], 0U, userTriggerCallback); iox_user_trigger_trigger(m_userTrigger[i]); } @@ -261,7 +288,7 @@ TEST_F(iox_ws_test, NumberOfTriggeredConditionsIsCorrectWhenAllWereTriggered) { for (uint64_t i = 0U; i < MAX_NUMBER_OF_ATTACHMENTS_PER_WAITSET; ++i) { - iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[i], 0U, NULL); + iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[i], 0U, userTriggerCallback); iox_user_trigger_trigger(m_userTrigger[i]); } @@ -271,7 +298,7 @@ TEST_F(iox_ws_test, NumberOfTriggeredConditionsIsCorrectWhenAllWereTriggered) TEST_F(iox_ws_test, SingleTriggerCaseWaitReturnsCorrectTrigger) { - iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[0], 5678U, NULL); + iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[0], 5678U, userTriggerCallback); iox_user_trigger_trigger(m_userTrigger[0U]); iox_ws_wait(m_sut, m_eventInfoStorage, MAX_NUMBER_OF_ATTACHMENTS_PER_WAITSET, &m_missedElements); @@ -286,7 +313,7 @@ TEST_F(iox_ws_test, MultiTriggerCaseWaitReturnsCorrectTrigger) { for (uint64_t i = 0U; i < 8; ++i) { - iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[i], 1337U + i, NULL); + iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[i], 1337U + i, userTriggerCallback); iox_user_trigger_trigger(m_userTrigger[i]); } @@ -304,7 +331,7 @@ TEST_F(iox_ws_test, MaxTriggerCaseWaitReturnsCorrectTrigger) { for (uint64_t i = 0U; i < MAX_NUMBER_OF_ATTACHMENTS_PER_WAITSET; ++i) { - iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[i], 42U * i + 1U, NULL); + iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[i], 42U * i + 1U, userTriggerCallback); iox_user_trigger_trigger(m_userTrigger[i]); } @@ -320,7 +347,7 @@ TEST_F(iox_ws_test, MaxTriggerCaseWaitReturnsCorrectTrigger) TEST_F(iox_ws_test, TimedWaitNumberOfTriggeredConditionsIsOneWhenOneWasTriggered) { - iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[0U], 0U, NULL); + iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[0U], 0U, userTriggerCallback); iox_user_trigger_trigger(m_userTrigger[0U]); EXPECT_EQ(iox_ws_timed_wait( @@ -332,7 +359,7 @@ TEST_F(iox_ws_test, TimedWaitNumberOfTriggeredConditionsIsCorrectWhenMultipleWer { for (uint64_t i = 0U; i < 10U; ++i) { - iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[i], 0U, NULL); + iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[i], 0U, userTriggerCallback); iox_user_trigger_trigger(m_userTrigger[i]); } @@ -345,7 +372,7 @@ TEST_F(iox_ws_test, TimedWaitNumberOfTriggeredConditionsIsCorrectWhenAllWereTrig { for (uint64_t i = 0U; i < MAX_NUMBER_OF_ATTACHMENTS_PER_WAITSET; ++i) { - iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[i], 0U, NULL); + iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[i], 0U, userTriggerCallback); iox_user_trigger_trigger(m_userTrigger[i]); } @@ -356,7 +383,7 @@ TEST_F(iox_ws_test, TimedWaitNumberOfTriggeredConditionsIsCorrectWhenAllWereTrig TEST_F(iox_ws_test, SingleTriggerCaseTimedWaitReturnsCorrectTrigger) { - iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[0U], 5678U, NULL); + iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[0U], 5678U, userTriggerCallback); iox_user_trigger_trigger(m_userTrigger[0U]); iox_ws_timed_wait(m_sut, m_timeout, m_eventInfoStorage, MAX_NUMBER_OF_ATTACHMENTS_PER_WAITSET, &m_missedElements); @@ -371,7 +398,7 @@ TEST_F(iox_ws_test, MultiTriggerCaseTimedWaitReturnsCorrectTrigger) { for (uint64_t i = 0U; i < 8U; ++i) { - iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[i], 1337U + i, NULL); + iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[i], 1337U + i, userTriggerCallback); iox_user_trigger_trigger(m_userTrigger[i]); } @@ -389,7 +416,7 @@ TEST_F(iox_ws_test, MaxTriggerCaseTimedWaitReturnsCorrectTrigger) { for (uint64_t i = 0U; i < MAX_NUMBER_OF_ATTACHMENTS_PER_WAITSET; ++i) { - iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[i], 42U * i + 1U, NULL); + iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[i], 42U * i + 1U, userTriggerCallback); iox_user_trigger_trigger(m_userTrigger[i]); } @@ -407,7 +434,7 @@ TEST_F(iox_ws_test, MissedElementsIsZeroWhenNothingWasMissed) { for (uint64_t i = 0U; i < 12U; ++i) { - iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[i], 0U, NULL); + iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[i], 0U, userTriggerCallback); iox_user_trigger_trigger(m_userTrigger[i]); } @@ -420,7 +447,7 @@ TEST_F(iox_ws_test, MissedElementsIsCorrectWhenSomethingWasMissed) { for (uint64_t i = 0U; i < 12U; ++i) { - iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[i], 0U, NULL); + iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[i], 0U, userTriggerCallback); iox_user_trigger_trigger(m_userTrigger[i]); } @@ -433,7 +460,7 @@ TEST_F(iox_ws_test, MissedElementsIsCorrectWhenAllWereMissed) { for (uint64_t i = 0U; i < MAX_NUMBER_OF_ATTACHMENTS_PER_WAITSET; ++i) { - iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[i], 0U, NULL); + iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[i], 0U, userTriggerCallback); iox_user_trigger_trigger(m_userTrigger[i]); } @@ -443,7 +470,7 @@ TEST_F(iox_ws_test, MissedElementsIsCorrectWhenAllWereMissed) } TIMING_TEST_F(iox_ws_test, WaitIsBlockingTillTriggered, Repeat(5), [&] { - iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[0U], 0U, NULL); + iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[0U], 0U, userTriggerCallback); std::atomic_bool waitWasCalled{false}; std::thread t([&] { @@ -480,7 +507,7 @@ TIMING_TEST_F(iox_ws_test, WaitIsNonBlockingAfterMarkForDestruction, Repeat(5), TIMING_TEST_F(iox_ws_test, TimedWaitIsBlockingTillTriggered, Repeat(5), [&] { - iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[0U], 0U, NULL); + iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[0U], 0U, userTriggerCallback); std::atomic_bool waitWasCalled{false}; std::thread t([&] { @@ -516,7 +543,7 @@ TIMING_TEST_F(iox_ws_test, TimedWaitIsNonBlockingAfterMarkForDestruction, Repeat }); TIMING_TEST_F(iox_ws_test, TimedWaitBlocksTillTimeout, Repeat(5), [&] { - iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[0U], 0U, NULL); + iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[0U], 0U, userTriggerCallback); std::atomic_bool waitWasCalled{false}; std::thread t([&] { @@ -547,6 +574,20 @@ TEST_F(iox_ws_test, SubscriberEventCallbackIsCalled) EXPECT_THAT(m_callbackOrigin, Eq(&m_subscriberVector[0])); } +TEST_F(iox_ws_test, NullptrSubscriberEventCallbackIsCalledWithoutError) +{ + iox_ws_attach_subscriber_event( + m_sut, &m_subscriberVector[0], iox_SubscriberEvent::SubscriberEvent_DATA_RECEIVED, 0, NULL); + + m_subscriberVector[0].m_trigger.trigger(); + ASSERT_THAT(iox_ws_wait(m_sut, m_eventInfoStorage, 1U, &m_missedElements), Eq(1U)); + EXPECT_EQ(m_missedElements, 0U); + + iox_notification_info_call(m_eventInfoStorage[0]); + + EXPECT_THAT(m_callbackOrigin, nullptr); +} + TEST_F(iox_ws_test, SubscriberEventCallbackWithContextDataIsCalled) { uint64_t someContextData = 0U; @@ -617,6 +658,19 @@ TEST_F(iox_ws_test, UserTriggerCallbackIsCalled) EXPECT_THAT(m_callbackOrigin, Eq(m_userTrigger[0])); } +TEST_F(iox_ws_test, NullptrUserTriggerCallbackIsCalledWithoutError) +{ + iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[0], 0, NULL); + iox_user_trigger_trigger(m_userTrigger[0]); + + ASSERT_THAT(iox_ws_wait(m_sut, m_eventInfoStorage, 1U, &m_missedElements), Eq(1U)); + EXPECT_EQ(m_missedElements, 0U); + + iox_notification_info_call(m_eventInfoStorage[0]); + + EXPECT_THAT(m_callbackOrigin, nullptr); +} + TEST_F(iox_ws_test, UserTriggerCallbackWithContextDataIsCalled) { uint64_t someContextData = 0U;