From 94149a0ffd2d4f106de7e106689f43b331096f7e Mon Sep 17 00:00:00 2001 From: msieben <4319079+msieben@users.noreply.github.com> Date: Thu, 16 May 2024 11:17:20 +0000 Subject: [PATCH 1/5] [Tests/unit/core] : WIP to fix test_message_dispatcher. --- Tests/unit/core/CMakeLists.txt | 2 +- Tests/unit/core/test_message_dispatcher.cpp | 53 +++++++++++---------- 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/Tests/unit/core/CMakeLists.txt b/Tests/unit/core/CMakeLists.txt index 79d28d528..4b2fb75ad 100644 --- a/Tests/unit/core/CMakeLists.txt +++ b/Tests/unit/core/CMakeLists.txt @@ -79,7 +79,7 @@ add_executable(${TEST_RUNNER_NAME} test_websockettext.cpp test_workerpool.cpp test_xgetopt.cpp - #test_message_dispatcher.cpp + test_message_dispatcher.cpp ) #[[ if(MESSAGING) diff --git a/Tests/unit/core/test_message_dispatcher.cpp b/Tests/unit/core/test_message_dispatcher.cpp index 50eb40dd1..e296732cd 100644 --- a/Tests/unit/core/test_message_dispatcher.cpp +++ b/Tests/unit/core/test_message_dispatcher.cpp @@ -25,6 +25,8 @@ #include #include +#include + namespace WPEFramework { namespace Tests { @@ -57,7 +59,7 @@ namespace Tests { void SetUp() override { - _dispatcher.reset(new Core::MessageDispatcherType(_identifier, _instanceId, true, _basePath)); + _dispatcher.reset(new Messaging::MessageDataBuffer(_identifier, _instanceId, _basePath, DATA_SIZE, 0, true)); } void TearDown() override { @@ -68,7 +70,7 @@ namespace Tests { Core::Singleton::Dispose(); } - std::unique_ptr> _dispatcher; + std::unique_ptr _dispatcher; string _identifier; string _basePath; @@ -114,16 +116,16 @@ namespace Tests { TEST_F(Core_MessageDispatcher, CreateAndOpenOperatesOnSameValidFile) { - Core::MessageDispatcherType writerDispatcher(_T("test_md"), 0, true, this->_basePath); - Core::MessageDispatcherType readerDispatcher(_T("test_md"), 0, false, this->_basePath); + Messaging::MessageDataBuffer writerDispatcher(_T("test_md"), 0, this->_basePath, DATA_SIZE, 0, true); + Messaging::MessageDataBuffer readerDispatcher(_T("test_md"), 0, this->_basePath, DATA_SIZE, 0, false); uint8_t testData[2] = { 13, 37 }; uint8_t readData[4]; uint16_t readLength = sizeof(readData); - ASSERT_EQ(_dispatcher->PushData(sizeof(testData), testData), Core::ERROR_NONE); - ASSERT_EQ(_dispatcher->PopData(readLength, readData), Core::ERROR_NONE); + ASSERT_EQ(writerDispatcher.PushData(sizeof(testData), testData), Core::ERROR_NONE); + ASSERT_EQ(readerDispatcher.PopData(readLength, readData), Core::ERROR_NONE); ASSERT_EQ(readLength, sizeof(testData)); ASSERT_EQ(readData[0], 13); @@ -132,24 +134,24 @@ namespace Tests { TEST_F(Core_MessageDispatcher, MessageDispatcherCanBeOpenedAndClosed) { - Core::MessageDispatcherType writerDispatcher(_T("test_md"), 0, true, this->_basePath); + Messaging::MessageDataBuffer writerDispatcher(_T("test_md"), 0, this->_basePath, DATA_SIZE, 0, true); { - Core::MessageDispatcherType readerDispatcher(_T("test_md"), 0, false, this->_basePath); + Messaging::MessageDataBuffer readerDispatcher(_T("test_md"), 0, this->_basePath, DATA_SIZE, 0, false); //destructor is called } //reopen - Core::MessageDispatcherType readerDispatcher(_T("test_md"), 0, true, this->_basePath); + Messaging::MessageDataBuffer readerDispatcher(_T("test_md"), 0, this->_basePath, DATA_SIZE, 0, false); uint8_t testData[2] = { 13, 37 }; uint8_t readData[4]; uint16_t readLength = sizeof(readData); - ASSERT_EQ(_dispatcher->PushData(sizeof(testData), testData), Core::ERROR_NONE); - ASSERT_EQ(_dispatcher->PopData(readLength, readData), Core::ERROR_NONE); + ASSERT_EQ(writerDispatcher.PushData(sizeof(testData), testData), Core::ERROR_NONE); + ASSERT_EQ(readerDispatcher.PopData(readLength, readData), Core::ERROR_NONE); ASSERT_EQ(readLength, sizeof(testData)); ASSERT_EQ(readData[0], 13); @@ -183,7 +185,7 @@ namespace Tests { TEST_F(Core_MessageDispatcher, WriteAndReadDataAreEqualInDiffrentProcesses) { auto lambdaFunc = [this](IPTestAdministrator& testAdmin) { - Core::MessageDispatcherType dispatcher(this->_identifier, this->_instanceId, false, this->_basePath); + Messaging::MessageDataBuffer dispatcher(this->_identifier, this->_instanceId, this->_basePath, DATA_SIZE, 0, false); uint8_t readData[4]; uint16_t readLength = sizeof(readData); @@ -228,33 +230,34 @@ namespace Tests { TEST_F(Core_MessageDispatcher, PushDataShouldFlushOldDataIfDoesNotFit) { - uint8_t fullBufferSimulation[DATA_SIZE - 1 + sizeof(Core::CyclicBuffer::control) //almost full buffer - - sizeof(uint8_t) //size of type (part of message header) - - sizeof(uint16_t)]; //size of length (part of message header) + // CyclicBuffer Reserve requires 'length' < Size() + uint8_t fullBufferSimulation[DATA_SIZE - sizeof(uint16_t) - 1]; // sizeof(length) + length - 1, eg, < Size() uint8_t testData[] = { 12, 21 }; uint8_t readData[4]; uint16_t readLength = sizeof(readData); - ASSERT_EQ(_dispatcher->PushData(sizeof(fullBufferSimulation), fullBufferSimulation), Core::ERROR_NONE); - //buffer is full, but trying to write new data + EXPECT_EQ(_dispatcher->PushData(sizeof(fullBufferSimulation), fullBufferSimulation), Core::ERROR_NONE); - ASSERT_EQ(_dispatcher->PushData(sizeof(testData), testData), Core::ERROR_NONE); + // One element free space remaining + + // 2+2 bytes, 1 at tail position, 3 starting at position 0 + EXPECT_EQ(_dispatcher->PushData(sizeof(testData), testData), Core::ERROR_NONE); //new data written, so the oldest data should be replaced //this is first entry and should be first popped (FIFO) - ASSERT_EQ(_dispatcher->PopData(readLength, readData), Core::ERROR_NONE); - ASSERT_EQ(readLength, sizeof(testData)); - ASSERT_EQ(readData[0], 12); - ASSERT_EQ(readData[1], 21); + EXPECT_EQ(_dispatcher->PopData(readLength, readData), Core::ERROR_NONE); + EXPECT_EQ(readLength, sizeof(testData)); + EXPECT_EQ(readData[0], 12); + EXPECT_EQ(readData[1], 21); } //doorbell (socket) is not quite working inside test suite TEST_F(Core_MessageDispatcher, DISABLED_ReaderShouldWaitUntillRingBells) { auto lambdaFunc = [this](IPTestAdministrator& testAdmin) { - Core::MessageDispatcherType dispatcher(this->_identifier, this->_instanceId, false, this->_basePath); + Messaging::MessageDataBuffer dispatcher(this->_identifier, this->_instanceId, this->_basePath, 0, false); uint8_t readData[4]; uint16_t readLength = sizeof(readData); @@ -289,7 +292,7 @@ namespace Tests { } testAdmin.Sync("done"); } - +#ifdef _0 TEST_F(Core_MessageDispatcher, WriteAndReadMetaDataAreEqualInSameProcess) { uint8_t testData[2] = { 13, 37 }; @@ -394,6 +397,6 @@ namespace Tests { auto result = _dispatcher->PushMetadata(sizeof(testData), testData, sizeof(testData)); ASSERT_EQ(result, 0); } - +#endif } // Tests } // WPEFramework From ff3c391037f275f60e7a79acdb8593ba99edb62a Mon Sep 17 00:00:00 2001 From: VeithMetro Date: Mon, 20 May 2024 15:34:48 +0200 Subject: [PATCH 2/5] Adding new tests to each corner case of cyclic buffer overflow --- Tests/unit/core/test_message_dispatcher.cpp | 85 ++++++++++++++++++--- 1 file changed, 75 insertions(+), 10 deletions(-) diff --git a/Tests/unit/core/test_message_dispatcher.cpp b/Tests/unit/core/test_message_dispatcher.cpp index e296732cd..f714e9019 100644 --- a/Tests/unit/core/test_message_dispatcher.cpp +++ b/Tests/unit/core/test_message_dispatcher.cpp @@ -228,29 +228,94 @@ namespace Tests { ASSERT_EQ(_dispatcher->PushData(sizeof(fullBufferSimulation), fullBufferSimulation), Core::ERROR_WRITE_ERROR); } - TEST_F(Core_MessageDispatcher, PushDataShouldFlushOldDataIfDoesNotFit) + TEST_F(Core_MessageDispatcher, OffsetCutPushDataShouldFlushOldDataIfDoesNotFitOffsetCut) { // CyclicBuffer Reserve requires 'length' < Size() - uint8_t fullBufferSimulation[DATA_SIZE - sizeof(uint16_t) - 1]; // sizeof(length) + length - 1, eg, < Size() + uint8_t fullBufferSimulation[DATA_SIZE - sizeof(uint16_t) - 1]; // sizeof(length) + length - 1, eg. < Size() + uint8_t testData[] = { 12, 11, 13, 21 }; + uint8_t readData[4]; + uint16_t readLength = sizeof(readData); + + EXPECT_EQ(_dispatcher->PushData(sizeof(fullBufferSimulation), fullBufferSimulation), Core::ERROR_NONE); + // One element free space remaining + // 2+2 bytes, 1 at tail position, 3 starting at position 0 - uint8_t testData[] = { 12, 21 }; + EXPECT_EQ(_dispatcher->PushData(sizeof(testData), testData), Core::ERROR_NONE); + // new data written, so the oldest data should be replaced + + // this is first entry and should be first popped (FIFO) + EXPECT_EQ(_dispatcher->PopData(readLength, readData), Core::ERROR_NONE); + EXPECT_EQ(readLength, sizeof(testData)); + EXPECT_EQ(readData[0], testData[0]); + EXPECT_EQ(readData[3], testData[3]); + } + + TEST_F(Core_MessageDispatcher, OnlyOffsetFitsPushDataShouldFlushOldDataIfDoesNotFit) + { + uint8_t onlyOffsetFitsSimulation[DATA_SIZE - sizeof(uint16_t) - 2]; + uint8_t testData[] = { 12, 11, 13, 21 }; uint8_t readData[4]; uint16_t readLength = sizeof(readData); - EXPECT_EQ(_dispatcher->PushData(sizeof(fullBufferSimulation), fullBufferSimulation), Core::ERROR_NONE); + EXPECT_EQ(_dispatcher->PushData(sizeof(onlyOffsetFitsSimulation), onlyOffsetFitsSimulation), Core::ERROR_NONE); + // Two elements free space remaining so offset of testData should fit at the end of the cyclic buffer, + // and content of testData buffer should be at the beginning of the cyclic buffer - // One element free space remaining + EXPECT_EQ(_dispatcher->PushData(sizeof(testData), testData), Core::ERROR_NONE); + + EXPECT_EQ(_dispatcher->PopData(readLength, readData), Core::ERROR_NONE); + + EXPECT_EQ(readLength, sizeof(testData)); + EXPECT_EQ(readData[0], testData[0]); + EXPECT_EQ(readData[3], testData[3]); + } + + TEST_F(Core_MessageDispatcher, OffsetFitsBufferCutPushDataShouldFlushOldDataIfDoesNotFit) + { + uint8_t offsetPlusFitsSimulation[DATA_SIZE - sizeof(uint16_t) - 3]; + uint8_t testData[] = { 12, 11, 13, 21 }; + uint8_t readData[4]; + uint16_t readLength = sizeof(readData); + + EXPECT_EQ(_dispatcher->PushData(sizeof(offsetPlusFitsSimulation), offsetPlusFitsSimulation), Core::ERROR_NONE); + // Three elements free space remaining, so the offset of testData should still fit at the end of the cyclic buffer, + // as well as the first part of the testData buffer, but its second part should be at the beginning of the cyclic buffer - // 2+2 bytes, 1 at tail position, 3 starting at position 0 EXPECT_EQ(_dispatcher->PushData(sizeof(testData), testData), Core::ERROR_NONE); - //new data written, so the oldest data should be replaced - //this is first entry and should be first popped (FIFO) EXPECT_EQ(_dispatcher->PopData(readLength, readData), Core::ERROR_NONE); + EXPECT_EQ(readLength, sizeof(testData)); - EXPECT_EQ(readData[0], 12); - EXPECT_EQ(readData[1], 21); + EXPECT_EQ(readData[0], testData[0]); + EXPECT_EQ(readData[3], testData[3]); + } + + TEST_F(Core_MessageDispatcher, BufferGetsFilledToItsVeryMaximum) + { + uint8_t almostFullBufferSimulation[DATA_SIZE - sizeof(uint16_t) - 6]; + uint8_t testData1[] = { 12, 11, 13, 21 }; + uint8_t testData2[] = { 54, 62, 78, 91 }; + uint8_t readData[4]; + uint16_t readLength = sizeof(readData); + + EXPECT_EQ(_dispatcher->PushData(sizeof(almostFullBufferSimulation), almostFullBufferSimulation), Core::ERROR_NONE); + + EXPECT_EQ(_dispatcher->PushData(sizeof(testData1), testData1), Core::ERROR_NONE); + // The cyclic buffer is now full + + EXPECT_EQ(_dispatcher->PushData(sizeof(testData2), testData2), Core::ERROR_NONE); + // The cyclic buffer needs to flush the almostFullBufferSimulation to make space for testData2 + + EXPECT_EQ(_dispatcher->PopData(readLength, readData), Core::ERROR_NONE); + EXPECT_EQ(readLength, sizeof(testData1)); + EXPECT_EQ(readData[0], testData1[0]); + EXPECT_EQ(readData[3], testData1[3]); + + EXPECT_EQ(_dispatcher->PopData(readLength, readData), Core::ERROR_NONE); + EXPECT_EQ(readLength, sizeof(testData2)); + EXPECT_EQ(readData[0], testData2[0]); + EXPECT_EQ(readData[3], testData2[3]); } //doorbell (socket) is not quite working inside test suite From db7d4075ce3808e54f71337fddc2f01152336038 Mon Sep 17 00:00:00 2001 From: msieben <4319079+msieben@users.noreply.github.com> Date: Tue, 21 May 2024 07:54:56 +0000 Subject: [PATCH 3/5] [Tests/unit/core] : cherry pick '081a0a1a5f6a2f0699d32b943764893198afd6a9' from 'development/cyclic-buffer-overlow-fix'. --- Source/core/CyclicBuffer.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Source/core/CyclicBuffer.cpp b/Source/core/CyclicBuffer.cpp index f5072aa81..b597beb30 100644 --- a/Source/core/CyclicBuffer.cpp +++ b/Source/core/CyclicBuffer.cpp @@ -394,25 +394,25 @@ namespace Core { foundData = false; } } else { - uint32_t part1 = 0; - uint32_t part2 = 0; + uint32_t newOffset = 0; if (_administration->_size < offset) { - part2 = result - (offset - _administration->_size); + const uint32_t skip = offset - _administration->_size; + newOffset = skip + bufferLength; + ::memcpy(buffer, _realBuffer + skip, bufferLength); } else { - part1 = _administration->_size - offset; - part2 = result - part1; - } - - memcpy(buffer, _realBuffer + offset, std::min(part1, bufferLength)); + const uint32_t part1 = _administration->_size - offset; + newOffset = result - part1; + ::memcpy(buffer, _realBuffer + offset, std::min(part1, bufferLength)); - if (part1 < bufferLength) { - memcpy(buffer + part1, _realBuffer, bufferLength - part1); + if (part1 < bufferLength) { + ::memcpy(buffer + part1, _realBuffer, bufferLength - part1); + } } // Add one round, but prevent overflow. roundCount = (roundCount + 1) % _administration->_roundCountModulo; - uint32_t newTail = part2 + roundCount * (1 + _administration->_tailIndexMask); + uint32_t newTail = newOffset + roundCount * (1 + _administration->_tailIndexMask); if (!_administration->_tail.compare_exchange_weak(oldTail, newTail)) { foundData = false; } From d9a5af825ee39968d548edb89c0af579b3f2c178 Mon Sep 17 00:00:00 2001 From: msieben <4319079+msieben@users.noreply.github.com> Date: Wed, 29 May 2024 17:26:54 +0000 Subject: [PATCH 4/5] [Tests/unit/core] : Fix build 'test_message-dispatcher'. --- Tests/unit/core/CMakeLists.txt | 4 +- Tests/unit/core/test_message_dispatcher.cpp | 166 +------------------- 2 files changed, 7 insertions(+), 163 deletions(-) diff --git a/Tests/unit/core/CMakeLists.txt b/Tests/unit/core/CMakeLists.txt index 2a5501e16..8aaed36f3 100644 --- a/Tests/unit/core/CMakeLists.txt +++ b/Tests/unit/core/CMakeLists.txt @@ -68,7 +68,7 @@ add_executable(${TEST_RUNNER_NAME} test_textfragment.cpp test_textreader.cpp test_thread.cpp - test_threadpool.cpp +# test_threadpool.cpp test_time.cpp test_timer.cpp test_tristate.cpp @@ -77,7 +77,7 @@ add_executable(${TEST_RUNNER_NAME} test_weblinktext.cpp test_websocketjson.cpp test_websockettext.cpp - test_workerpool.cpp +# test_workerpool.cpp test_xgetopt.cpp test_message_dispatcher.cpp ) diff --git a/Tests/unit/core/test_message_dispatcher.cpp b/Tests/unit/core/test_message_dispatcher.cpp index f714e9019..d90ab8388 100644 --- a/Tests/unit/core/test_message_dispatcher.cpp +++ b/Tests/unit/core/test_message_dispatcher.cpp @@ -182,7 +182,7 @@ namespace Tests { ASSERT_EQ(readData[0], 40); } - TEST_F(Core_MessageDispatcher, WriteAndReadDataAreEqualInDiffrentProcesses) + TEST_F(Core_MessageDispatcher, WriteAndReadDataAreEqualInDifferentProcesses) { auto lambdaFunc = [this](IPTestAdministrator& testAdmin) { Messaging::MessageDataBuffer dispatcher(this->_identifier, this->_instanceId, this->_basePath, DATA_SIZE, 0, false); @@ -190,17 +190,13 @@ namespace Tests { uint8_t readData[4]; uint16_t readLength = sizeof(readData); - testAdmin.Sync("setup reader"); - testAdmin.Sync("writer wrote"); - + // Arbitrary timeout value, 1 second + ASSERT_EQ(dispatcher.Wait(1000), Core::ERROR_NONE); ASSERT_EQ(dispatcher.PopData(readLength, readData), Core::ERROR_NONE); ASSERT_EQ(readLength, 2); ASSERT_EQ(readData[0], 13); ASSERT_EQ(readData[1], 37); - - testAdmin.Sync("reader read"); - testAdmin.Sync("done"); }; static std::function lambdaVar = lambdaFunc; @@ -209,15 +205,11 @@ namespace Tests { // This side (tested) acts as writer IPTestAdministrator testAdmin(otherSide); { - testAdmin.Sync("setup reader"); - uint8_t testData[2] = { 13, 37 }; ASSERT_EQ(_dispatcher->PushData(sizeof(testData), testData), Core::ERROR_NONE); - - testAdmin.Sync("writer wrote"); - testAdmin.Sync("reader read"); + // The 'ring' is implicit +// _dispatcher->Ring(); } - testAdmin.Sync("done"); } TEST_F(Core_MessageDispatcher, PushDataShouldNotFitWhenExcedingDataBufferSize) @@ -263,7 +255,6 @@ namespace Tests { // and content of testData buffer should be at the beginning of the cyclic buffer EXPECT_EQ(_dispatcher->PushData(sizeof(testData), testData), Core::ERROR_NONE); - EXPECT_EQ(_dispatcher->PopData(readLength, readData), Core::ERROR_NONE); EXPECT_EQ(readLength, sizeof(testData)); @@ -283,7 +274,6 @@ namespace Tests { // as well as the first part of the testData buffer, but its second part should be at the beginning of the cyclic buffer EXPECT_EQ(_dispatcher->PushData(sizeof(testData), testData), Core::ERROR_NONE); - EXPECT_EQ(_dispatcher->PopData(readLength, readData), Core::ERROR_NONE); EXPECT_EQ(readLength, sizeof(testData)); @@ -317,151 +307,5 @@ namespace Tests { EXPECT_EQ(readData[0], testData2[0]); EXPECT_EQ(readData[3], testData2[3]); } - - //doorbell (socket) is not quite working inside test suite - TEST_F(Core_MessageDispatcher, DISABLED_ReaderShouldWaitUntillRingBells) - { - auto lambdaFunc = [this](IPTestAdministrator& testAdmin) { - Messaging::MessageDataBuffer dispatcher(this->_identifier, this->_instanceId, this->_basePath, 0, false); - - uint8_t readData[4]; - uint16_t readLength = sizeof(readData); - - bool called = false; - dispatcher.Wait(0); //initialize socket - testAdmin.Sync("init"); - - if (dispatcher.Wait(Core::infinite) == Core::ERROR_NONE) { - ASSERT_EQ(dispatcher.PopData(readLength, readData), Core::ERROR_NONE); - - ASSERT_EQ(readLength, 2); - ASSERT_EQ(readData[0], 13); - ASSERT_EQ(readData[1], 37); - called = true; - } - ASSERT_EQ(called, true); - - testAdmin.Sync("done"); - }; - - static std::function lambdaVar = lambdaFunc; - IPTestAdministrator::OtherSideMain otherSide = [](IPTestAdministrator& testAdmin) { lambdaVar(testAdmin); }; - - // This side (tested) acts as writer - IPTestAdministrator testAdmin(otherSide); - { - uint8_t testData[2] = { 13, 37 }; - testAdmin.Sync("init"); - - ASSERT_EQ(_dispatcher->PushData(sizeof(testData), testData), Core::ERROR_NONE); - } - testAdmin.Sync("done"); - } -#ifdef _0 - TEST_F(Core_MessageDispatcher, WriteAndReadMetaDataAreEqualInSameProcess) - { - uint8_t testData[2] = { 13, 37 }; - - _dispatcher->RegisterDataAvailable([&](const uint16_t length, const uint8_t* value, uint16_t& outLength, uint8_t* outValue) { - EXPECT_EQ(length, sizeof(testData)); - EXPECT_EQ(value[0], 13); - EXPECT_EQ(value[1], 37); - - outValue[0] = 60; - outValue[1] = 61; - outLength = 2; - }); - - auto result = _dispatcher->PushMetadata(sizeof(testData), testData, sizeof(testData)); - ASSERT_EQ(result, 2); - ASSERT_EQ(testData[0], 60); - ASSERT_EQ(testData[1], 61); - ::SleepMs(50); //wait for callback complete before closing - - _dispatcher->UnregisterDataAvailable(); - } - - TEST_F(Core_MessageDispatcher, WriteAndReadMetaDataAreEqualInSameProcessTwice) - { - uint8_t testData1[2] = { 13, 37 }; - uint8_t testData2[2] = { 12, 34 }; - - //first write and read - _dispatcher->RegisterDataAvailable([&](const uint16_t length, const uint8_t* value, uint16_t& outLength, uint8_t* outValue) { - EXPECT_EQ(length, sizeof(testData1)); - EXPECT_EQ(value[0], 13); - EXPECT_EQ(value[1], 37); - - outValue[0] = 60; - outValue[1] = 61; - outLength = 2; - }); - auto result = _dispatcher->PushMetadata(sizeof(testData1), testData1, sizeof(testData1)); - ASSERT_EQ(result, 2); - ASSERT_EQ(testData1[0], 60); - ASSERT_EQ(testData1[1], 61); - ::SleepMs(50); //need to wait before unregistering, not clean solution though - _dispatcher->UnregisterDataAvailable(); - - //second write and read - _dispatcher->RegisterDataAvailable([&](const uint16_t length, const uint8_t* value, uint16_t& outLength, uint8_t* outValue) { - EXPECT_EQ(length, sizeof(testData2)); - EXPECT_EQ(value[0], 12); - EXPECT_EQ(value[1], 34); - - outValue[0] = 60; - outValue[1] = 61; - outLength = 2; - }); - result = _dispatcher->PushMetadata(sizeof(testData2), testData2, sizeof(testData2)); - ASSERT_EQ(result, 2); - ASSERT_EQ(testData2[0], 60); - ASSERT_EQ(testData2[1], 61); - ::SleepMs(50); - _dispatcher->UnregisterDataAvailable(); - } - - //socket problems inside test suite - TEST_F(Core_MessageDispatcher, DISABLED_WriteAndReadMetaDataAreEqualInDiffrentProcesses) - { - auto lambdaFunc = [this](IPTestAdministrator& testAdmin) { - Core::MessageDispatcherType dispatcher(this->_identifier, this->_instanceId, false, this->_basePath); - uint8_t testData[2] = { 13, 37 }; - //testAdmin.Sync("setup"); - - auto result = _dispatcher->PushMetadata(sizeof(testData), testData, sizeof(testData)); - ASSERT_EQ(result, 2); - ASSERT_EQ(testData[0], 60); - ASSERT_EQ(testData[1], 61); - ::SleepMs(2000); - }; - - static std::function lambdaVar = lambdaFunc; - IPTestAdministrator::OtherSideMain otherSide = [](IPTestAdministrator& testAdmin) { lambdaVar(testAdmin); }; - - // This side (tested) acts as reader - IPTestAdministrator testAdmin(otherSide); - { - _dispatcher->RegisterDataAvailable([&](const uint16_t length, const uint8_t* value, uint16_t& outLength, uint8_t* outValue) { - std::vector result{ 60, 61 }; - EXPECT_EQ(length, 2); - EXPECT_EQ(value[0], 13); - EXPECT_EQ(value[1], 37); - return result; - }); - - ::SleepMs(2000); - } - _dispatcher->UnregisterDataAvailable(); - } - - TEST_F(Core_MessageDispatcher, WriteMetaDataShouldFailIfReaderNotRegistered) - { - uint8_t testData[2] = { 13, 37 }; - - auto result = _dispatcher->PushMetadata(sizeof(testData), testData, sizeof(testData)); - ASSERT_EQ(result, 0); - } -#endif } // Tests } // WPEFramework From 507ebc160585d00b3051a0a65516c66609da829f Mon Sep 17 00:00:00 2001 From: msieben <4319079+msieben@users.noreply.github.com> Date: Thu, 30 May 2024 07:21:43 +0000 Subject: [PATCH 5/5] [Tests/unit/core] : Re-enable 'test_workerpool' and 'test_threadpool' --- Tests/unit/core/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/unit/core/CMakeLists.txt b/Tests/unit/core/CMakeLists.txt index 8aaed36f3..2a5501e16 100644 --- a/Tests/unit/core/CMakeLists.txt +++ b/Tests/unit/core/CMakeLists.txt @@ -68,7 +68,7 @@ add_executable(${TEST_RUNNER_NAME} test_textfragment.cpp test_textreader.cpp test_thread.cpp -# test_threadpool.cpp + test_threadpool.cpp test_time.cpp test_timer.cpp test_tristate.cpp @@ -77,7 +77,7 @@ add_executable(${TEST_RUNNER_NAME} test_weblinktext.cpp test_websocketjson.cpp test_websockettext.cpp -# test_workerpool.cpp + test_workerpool.cpp test_xgetopt.cpp test_message_dispatcher.cpp )