From 109c05bc985d25f513444a7caa1e54557ef0f3c0 Mon Sep 17 00:00:00 2001 From: Finn Williams Date: Fri, 29 Nov 2019 13:56:33 +0000 Subject: IVGCVSW-4118 Change the SendCounterPacket send thread to use do while Signed-off-by: Finn Williams Change-Id: I702fdc941e29ddcb31f54513e0a7dc642f0f4685 --- src/profiling/SendCounterPacket.cpp | 6 +++--- src/profiling/test/SendCounterPacketTests.cpp | 31 +++++++-------------------- 2 files changed, 11 insertions(+), 26 deletions(-) diff --git a/src/profiling/SendCounterPacket.cpp b/src/profiling/SendCounterPacket.cpp index e3a9b77f41..a9846c9f06 100644 --- a/src/profiling/SendCounterPacket.cpp +++ b/src/profiling/SendCounterPacket.cpp @@ -974,8 +974,8 @@ void SendCounterPacket::Stop(bool rethrowSendThreadExceptions) void SendCounterPacket::Send(IProfilingConnection& profilingConnection) { - // Keep the sending procedure looping until the thread is signalled to stop - while (m_KeepRunning.load()) + // Run once and keep the sending procedure looping until the thread is signalled to stop + do { // Check the current state of the profiling service ProfilingState currentState = m_StateMachine.GetCurrentState(); @@ -1054,7 +1054,7 @@ void SendCounterPacket::Send(IProfilingConnection& profilingConnection) // Send all the available packets in the buffer FlushBuffer(profilingConnection); - } + } while (m_KeepRunning.load()); // Ensure that all readable data got written to the profiling connection before the thread is stopped // (do not notify any watcher in this case, as this is just to wrap up things before shutting down the send thread) diff --git a/src/profiling/test/SendCounterPacketTests.cpp b/src/profiling/test/SendCounterPacketTests.cpp index 740ea33c9a..b4564fec29 100644 --- a/src/profiling/test/SendCounterPacketTests.cpp +++ b/src/profiling/test/SendCounterPacketTests.cpp @@ -1793,8 +1793,6 @@ BOOST_AUTO_TEST_CASE(SendThreadTest0) sendCounterPacket.Start(mockProfilingConnection); BOOST_CHECK(sendCounterPacket.IsRunning()); - std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS)); - sendCounterPacket.Stop(); BOOST_CHECK(!sendCounterPacket.IsRunning()); } @@ -1899,7 +1897,7 @@ BOOST_AUTO_TEST_CASE(SendThreadTest1) sendCounterPacket.SetReadyToRead(); - // To test an exact value of the "read size" in the mock buffer, wait two seconds to allow the send thread to + // To test an exact value of the "read size" in the mock buffer, wait to allow the send thread to // read all what's remaining in the buffer std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS)); @@ -2022,7 +2020,7 @@ BOOST_AUTO_TEST_CASE(SendThreadTest2) sendCounterPacket.SetReadyToRead(); - // To test an exact value of the "read size" in the mock buffer, wait two seconds to allow the send thread to + // To test an exact value of the "read size" in the mock buffer, wait to allow the send thread to // read all what's remaining in the buffer std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS)); @@ -2346,10 +2344,6 @@ BOOST_AUTO_TEST_CASE(SendThreadSendStreamMetadataPacket1) sendCounterPacket.Start(mockProfilingConnection); // The profiling state is set to "Uninitialized", so the send thread should throw an exception - - // Wait a bit to make sure that the send thread is properly started - std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS)); - BOOST_CHECK_THROW(sendCounterPacket.Stop(), armnn::RuntimeException); } @@ -2364,10 +2358,6 @@ BOOST_AUTO_TEST_CASE(SendThreadSendStreamMetadataPacket2) sendCounterPacket.Start(mockProfilingConnection); // The profiling state is set to "NotConnected", so the send thread should throw an exception - - // Wait a bit to make sure that the send thread is properly started - std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS)); - BOOST_CHECK_THROW(sendCounterPacket.Stop(), armnn::RuntimeException); } @@ -2387,10 +2377,7 @@ BOOST_AUTO_TEST_CASE(SendThreadSendStreamMetadataPacket3) sendCounterPacket.Start(mockProfilingConnection); // The profiling state is set to "WaitingForAck", so the send thread should send a Stream Metadata packet - - // Wait for a bit to make sure that we get the packet - std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS)); - + // Wait for sendCounterPacket to join BOOST_CHECK_NO_THROW(sendCounterPacket.Stop()); // Check that the buffer contains one Stream Metadata packet @@ -2415,10 +2402,10 @@ BOOST_AUTO_TEST_CASE(SendThreadSendStreamMetadataPacket4) sendCounterPacket.Start(mockProfilingConnection); // The profiling state is set to "WaitingForAck", so the send thread should send a Stream Metadata packet + // Wait for sendCounterPacket to join + sendCounterPacket.Stop(); - // Wait for a bit to make sure that we get the packet - std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS)); - + sendCounterPacket.Start(mockProfilingConnection); // Check that the profiling state is still "WaitingForAck" BOOST_TEST((profilingStateMachine.GetCurrentState() == ProfilingState::WaitingForAck)); @@ -2432,8 +2419,8 @@ BOOST_AUTO_TEST_CASE(SendThreadSendStreamMetadataPacket4) // Try triggering a new buffer read sendCounterPacket.SetReadyToRead(); - // Wait for a bit to make sure that we get the packet - std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS)); + // Wait for sendCounterPacket to join + BOOST_CHECK_NO_THROW(sendCounterPacket.Stop()); // Check that the profiling state is still "WaitingForAck" BOOST_TEST((profilingStateMachine.GetCurrentState() == ProfilingState::WaitingForAck)); @@ -2441,8 +2428,6 @@ BOOST_AUTO_TEST_CASE(SendThreadSendStreamMetadataPacket4) // Check that the buffer contains one Stream Metadata packet BOOST_TEST(writtenData.size() == 1); BOOST_TEST(writtenData[0] == streamMetadataPacketsize); - - BOOST_CHECK_NO_THROW(sendCounterPacket.Stop()); } BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.1