Skip to content

Commit

Permalink
Development/messagedispatcher (#1715)
Browse files Browse the repository at this point in the history
* [Tests/unit/core] : WIP to fix test_message_dispatcher.

* Adding new tests to each corner case of cyclic buffer overflow

* [Tests/unit/core] : cherry pick '081a0a1a5f6a2f0699d32b943764893198afd6a9' from 'development/cyclic-buffer-overlow-fix'.

* [Tests/unit/core] : Fix build 'test_message-dispatcher'.

* [Tests/unit/core] : Re-enable 'test_workerpool' and 'test_threadpool'

* [Tests/unit] : Do not depend on 'IPTestAdministrator' if not used

* [Tests/unit/tests] : Cherry pick 'test_iptestmanager' from development/namespaces

* [Tests/unit / Tests/unit/tests] : Improve synchronization usage of 'IPTestAdministrator'

* [core/IPCChannel] : cherry-pick from 'development/ipcchannel_dangling_handlers'

* Tests/unit/core] : align tests with '957977381dfa8137f1475131622390ebed2bdcf7'

* [Tests/unit] : Improve synchronization with premature signalling

* [Tests/unit] : Add test cases to 'Tests/unit/tests/test_iptestmanager.cpp'

* [Tests/unit/core] : align tests with '346fb6ec2a0da5058f7a581190e63c7cb61d929c'

Including various improvements for some test.

* [Tests/unit/core] : amend '7c9a286d1398de9f2b470b02bb58596120f0d8c9'

* [Tests/core/unit] : cherry pick from 'development/messageunit'

* [Tests/unit/core] : Use 'IPTestAdministrator' for 'PopMessageShouldReturnLastPushedMessageInOtherProcess' in test_message_unit'

* [Tests/unit/IPTestAdministrator] : Try to prevent to leak shared memory descriptors

---------

Co-authored-by: VeithMetro <[email protected]>
Co-authored-by: Pierre Wielders <[email protected]>
Co-authored-by: MFransen69 <[email protected]>
  • Loading branch information
4 people authored Aug 15, 2024
1 parent c238828 commit 282e7ad
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Tests/unit/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ add_executable(${TEST_RUNNER_NAME}
test_lockablecontainer.cpp
test_measurementtype.cpp
test_memberavailability.cpp
test_message_dispatcher.cpp
test_messageException.cpp
test_networkinfo.cpp
test_nodeid.cpp
Expand Down Expand Up @@ -106,7 +107,6 @@ add_executable(${TEST_RUNNER_NAME}
test_lockablecontainer.cpp
test_measurementtype.cpp
test_memberavailability.cpp
# test_message_dispatcher.cpp
test_messageException.cpp
test_networkinfo.cpp
test_nodeid.cpp
Expand Down
29 changes: 20 additions & 9 deletions Tests/unit/core/test_message_dispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,30 +189,41 @@ namespace Core {

TEST_F(Core_MessageDispatcher, WriteAndReadDataAreEqualInDifferentProcesses)
{
auto lambdaFunc = [this](IPTestAdministrator& testAdmin) {
constexpr uint32_t initHandshakeValue = 0, maxWaitTime = 4, maxWaitTimeMs = 4000, maxInitTime = 2000;
constexpr uint8_t maxRetries = 1;

IPTestAdministrator::Callback callback_child = [&](IPTestAdministrator& testAdmin) {
::Thunder::Messaging::MessageDataBuffer dispatcher(this->_identifier, this->_instanceId, this->_basePath, DATA_SIZE, 0, false);

uint8_t readData[4];
uint16_t readLength = sizeof(readData);

// Arbitrary timeout value, 1 second
ASSERT_EQ(dispatcher.Wait(1000), ::Thunder::Core::ERROR_NONE);
ASSERT_EQ(dispatcher.Wait(maxWaitTimeMs), ::Thunder::Core::ERROR_NONE);
ASSERT_EQ(dispatcher.PopData(readLength, readData), ::Thunder::Core::ERROR_NONE);

ASSERT_EQ(readLength, 2);
ASSERT_EQ(readData[0], 13);
ASSERT_EQ(readData[1], 37);
};

static std::function<void(IPTestAdministrator&)> lambdaVar = lambdaFunc;
IPTestAdministrator::OtherSideMain otherSide = [](IPTestAdministrator& testAdmin) { lambdaVar(testAdmin); };
ASSERT_EQ(testAdmin.Signal(initHandshakeValue, maxRetries), ::Thunder::Core::ERROR_NONE);
};

// This side (tested) acts as writer
IPTestAdministrator testAdmin(otherSide);
{
IPTestAdministrator::Callback callback_parent = [&](IPTestAdministrator& testAdmin) {
// a small delay so the child can be set up
SleepMs(maxInitTime);

uint8_t testData[2] = { 13, 37 };
ASSERT_EQ(_dispatcher->PushData(sizeof(testData), testData), ::Thunder::Core::ERROR_NONE);
}

ASSERT_EQ(testAdmin.Wait(initHandshakeValue), ::Thunder::Core::ERROR_NONE);
};

IPTestAdministrator testAdmin(callback_parent, callback_child, initHandshakeValue, maxWaitTime);

// Code after this line is executed by both parent and child

::Thunder::Core::Singleton::Dispose();
}

TEST_F(Core_MessageDispatcher, PushDataShouldNotFitWhenExcedingDataBufferSize)
Expand Down

0 comments on commit 282e7ad

Please sign in to comment.